diff options
author | Guy Harris <guy@alum.mit.edu> | 2000-04-12 22:53:16 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2000-04-12 22:53:16 +0000 |
commit | cf31cb477de12dd31cda254b544290173b76fd13 (patch) | |
tree | c8532731900da17a24d9529fb203a39c853775e3 /packet-udp.c | |
parent | ed237c129d8445a45dbe5e8819353c468e6d24ee (diff) | |
download | wireshark-cf31cb477de12dd31cda254b544290173b76fd13.tar.gz wireshark-cf31cb477de12dd31cda254b544290173b76fd13.tar.bz2 wireshark-cf31cb477de12dd31cda254b544290173b76fd13.zip |
Jeff Foster's SOCKS dissector, support for associating dissectors
with conversations and having TCP and UDP check whether a packet is part
of a conversation with a dissector and, if so, using that dissector on
the conversation, and "ethertype()"-style support for allowing a
dissector to call a sub-dissector via the same path that the TCP and UDP
dissectors use, based on port numbers supplied by that dissector.
svn path=/trunk/; revision=1837
Diffstat (limited to 'packet-udp.c')
-rw-r--r-- | packet-udp.c | 112 |
1 files changed, 70 insertions, 42 deletions
diff --git a/packet-udp.c b/packet-udp.c index c805250c84..ca22c9f972 100644 --- a/packet-udp.c +++ b/packet-udp.c @@ -1,7 +1,7 @@ /* packet-udp.c * Routines for UDP packet disassembly * - * $Id: packet-udp.c,v 1.59 2000/04/08 07:07:41 guy Exp $ + * $Id: packet-udp.c,v 1.60 2000/04/12 22:53:16 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -83,55 +83,28 @@ typedef struct _e_udphdr { static dissector_table_t udp_dissector_table; + void -dissect_udp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { - e_udphdr uh; - guint16 uh_sport, uh_dport, uh_ulen, uh_sum; - proto_tree *udp_tree; - proto_item *ti; +decode_udp_ports( const u_char *pd, int offset, frame_data *fd, + proto_tree *tree, int uh_sport, int uh_dport){ - if (!BYTES_ARE_IN_FRAME(offset, sizeof(e_udphdr))) { - dissect_data(pd, offset, fd, tree); - return; - } +/* Determine if there is a sub-dissector and call it. This has been */ +/* separated into a stand alone routine to other protocol dissectors */ +/* can call to it, ie. socks */ - /* Avoids alignment problems on many architectures. */ - memcpy(&uh, &pd[offset], sizeof(e_udphdr)); - uh_sport = ntohs(uh.uh_sport); - uh_dport = ntohs(uh.uh_dport); - uh_ulen = ntohs(uh.uh_ulen); - uh_sum = ntohs(uh.uh_sum); - - if (check_col(fd, COL_PROTOCOL)) - col_add_str(fd, COL_PROTOCOL, "UDP"); - if (check_col(fd, COL_INFO)) - col_add_fstr(fd, COL_INFO, "Source port: %s Destination port: %s", - get_udp_port(uh_sport), get_udp_port(uh_dport)); - - if (tree) { - ti = proto_tree_add_item(tree, proto_udp, offset, 8); - udp_tree = proto_item_add_subtree(ti, ett_udp); + dissector_t sub_dissector; - proto_tree_add_uint_format(udp_tree, hf_udp_srcport, offset, 2, uh_sport, - "Source port: %s (%u)", get_udp_port(uh_sport), uh_sport); - proto_tree_add_uint_format(udp_tree, hf_udp_dstport, offset + 2, 2, uh_dport, - "Destination port: %s (%u)", get_udp_port(uh_dport), uh_dport); - proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset, 2, uh_sport); - proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset+2, 2, uh_dport); +/* determine if this packet is part of a conversation and call dissector */ +/* for the conversation if available */ - proto_tree_add_item(udp_tree, hf_udp_length, offset + 4, 2, uh_ulen); - proto_tree_add_uint_format(udp_tree, hf_udp_checksum, offset + 6, 2, uh_sum, - "Checksum: 0x%04x", uh_sum); + sub_dissector = find_conversation_dissector( &pi.src, &pi.dst, PT_UDP, + uh_sport, uh_dport); + if (sub_dissector){ + (sub_dissector)(pd, offset, fd, tree); + return; } - /* Skip over header */ - offset += 8; - - pi.ptype = PT_UDP; - pi.srcport = uh_sport; - pi.destport = uh_dport; - /* ONC RPC. We can't base this on anything in the UDP header; we have to look at the payload. If "dissect_rpc()" returns TRUE, it was an RPC packet, otherwise it's some other type of packet. */ @@ -185,6 +158,61 @@ dissect_udp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { } } + +void +dissect_udp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { + e_udphdr uh; + guint16 uh_sport, uh_dport, uh_ulen, uh_sum; + proto_tree *udp_tree; + proto_item *ti; + + if (!BYTES_ARE_IN_FRAME(offset, sizeof(e_udphdr))) { + dissect_data(pd, offset, fd, tree); + return; + } + + /* Avoids alignment problems on many architectures. */ + memcpy(&uh, &pd[offset], sizeof(e_udphdr)); + uh_sport = ntohs(uh.uh_sport); + uh_dport = ntohs(uh.uh_dport); + uh_ulen = ntohs(uh.uh_ulen); + uh_sum = ntohs(uh.uh_sum); + + if (check_col(fd, COL_PROTOCOL)) + col_add_str(fd, COL_PROTOCOL, "UDP"); + if (check_col(fd, COL_INFO)) + col_add_fstr(fd, COL_INFO, "Source port: %s Destination port: %s", + get_udp_port(uh_sport), get_udp_port(uh_dport)); + + if (tree) { + ti = proto_tree_add_item(tree, proto_udp, offset, 8); + udp_tree = proto_item_add_subtree(ti, ett_udp); + + proto_tree_add_uint_format(udp_tree, hf_udp_srcport, offset, 2, uh_sport, + "Source port: %s (%u)", get_udp_port(uh_sport), uh_sport); + proto_tree_add_uint_format(udp_tree, hf_udp_dstport, offset + 2, 2, uh_dport, + "Destination port: %s (%u)", get_udp_port(uh_dport), uh_dport); + + proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset, 2, uh_sport); + proto_tree_add_item_hidden(udp_tree, hf_udp_port, offset+2, 2, uh_dport); + + proto_tree_add_item(udp_tree, hf_udp_length, offset + 4, 2, uh_ulen); + proto_tree_add_uint_format(udp_tree, hf_udp_checksum, offset + 6, 2, uh_sum, + "Checksum: 0x%04x", uh_sum); + } + + /* Skip over header */ + offset += 8; + + pi.ptype = PT_UDP; + pi.srcport = uh_sport; + pi.destport = uh_dport; + +/* call sub-dissectors */ + decode_udp_ports( pd, offset, fd, tree, uh_sport, uh_dport); + +} + void proto_register_udp(void) { |