summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-11-03 18:23:27 -0400
committerOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-11-03 18:23:27 -0400
commit16ec12371aa3a0cdb3701f7526adf6f41705806b (patch)
treef5c0b9fbc800dff02df2ac14a0d9fe809bf905f7
parentec16c22f54fc6ac177b317bbe3940527869d12d6 (diff)
pcapparse: Fail on unknown version or linktype
The element only knows about major version 2 and only decodes linktype ethernet
-rw-r--r--gst/pcapparse/gstpcapparse.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/gst/pcapparse/gstpcapparse.c b/gst/pcapparse/gstpcapparse.c
index 401e20f83..925551fd0 100644
--- a/gst/pcapparse/gstpcapparse.c
+++ b/gst/pcapparse/gstpcapparse.c
@@ -468,7 +468,9 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
self->cur_packet_size = incl_len;
}
} else {
- guint magic;
+ guint32 magic;
+ guint32 linktype;
+ guint16 major_version;
if (avail < 24)
break;
@@ -476,24 +478,43 @@ gst_pcap_parse_chain (GstPad * pad, GstBuffer * buffer)
data = gst_adapter_peek (self->adapter, 24);
magic = *((guint32 *) data);
+ major_version = *((guint16 *) (data + 4));
- gst_adapter_flush (self->adapter, 24);
-
- if (magic == 0xa1b2c3d4)
+ if (magic == 0xa1b2c3d4) {
self->swap_endian = FALSE;
- else if (magic == 0xd4c3b2a1)
+ } else if (magic == 0xd4c3b2a1) {
self->swap_endian = TRUE;
- else {
+ major_version = major_version << 8 | major_version >> 8;
+ } else {
+ GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL),
+ ("File is not a libpcap file, magic is %X", magic));
+ ret = GST_FLOW_ERROR;
+ goto out;
+ }
+
+ if (major_version != 2) {
GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL),
- ("File is not a libpcap file version 2, magic is %X", magic));
+ ("File is not a libpcap major version 2, but %u", major_version));
ret = GST_FLOW_ERROR;
+ goto out;
}
- if (ret == GST_FLOW_OK)
- self->initialized = TRUE;
+ linktype = gst_pcap_parse_read_uint32 (self, data + 20);
+
+ if (linktype != 1) {
+ GST_ELEMENT_ERROR (self, STREAM, WRONG_TYPE, (NULL),
+ ("Only Ethernet packets of type 1 understood,"
+ " type %d unknown", linktype));
+ ret = GST_FLOW_ERROR;
+ goto out;
+ }
+
+ gst_adapter_flush (self->adapter, 24);
+ self->initialized = TRUE;
}
}
+out:
if (ret != GST_FLOW_OK)
gst_pcap_parse_reset (self);