diff options
author | Michael Mann <mmann78@netscape.net> | 2015-12-13 16:54:16 -0500 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-12-14 12:17:49 +0000 |
commit | 0960ac4dfdbfba5a81c56a49cfc6201ecd8f48e3 (patch) | |
tree | 3d88cd321da2fade206b9ccddff22b70ecdfae28 /epan/dissectors/packet-null.c | |
parent | 9319357f5e27c10f2d29e78fcdf9d323c2af36b0 (diff) |
Create capture dissector tables.
They are modeled after dissection dissector tables, but for the moment, don't have/need the flexibility. They are intended to be much simpler/faster than full dissection.
The two most used/needed are "wtap_encap" and "ethertype", so they were the basis of starting to use and test capture dissector table API. Others may be added in the future.
The "capture dissector" function signature needed a bit of tweeking to handling "claiming" of a packet.
The current application of this is capture functions returning TRUE if they affected a "type" of packet count. Returning FALSE ends up considering the packet an "other" type.
Change-Id: I81d06a6ccb2c03665f087258a46b9d78d513d6cd
Reviewed-on: https://code.wireshark.org/review/12607
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan/dissectors/packet-null.c')
-rw-r--r-- | epan/dissectors/packet-null.c | 59 |
1 files changed, 24 insertions, 35 deletions
diff --git a/epan/dissectors/packet-null.c b/epan/dissectors/packet-null.c index 41d7b12cad..ee514ebdc9 100644 --- a/epan/dissectors/packet-null.c +++ b/epan/dissectors/packet-null.c @@ -65,7 +65,7 @@ static const value_string family_vals[] = { static dissector_handle_t ppp_hdlc_handle; static dissector_handle_t data_handle; -static void +static gboolean capture_null( const guchar *pd, int offset _U_, int len, packet_counts *ld, const union wtap_pseudo_header *pseudo_header _U_ ) { guint32 null_header; @@ -252,23 +252,21 @@ capture_null( const guchar *pd, int offset _U_, int len, packet_counts *ld, cons * digits would be zero and the next 2 hex digits would not be zero. * Furthermore, the third hex digit from the bottom would be < */ - if (!BYTES_ARE_IN_FRAME(0, len, 2)) { - ld->other++; - return; - } + if (!BYTES_ARE_IN_FRAME(0, len, 2)) + return FALSE; + if (pd[0] == 0xFF && pd[1] == 0x03) { /* * Hand it to PPP. */ - capture_ppp_hdlc(pd, 0, len, ld, pseudo_header); + return capture_ppp_hdlc(pd, 0, len, ld, pseudo_header); } else { /* * Treat it as a normal DLT_NULL header. */ - if (!BYTES_ARE_IN_FRAME(0, len, (int)sizeof(null_header))) { - ld->other++; - return; - } + if (!BYTES_ARE_IN_FRAME(0, len, (int)sizeof(null_header))) + return FALSE; + memcpy((char *)&null_header, (const char *)&pd[0], sizeof(null_header)); if ((null_header & 0xFFFF0000) != 0) { @@ -317,56 +315,47 @@ capture_null( const guchar *pd, int offset _U_, int len, packet_counts *ld, cons * BSD derivatives have different values?). */ if (null_header > IEEE_802_3_MAX_LEN) - capture_ethertype((guint16) null_header, pd, 4, len, ld, pseudo_header); + return try_capture_dissector("ethertype", null_header, pd, 4, len, ld, pseudo_header); else { switch (null_header) { case BSD_AF_INET: - capture_ip(pd, 4, len, ld, pseudo_header); - break; + return capture_ip(pd, 4, len, ld, pseudo_header); case BSD_AF_INET6_BSD: case BSD_AF_INET6_FREEBSD: case BSD_AF_INET6_DARWIN: - capture_ipv6(pd, 4, len, ld, pseudo_header); - break; - - default: - ld->other++; - break; + return capture_ipv6(pd, 4, len, ld, pseudo_header); } } } + + return FALSE; } -static void +static gboolean capture_loop( const guchar *pd, int offset _U_, int len, packet_counts *ld, const union wtap_pseudo_header *pseudo_header _U_ ) { guint32 loop_family; - if (!BYTES_ARE_IN_FRAME(0, len, (int)sizeof(loop_family))) { - ld->other++; - return; - } + if (!BYTES_ARE_IN_FRAME(0, len, (int)sizeof(loop_family))) + return FALSE; + loop_family = pntoh32(&pd[0]); switch (loop_family) { case BSD_AF_INET: - capture_ip(pd, 4, len, ld, pseudo_header); - break; + return capture_ip(pd, 4, len, ld, pseudo_header); case BSD_AF_INET6_BSD: case BSD_AF_INET6_FREEBSD: case BSD_AF_INET6_DARWIN: - capture_ipv6(pd, 4, len, ld, pseudo_header); - break; - - default: - ld->other++; - break; + return capture_ipv6(pd, 4, len, ld, pseudo_header); } + + return FALSE; } static int @@ -535,9 +524,6 @@ proto_register_null(void) proto_register_field_array(proto_null, hf, array_length(hf)); proto_register_subtree_array(ett, array_length(ett)); - register_capture_dissector(WTAP_ENCAP_NULL, capture_null, proto_null); - register_capture_dissector(WTAP_ENCAP_LOOP, capture_loop, proto_null); - /* subdissector code */ null_dissector_table = register_dissector_table("null.type", "Null type", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_NOT_ALLOW_DUPLICATE); @@ -562,6 +548,9 @@ proto_reg_handoff_null(void) loop_handle = create_dissector_handle(dissect_loop, proto_null); dissector_add_uint("wtap_encap", WTAP_ENCAP_LOOP, loop_handle); + + register_capture_dissector("wtap_encap", WTAP_ENCAP_NULL, capture_null, proto_null); + register_capture_dissector("wtap_encap", WTAP_ENCAP_LOOP, capture_loop, proto_null); } /* |