pcapparse: Add support for Linux Cooked Capture (SLL) frames

This commit is contained in:
Olivier Crête 2010-11-03 18:34:28 -04:00
parent 16ec12371a
commit 7ad651c3ff
2 changed files with 33 additions and 8 deletions

View file

@ -319,6 +319,7 @@ gst_pcap_parse_read_uint32 (GstPcapParse * self, const guint8 * p)
}
#define ETH_HEADER_LEN 14
#define SLL_HEADER_LEN 16
#define IP_HEADER_MIN_LEN 20
#define UDP_HEADER_LEN 8
@ -341,14 +342,29 @@ gst_pcap_parse_scan_frame (GstPcapParse * self,
guint16 udp_dst_port;
guint16 udp_len;
if (buf_size < ETH_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN)
return FALSE;
switch (self->linktype) {
case DLT_ETHER:
if (buf_size < ETH_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN)
return FALSE;
eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 12)));
if (eth_type != 0x800)
return FALSE;
eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 12)));
if (eth_type != 0x800)
return FALSE;
buf_ip = buf + ETH_HEADER_LEN;
buf_ip = buf + ETH_HEADER_LEN;
break;
case DLT_SLL:
if (buf_size < SLL_HEADER_LEN + IP_HEADER_MIN_LEN + UDP_HEADER_LEN)
return FALSE;
eth_type = GUINT16_FROM_BE (*((guint16 *) (buf + 2)));
if (eth_type != 1)
return FALSE;
buf_ip = buf + SLL_HEADER_LEN;
break;
}
b = *buf_ip;
if (((b >> 4) & 0x0f) != 4)
@ -501,14 +517,16 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
linktype = gst_pcap_parse_read_uint32 (self, data + 20);
if (linktype != 1) {
if (linktype != DLT_ETHER && linktype != DLT_SLL) {
GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL),
("Only Ethernet packets of type 1 understood,"
("Only dumps of type Ethernet or Linux Coooked (SLL) understood,"
" type %d unknown", linktype));
ret = GST_FLOW_ERROR;
goto out;
}
self->linktype = linktype;
gst_adapter_flush (self->adapter, 24);
self->initialized = TRUE;
}

View file

@ -45,6 +45,12 @@ typedef enum
PCAP_PARSE_STATE_PARSING,
} GstPcapParseState;
typedef enum
{
DLT_ETHER = 1,
DLT_SLL = 113
} GstPcapParseLinktype;
/**
* GstPcapParse:
*
@ -72,6 +78,7 @@ struct _GstPcapParse
gboolean swap_endian;
gint64 cur_packet_size;
GstClockTime cur_ts;
GstPcapParseLinktype linktype;
gboolean newsegment_sent;