From 684d0418969820f165978355104400167515b5c4 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 9 Oct 2014 04:11:00 -0400 Subject: [PATCH] pcapparse: Add support for LINKTYPE_RAW Also, strictly speaking, these numbers aren't DLT_*; they are LINKTYPE_* because libpcap translates from internal OS-specific DLT_ numbering to the portable LINKTYPE_ number space when writing files. https://bugzilla.gnome.org/show_bug.cgi?id=738206 --- gst/pcapparse/gstpcapparse.c | 19 ++++++++++++++----- gst/pcapparse/gstpcapparse.h | 5 +++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gst/pcapparse/gstpcapparse.c b/gst/pcapparse/gstpcapparse.c index 069d75970e..ade724d1a6 100644 --- a/gst/pcapparse/gstpcapparse.c +++ b/gst/pcapparse/gstpcapparse.c @@ -360,20 +360,28 @@ gst_pcap_parse_scan_frame (GstPcapParse * self, guint16 len; switch (self->linktype) { - case DLT_ETHER: + case LINKTYPE_ETHER: if (buf_size < ETH_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN) return FALSE; eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 12))); buf_ip = buf + ETH_HEADER_LEN; break; - case DLT_SLL: + case LINKTYPE_SLL: if (buf_size < SLL_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN) return FALSE; eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 14))); buf_ip = buf + SLL_HEADER_LEN; break; + case LINKTYPE_RAW: + if (buf_size < IP_HEADER_MIN_LEN + UDP_HEADER_LEN) + return FALSE; + + eth_type = 0x800; /* This is fine since IPv4/IPv6 is parse elsewhere */ + buf_ip = buf; + break; + default: return FALSE; } @@ -569,10 +577,11 @@ gst_pcap_parse_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer) goto out; } - if (linktype != DLT_ETHER && linktype != DLT_SLL) { + if (linktype != LINKTYPE_ETHER && linktype != LINKTYPE_SLL && + linktype != LINKTYPE_RAW) { GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL), - ("Only dumps of type Ethernet or Linux Coooked (SLL) understood," - " type %d unknown", linktype)); + ("Only dumps of type Ethernet, raw IP or Linux Cooked (SLL) " + "understood; type %d unknown", linktype)); ret = GST_FLOW_ERROR; goto out; } diff --git a/gst/pcapparse/gstpcapparse.h b/gst/pcapparse/gstpcapparse.h index ef90ea2e76..2c9216f0ab 100644 --- a/gst/pcapparse/gstpcapparse.h +++ b/gst/pcapparse/gstpcapparse.h @@ -47,8 +47,9 @@ typedef enum typedef enum { - DLT_ETHER = 1, - DLT_SLL = 113 + LINKTYPE_ETHER = 1, + LINKTYPE_RAW = 101, + LINKTYPE_SLL = 113 } GstPcapParseLinktype; /**