diff options
author | Jeff Foster <jfoste@woodward.com> | 2001-10-29 21:45:12 +0000 |
---|---|---|
committer | Jeff Foster <jfoste@woodward.com> | 2001-10-29 21:45:12 +0000 |
commit | 1afe1af21196d6941b0fec2f39127c1f6c34f85d (patch) | |
tree | 1fde58b9d68dd338af89304a5dad91f4d998cba4 /packet-socks.c | |
parent | d82c74d757383e94f745fef6b409b3da44ffb08d (diff) | |
download | wireshark-1afe1af21196d6941b0fec2f39127c1f6c34f85d.tar.gz wireshark-1afe1af21196d6941b0fec2f39127c1f6c34f85d.tar.bz2 wireshark-1afe1af21196d6941b0fec2f39127c1f6c34f85d.zip |
Dissector converted to TVBuffers. The changes are originally from
Pia Sahlberg <piabar@hotmail.com.
svn path=/trunk/; revision=4100
Diffstat (limited to 'packet-socks.c')
-rw-r--r-- | packet-socks.c | 458 |
1 files changed, 205 insertions, 253 deletions
diff --git a/packet-socks.c b/packet-socks.c index fdfcb273dc..761d12e715 100644 --- a/packet-socks.c +++ b/packet-socks.c @@ -2,7 +2,7 @@ * Routines for socks versions 4 &5 packet dissection * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com> * - * $Id: packet-socks.c,v 1.24 2001/10/26 18:28:16 gram Exp $ + * $Id: packet-socks.c,v 1.25 2001/10/29 21:45:12 jfoster Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -81,12 +81,8 @@ #include "strutil.h" -#define CHECK_PACKET_LENGTH(X) if (!BYTES_ARE_IN_FRAME(offset, X)){ \ - proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***"); \ - return; } - -#define compare_packet(X) (X == (fd->num)) -#define get_packet_ptr (fd->num) +#define compare_packet(X) (X == (pinfo->fd->num)) +#define get_packet_ptr (pinfo->fd->num) #define row_pointer_type guint32 #define TCP_PORT_SOCKS 1080 @@ -145,15 +141,15 @@ enum SockState { typedef struct { - int state; - int version; - int command; - int grant; - gint32 port; - gint32 udp_port; - gint32 udp_remote_port; + int state; + int version; + int command; + int grant; + guint32 port; + guint32 udp_port; + guint32 udp_remote_port; - int connect_offset; + int connect_offset; row_pointer_type v4_name_row; row_pointer_type v4_user_name_row; row_pointer_type connect_row; @@ -216,7 +212,7 @@ static GMemChunk *socks_vals = NULL; /************************* Support routines ***************************/ -static int display_string( const u_char *pd, int offset, frame_data *fd, +static int display_string(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *label){ /* display a string with a length, characters encoding */ @@ -229,27 +225,22 @@ static int display_string( const u_char *pd, int offset, frame_data *fd, char temp[ 256]; - int length = GBYTE( pd, offset); - - if (!BYTES_ARE_IN_FRAME(offset, 8)){ - proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***"); - return 0; - } + int length = tvb_get_guint8(tvb, offset); - strncpy( temp, &pd[ offset + 1], length); + strncpy( temp, tvb_get_ptr(tvb, offset+1, -1), length); temp[ length ] = 0; - ti = proto_tree_add_text(tree, NullTVB, offset, length + 1, + ti = proto_tree_add_text(tree, tvb, offset, length + 1, "%s: %s" , label, temp); name_tree = proto_item_add_subtree(ti, ett_socks_name); - proto_tree_add_text( name_tree, NullTVB, offset, 1, "Length: %d", length); + proto_tree_add_text( name_tree, tvb, offset, 1, "Length: %d", length); ++offset; - proto_tree_add_text( name_tree, NullTVB, offset, length, "String: %s", temp); + proto_tree_add_text( name_tree, tvb, offset, length, "String: %s", temp); return length + 1; } @@ -288,14 +279,14 @@ static char *get_command_name( guint Number){ } -static int display_address( const u_char *pd, int offset, - frame_data *fd, proto_tree *tree) { +static int +display_address(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree) { /* decode and display the v5 address, return offset of next byte */ - int a_type = GBYTE( pd, offset); + int a_type = tvb_get_guint8(tvb, offset); - proto_tree_add_text( tree, NullTVB, offset, 1, + proto_tree_add_text( tree, tvb, offset, 1, "Address Type: %d (%s)", a_type, address_type_table[ MIN( (guint) a_type, array_length( address_type_table)-1) ]); @@ -303,24 +294,18 @@ static int display_address( const u_char *pd, int offset, ++offset; if ( a_type == 1){ /* IPv4 address */ - if (!BYTES_ARE_IN_FRAME(offset, 4)) - proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***"); - - proto_tree_add_ipv4( tree, hf_socks_ip_dst, NullTVB, offset, - 4, GWORD( pd, offset)); + proto_tree_add_ipv4( tree, hf_socks_ip_dst, tvb, offset, + 4, tvb_get_letohl(tvb, offset)); offset += 4; } else if ( a_type == 3){ /* domain name address */ - offset += display_string( pd, offset, fd, tree, + offset += display_string(tvb, offset, pinfo, tree, "Remote name"); } else if ( a_type == 4){ /* IPv6 address */ - if (!BYTES_ARE_IN_FRAME(offset, 16)) - proto_tree_add_text(tree, NullTVB, offset, 0, "*** FRAME TOO SHORT ***"); - - proto_tree_add_ipv6( tree, hf_socks_ip6_dst, NullTVB, offset, - 4, &pd[offset]); + proto_tree_add_ipv6( tree, hf_socks_ip6_dst, tvb, offset, + 4, tvb_get_ptr(tvb, offset, 16)); offset += 16; } @@ -328,19 +313,19 @@ static int display_address( const u_char *pd, int offset, } -static int get_address_v5( const u_char *pd, int offset, +static int get_address_v5(tvbuff_t *tvb, int offset, socks_hash_entry_t *hash_info) { /* decode the v5 address and return offset of next byte */ -/*$$$ this needs to handle IPV6 and domain name addresses */ +/*XXX this needs to handle IPV6 and domain name addresses */ - int a_type = GBYTE( pd, offset++); + int a_type = tvb_get_guint8(tvb, offset++); if ( a_type == 1){ /* IPv4 address */ if ( hash_info) - hash_info->dst_addr = GWORD( pd, offset); + hash_info->dst_addr = tvb_get_letohl(tvb, offset); offset += 4; } @@ -348,82 +333,77 @@ static int get_address_v5( const u_char *pd, int offset, offset += 16; else if ( a_type == 3) /* domain name address */ - offset += GBYTE( pd, offset) + 1; - + offset += tvb_get_guint8(tvb, offset) + 1; return offset; } /********************* V5 UDP Associate handlers ***********************/ -static void socks_udp_dissector( const u_char *pd, int offset, frame_data *fd, - proto_tree *tree) { +static void +socks_udp_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { /* Conversation dissector called from UDP dissector. Decode and display */ /* the socks header, the pass the rest of the data to the udp port */ /* decode routine to handle the payload. */ + int offset = 0; guint32 *ptr; socks_hash_entry_t *hash_info; conversation_t *conversation; proto_tree *socks_tree; proto_item *ti; - tvbuff_t *tvb; +//XX tvbuff_t *tvb; - conversation = find_conversation( &pi.src, &pi.dst, pi.ptype, - pi.srcport, pi.destport, 0); + conversation = find_conversation( &pinfo->src, &pinfo->dst, pinfo->ptype, + pinfo->srcport, pinfo->destport, 0); g_assert( conversation); /* should always find a conversation */ hash_info = conversation_get_proto_data(conversation, proto_socks); - if (check_col(fd, COL_PROTOCOL)) - col_set_str(fd, COL_PROTOCOL, "Socks"); + if (check_col(pinfo->fd, COL_PROTOCOL)) + col_set_str(pinfo->fd, COL_PROTOCOL, "Socks"); - if (check_col(fd, COL_INFO)) - col_add_fstr(fd, COL_INFO, "Version: 5, UDP Associated packet"); + if (check_col(pinfo->fd, COL_INFO)) + col_add_fstr(pinfo->fd, COL_INFO, "Version: 5, UDP Associated packet"); if ( tree) { - ti = proto_tree_add_protocol_format( tree, proto_socks, NullTVB, offset, - END_OF_FRAME, "Socks" ); + ti = proto_tree_add_protocol_format( tree, proto_socks, tvb, offset, + tvb_length_remaining(tvb, offset), "Socks" ); socks_tree = proto_item_add_subtree(ti, ett_socks); - CHECK_PACKET_LENGTH( 3); - - proto_tree_add_text( socks_tree, NullTVB, offset, 2, "Reserved"); + proto_tree_add_text( socks_tree, tvb, offset, 2, "Reserved"); offset += 2; - proto_tree_add_text( socks_tree, NullTVB, offset, 1, "Fragment Number: %d", GBYTE( pd,offset)); + proto_tree_add_text( socks_tree, tvb, offset, 1, "Fragment Number: %d", tvb_get_guint8(tvb, offset)); ++offset; - offset = display_address( pd, offset, fd, socks_tree); - hash_info->udp_remote_port = pntohs( &pd[ offset]); + offset = display_address( tvb, offset, pinfo, socks_tree); + hash_info->udp_remote_port = tvb_get_ntohs(tvb, offset); - CHECK_PACKET_LENGTH( 2); - proto_tree_add_uint( socks_tree, hf_socks_dstport, NullTVB, + proto_tree_add_uint( socks_tree, hf_socks_dstport, tvb, offset, 2, hash_info->udp_remote_port); offset += 2; } else { /* no tree, skip past the socks header */ - CHECK_PACKET_LENGTH( 3); offset += 3; - offset = get_address_v5( pd,offset, 0) + 2; + offset = get_address_v5( tvb, offset, 0) + 2; } /* set pi src/dst port and call the udp sub-dissector lookup */ - if ( pi.srcport == (guint32) hash_info->port) - ptr = &pi.destport; + if ( pi.srcport == hash_info->port) + ptr = &pinfo->destport; else - ptr = &pi.srcport; + ptr = &pinfo->srcport; *ptr = hash_info->udp_remote_port; - tvb = tvb_create_from_top(0); decode_udp_ports( tvb, offset, &pi, tree, pi.srcport, pi.destport); *ptr = hash_info->udp_port; @@ -431,15 +411,16 @@ static void socks_udp_dissector( const u_char *pd, int offset, frame_data *fd, } -void new_udp_conversation( socks_hash_entry_t *hash_info){ +void +new_udp_conversation( socks_hash_entry_t *hash_info, packet_info *pinfo){ - conversation_t *conversation = conversation_new( &pi.src, &pi.dst, PT_UDP, + conversation_t *conversation = conversation_new( &pinfo->src, &pinfo->dst, PT_UDP, hash_info->udp_port, hash_info->port, 0); g_assert( conversation); conversation_add_proto_data(conversation, proto_socks, hash_info); - old_conversation_set_dissector(conversation, socks_udp_dissector); + conversation_set_dissector(conversation, socks_udp_dissector); } @@ -447,9 +428,8 @@ void new_udp_conversation( socks_hash_entry_t *hash_info){ /**************** Protocol Tree Display routines ******************/ - -void display_socks_v4( const u_char *pd, int offset, frame_data *fd, - proto_tree *parent, proto_tree *tree, socks_hash_entry_t *hash_info) { +void +display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent, proto_tree *tree, socks_hash_entry_t *hash_info) { /* Display the protocol tree for the V5 version. This routine uses the */ @@ -464,69 +444,67 @@ void display_socks_v4( const u_char *pd, int offset, frame_data *fd, /* Display command from client */ if (compare_packet( hash_info->connect_row)){ - CHECK_PACKET_LENGTH( 8); - proto_tree_add_text( tree, NullTVB, offset, 1, + proto_tree_add_text( tree, tvb, offset, 1, "Version: %u ", hash_info->version); ++offset; - command = GBYTE( pd, offset); + command = tvb_get_guint8(tvb, offset); - proto_tree_add_text( tree, NullTVB, offset, 1, + proto_tree_add_text( tree, tvb, offset, 1, "Command: %u (%s)", command, get_command_name( command)); ++offset; /* Do remote port */ - proto_tree_add_uint( tree, hf_socks_dstport, NullTVB, offset, 2, - pntohs( &pd[ offset])); + proto_tree_add_uint( tree, hf_socks_dstport, tvb, offset, 2, + tvb_get_ntohs(tvb, offset)); offset += 2; /* Do destination address */ - proto_tree_add_ipv4( tree, hf_socks_ip_dst, NullTVB, offset, - 4, GWORD( pd, offset)); + proto_tree_add_ipv4( tree, hf_socks_ip_dst, tvb, offset, + 4, tvb_get_letohl(tvb, offset)); offset += 4; -/*$$ check this, needs to do length checking */ +/*XXX check this, needs to do length checking */ /* display user name */ - proto_tree_add_string( tree, hf_user_name, NullTVB, offset, - strlen( &pd[offset]) + 1, - &pd[offset]); + proto_tree_add_string( tree, hf_user_name, tvb, offset, + strlen( tvb_get_ptr(tvb, offset, -1)) + 1, + tvb_get_ptr(tvb, offset, -1)); } /*Display command response from server*/ else if ( compare_packet( hash_info->cmd_reply_row)){ - CHECK_PACKET_LENGTH( 8); - proto_tree_add_text( tree, NullTVB, offset, 1, - "Version: %u (should be 0) ", GBYTE( pd, offset)); + proto_tree_add_text( tree, tvb, offset, 1, + "Version: %u (should be 0) ", tvb_get_guint8(tvb, offset)); ++offset; /* Do results code */ - proto_tree_add_text( tree, NullTVB, offset, 1, - "Result Code: %u (%s)", GBYTE( pd, offset) , - reply_table_v4[ MAX(0, MIN( GBYTE( pd, offset) - 90, 4))]); + proto_tree_add_text( tree, tvb, offset, 1, + "Result Code: %u (%s)", tvb_get_guint8(tvb, offset) , + reply_table_v4[ MAX(0, MIN( tvb_get_guint8(tvb, offset) - 90, 4))]); ++offset; /* Do remote port */ - proto_tree_add_uint( tree, hf_socks_dstport, NullTVB, offset, 2, - pntohs( &pd[ offset])); + proto_tree_add_uint( tree, hf_socks_dstport, tvb, offset, 2, + tvb_get_ntohs(tvb, offset)); offset += 2;; /* Do remote address */ - proto_tree_add_ipv4( tree, hf_socks_ip_dst, NullTVB, offset, 4, - GWORD( pd, offset)); + proto_tree_add_ipv4( tree, hf_socks_ip_dst, tvb, offset, 4, + tvb_get_letohl(tvb, offset)); } else if ( compare_packet( hash_info->v4_user_name_row)){ -/*$$ check this, needs to do length checking */ - proto_tree_add_text( tree, NullTVB, offset, strlen( &pd[offset]), - "User Name: %s", &pd[offset]); +/*XXX check this, needs to do length checking */ + proto_tree_add_text( tree, tvb, offset, strlen( tvb_get_ptr(tvb, offset, -1)), + "User Name: %s", tvb_get_ptr(tvb, offset, -1)); } } - -void display_socks_v5( const u_char *pd, int offset, frame_data *fd, +void +display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *parent, proto_tree *tree, socks_hash_entry_t *hash_info) { /* Display the protocol tree for the version. This routine uses the */ @@ -545,56 +523,52 @@ void display_socks_v5( const u_char *pd, int offset, frame_data *fd, proto_tree *AuthTree; proto_item *ti; - CHECK_PACKET_LENGTH( 2); /* Do version */ - proto_tree_add_uint( tree, hf_socks_ver, NullTVB, offset, 1, + proto_tree_add_uint( tree, hf_socks_ver, tvb, offset, 1, hash_info->version); ++offset; - temp = GBYTE( pd, offset); /* Get Auth method count */ + temp = tvb_get_guint8(tvb, offset); /* Get Auth method count */ /* build auth tree */ - ti = proto_tree_add_text( tree, NullTVB, offset, 1, + ti = proto_tree_add_text( tree, tvb, offset, 1, "Client Authentication Methods"); AuthTree = proto_item_add_subtree(ti, ett_socks_auth); - proto_tree_add_text( AuthTree, NullTVB, offset, 1, + proto_tree_add_text( AuthTree, tvb, offset, 1, "Count: %u ", temp); ++offset; - CHECK_PACKET_LENGTH( (int)temp); - for( i = 0; i < temp; ++i) { AuthMethodStr = get_auth_method_name( - GBYTE( pd, offset + i)); - proto_tree_add_text( AuthTree, NullTVB, offset + i, 1, + tvb_get_guint8( tvb, offset + i)); + proto_tree_add_text( AuthTree, tvb, offset + i, 1, "Method[%d]: %u (%s)", i, - GBYTE( pd, offset + i), AuthMethodStr); + tvb_get_guint8( tvb, offset + i), AuthMethodStr); } return; } /* Get accepted auth method */ else if (compare_packet( hash_info->auth_method_row)) { ++offset; - CHECK_PACKET_LENGTH( 1); - proto_tree_add_text( tree, NullTVB, offset, 1, - "Accepted Auth Method: 0x%0x (%s)", GBYTE( pd, offset), - get_auth_method_name( GBYTE( pd, offset))); + proto_tree_add_text( tree, tvb, offset, 1, + "Accepted Auth Method: 0x%0x (%s)", tvb_get_guint8( tvb, offset), + get_auth_method_name( tvb_get_guint8( tvb, offset))); return; } /* handle user/password auth */ else if (compare_packet( hash_info->user_name_auth_row)) { - proto_tree_add_text( tree, NullTVB, offset, 1, + proto_tree_add_text( tree, tvb, offset, 1, "Version: %u ", hash_info->version); ++offset; /* process user name */ - offset += display_string( pd, offset, fd, tree, + offset += display_string( tvb, offset, pinfo, tree, "User name"); /* process password */ - offset += display_string( pd, offset, fd, tree, + offset += display_string( tvb, offset, pinfo, tree, "Password"); } /* command to the server */ @@ -603,37 +577,34 @@ void display_socks_v5( const u_char *pd, int offset, frame_data *fd, (compare_packet( hash_info->cmd_reply_row)) || (compare_packet( hash_info->bind_reply_row))){ - proto_tree_add_text( tree, NullTVB, offset, 1, + proto_tree_add_text( tree, tvb, offset, 1, "Version: %u ", hash_info->version); - CHECK_PACKET_LENGTH( 1); - ++offset; - command = GBYTE( pd, offset); + command = tvb_get_guint8(tvb, offset); if (compare_packet( hash_info->command_row)) - proto_tree_add_text( tree, NullTVB, offset, 1, "Command: %u (%s)", + proto_tree_add_text( tree, tvb, offset, 1, "Command: %u (%s)", command, get_command_name( command)); else - proto_tree_add_text( tree, NullTVB, offset, 1, "Status: %d (%s)", - GBYTE( pd, offset), reply_table_v5[ MAX( 0, - MIN(GBYTE( pd, offset) - 90, 9))]); + proto_tree_add_text( tree, tvb, offset, 1, "Status: %d (%s)", + tvb_get_guint8(tvb, offset), reply_table_v5[ MAX( 0, + MIN(tvb_get_guint8(tvb, offset) - 90, 9))]); ++offset; - proto_tree_add_text( tree, NullTVB, offset, 1, - "Reserved: 0x%0x (should = 0x00)", GBYTE( pd, offset)); + proto_tree_add_text( tree, tvb, offset, 1, + "Reserved: 0x%0x (should = 0x00)", tvb_get_guint8(tvb, offset)); ++offset; - offset = display_address( pd, offset, fd, tree); + offset = display_address(tvb, offset, pinfo, tree); - CHECK_PACKET_LENGTH( 2); /* Do remote port */ - proto_tree_add_text( tree, NullTVB, offset, 2, + proto_tree_add_text( tree, tvb, offset, 2, "%sPort: %d", (compare_packet( hash_info->bind_reply_row) ? "Remote Host " : ""), - pntohs( &pd[ offset])); + tvb_get_ntohs(tvb, offset)); } } @@ -642,8 +613,8 @@ void display_socks_v5( const u_char *pd, int offset, frame_data *fd, /**************** Decoder State Machines ******************/ -static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, - int offset, frame_data *fd) { +static guint +state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb, int offset, packet_info *pinfo) { /* Decode V4 protocol. This is done on the first pass through the */ /* list. Based upon the current state, decode the packet and determine */ @@ -652,17 +623,17 @@ static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, if ( hash_info->state == None) { /* new connection */ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Connect to server request"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Connect to server request"); hash_info->state = Connecting; /* change state */ - hash_info->command = GBYTE( pd, offset + 1); + hash_info->command = tvb_get_guint8(tvb, offset + 1); /* get remote port */ if ( hash_info->command == CONNECT_COMMAND) - hash_info->port = pntohs( &pd[ offset + 2]); + hash_info->port = tvb_get_ntohs(tvb, offset + 2); /* get remote address */ - hash_info->dst_addr = GWORD( pd, offset + 4); + hash_info->dst_addr = tvb_get_letohl(tvb, offset + 4); /* save the packet pointer */ hash_info->connect_row = get_packet_ptr; @@ -672,17 +643,17 @@ static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, offset += 8; - if ( offset == pi.len) /* if no user name */ + if ( offset == pinfo->len) /* if no user name */ /* change state */ hash_info->state = V4UserNameWait; - hash_info->connect_offset += strlen( &pd[ offset]) + 1; + hash_info->connect_offset += strlen( tvb_get_ptr(tvb, offset, -1)) + 1; if ( !hash_info->dst_addr){ /* if no dest address */ /* if more data */ - if ( hash_info->connect_offset < pi.len ) { -/*$$$ copy remote name here ??? */ + if ( hash_info->connect_offset < pinfo->len ) { +/*XXX copy remote name here ??? */ hash_info->state = Connecting; } else @@ -691,11 +662,11 @@ static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, /* waiting for V4 user name */ }else if ( hash_info->state == V4UserNameWait){ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Connect Request (User name)"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Connect Request (User name)"); hash_info->v4_user_name_row = get_packet_ptr; -/*$$$ may need to check for domain name here */ +/*XXX may need to check for domain name here */ hash_info->state = Connecting; } /* waiting for V4 domain name */ @@ -707,8 +678,8 @@ static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, } else if ( hash_info->state == Connecting){ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Connect Response"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Connect Response"); /* save packet pointer */ hash_info->cmd_reply_row = get_packet_ptr; @@ -721,8 +692,8 @@ static guint state_machine_v4( socks_hash_entry_t *hash_info, const u_char *pd, -static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, - int offset, frame_data *fd) { +static void +state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb, int offset, packet_info *pinfo) { /* Decode V5 protocol. This is done on the first pass through the */ /* list. Based upon the current state, decode the packet and determine */ @@ -734,27 +705,22 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, if ( hash_info->state == None) { - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Connect to server request"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Connect to server request"); hash_info->state = Connecting; /* change state */ hash_info->connect_row = get_packet_ptr; - if (!BYTES_ARE_IN_FRAME(offset, 1)){ - hash_info->state = Done; /* change state */ - return; - } - - temp = GBYTE( pd, offset + 1); + temp = tvb_get_guint8(tvb, offset + 1); /* skip past auth methods */ offset = hash_info->connect_offset = offset + 1 + temp; } else if ( hash_info->state == Connecting){ - guint AuthMethod = GBYTE( pd, offset + 1); + guint AuthMethod = tvb_get_guint8(tvb, offset + 1); - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Connect to server response"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Connect to server response"); hash_info->auth_method_row = get_packet_ptr; @@ -765,7 +731,7 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, hash_info->state = UserNameAuth; else if ( AuthMethod == GSS_API_AUTHENTICATION) -/*$$$ should be this hash_info->state = GssApiAuth; */ +/*XXX should be this hash_info->state = GssApiAuth; */ hash_info->state = Done; else hash_info->state = Done; /*Auth failed or error*/ @@ -776,15 +742,10 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, guint temp; - if (!BYTES_ARE_IN_FRAME(offset, 1)){ - hash_info->state = Done; /* change state */ - return; - } - - hash_info->command = GBYTE( pd, offset + 1); /* get command */ + hash_info->command = tvb_get_guint8(tvb, offset + 1); /* get command */ - if (check_col(fd, COL_INFO)) - col_append_fstr(fd, COL_INFO, " Command Request - %s", + if (check_col(pinfo->fd, COL_INFO)) + col_append_fstr(pinfo->fd, COL_INFO, " Command Request - %s", get_command_name(hash_info->command)); hash_info->state = V5Reply; @@ -792,25 +753,21 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, offset += 3; /* skip to address type */ - offset = get_address_v5( pd, offset, hash_info); + offset = get_address_v5(tvb, offset, hash_info); - if (!BYTES_ARE_IN_FRAME(offset, 1)){ - hash_info->state = Done; - return; - } - temp = GBYTE( pd, offset); + temp = tvb_get_guint8(tvb, offset); if (( hash_info->command == CONNECT_COMMAND) || ( hash_info->command == UDP_ASSOCIATE_COMMAND)) /* get remote port */ - hash_info->port = pntohs( &pd[ offset]); + hash_info->port = tvb_get_ntohs(tvb, offset); } else if ( hash_info->state == V5Reply) { /* V5 Command Reply */ - if (check_col(fd, COL_INFO)) - col_append_fstr(fd, COL_INFO, " Command Response - %s", + if (check_col(pinfo->fd, COL_INFO)) + col_append_fstr(pinfo->fd, COL_INFO, " Command Response - %s", get_command_name(hash_info->command)); hash_info->cmd_reply_row = get_packet_ptr; @@ -825,33 +782,29 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, else if ( hash_info->command == UDP_ASSOCIATE_COMMAND){ offset += 3; /* skip to address type */ - offset = get_address_v5( pd, offset, hash_info); + offset = get_address_v5(tvb, offset, hash_info); /* save server udp port and create udp conversation */ - if (!BYTES_ARE_IN_FRAME(offset, 2)){ - hash_info->state = Done; - return; - } - hash_info->udp_port = pntohs( &pd[ offset]); + hash_info->udp_port = tvb_get_ntohs(tvb, offset); - if (!fd->flags.visited) - new_udp_conversation( hash_info); + if (!pinfo->fd->flags.visited) + new_udp_conversation( hash_info, pinfo); -/*$$ may need else statement to handle unknows and generate error message */ +/*XXX may need else statement to handle unknows and generate error message */ } } else if ( hash_info->state == V5BindReply) { /* V5 Bind Second Reply */ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " Command Response: Bind remote host info"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " Command Response: Bind remote host info"); hash_info->bind_reply_row = get_packet_ptr; hash_info->state = Done; } else if ( hash_info->state == UserNameAuth) { /* Handle V5 User Auth*/ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " User authentication response"); hash_info->user_name_auth_row = get_packet_ptr; @@ -860,16 +813,16 @@ static void state_machine_v5( socks_hash_entry_t *hash_info, const u_char *pd, } else if ( hash_info->state == AuthReply){ /* V5 User Auth reply */ hash_info->cmd_reply_row = get_packet_ptr; - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, " User authentication reply"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, " User authentication reply"); hash_info->state = V5Command; } } -static void display_ping_and_tracert( const u_char *pd, int offset, - frame_data *fd, proto_tree *tree, socks_hash_entry_t *hash_info) { +static void +display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, socks_hash_entry_t *hash_info) { /* Display the ping/trace_route conversation */ @@ -879,35 +832,35 @@ static void display_ping_and_tracert( const u_char *pd, int offset, int linelen; /* handle the end command */ - if ( pi.destport == TCP_PORT_SOCKS){ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, ", Terminate Request"); + if ( pinfo->destport == TCP_PORT_SOCKS){ + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, ", Terminate Request"); if ( tree) - proto_tree_add_text(tree, NullTVB, offset, 1, + proto_tree_add_text(tree, tvb, offset, 1, (hash_info->command == PING_COMMAND) ? "Ping: End command" : "Traceroute: End command"); } else{ /* display the PING or Traceroute results */ - if (check_col(fd, COL_INFO)) - col_append_str(fd, COL_INFO, ", Results"); + if (check_col(pinfo->fd, COL_INFO)) + col_append_str(pinfo->fd, COL_INFO, ", Results"); if ( tree){ - proto_tree_add_text(tree, NullTVB, offset, END_OF_FRAME, + proto_tree_add_text(tree, tvb, offset, END_OF_FRAME, (hash_info->command == PING_COMMAND) ? "Ping Results:" : "Traceroute Results"); - data = &pd[offset]; - dataend = data + END_OF_FRAME; + data = tvb_get_ptr(tvb, offset, -1); + dataend = data + tvb_length_remaining(tvb, offset); while (data < dataend) { lineend = find_line_end(data, dataend, &eol); linelen = lineend - data; - proto_tree_add_text( tree, NullTVB, offset, linelen, + proto_tree_add_text( tree, tvb, offset, linelen, format_text(data, linelen)); offset += linelen; data = lineend; @@ -918,7 +871,7 @@ static void display_ping_and_tracert( const u_char *pd, int offset, -static void call_next_dissector( const u_char *pd, int offset, frame_data *fd, +static void call_next_dissector(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, socks_hash_entry_t *hash_info) { /* Display the results for PING and TRACERT extensions or */ @@ -929,25 +882,23 @@ static void call_next_dissector( const u_char *pd, int offset, frame_data *fd, /* payload, and restore the pi port after that is done. */ guint32 *ptr; - tvbuff_t *tvb; if (( hash_info->command == PING_COMMAND) || ( hash_info->command == TRACERT_COMMAND)) - display_ping_and_tracert( pd, offset, fd, tree, hash_info); + display_ping_and_tracert(tvb, offset, pinfo, tree, hash_info); else { /* call the tcp port decoder to handle the payload */ -/*$$$ may want to load dest address here */ +/*XXX may want to load dest address here */ - if ( pi.destport == TCP_PORT_SOCKS) - ptr = &pi.destport; + if ( pinfo->destport == TCP_PORT_SOCKS) + ptr = &pinfo->destport; else - ptr = &pi.srcport; + ptr = &pinfo->srcport; *ptr = hash_info->port; - tvb = tvb_create_from_top(0); - decode_tcp_ports( tvb, offset, &pi, tree, pi.srcport, pi.destport); + decode_tcp_ports( tvb, offset, pinfo, tree, pinfo->srcport, pinfo->destport); *ptr = TCP_PORT_SOCKS; } } @@ -955,29 +906,29 @@ static void call_next_dissector( const u_char *pd, int offset, frame_data *fd, static void -dissect_socks(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { +dissect_socks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { + int offset = 0; proto_tree *socks_tree; proto_item *ti; socks_hash_entry_t *hash_info; conversation_t *conversation; - OLD_CHECK_DISPLAY_AS_DATA(proto_socks, pd, offset, fd, tree); - - conversation = find_conversation( &pi.src, &pi.dst, pi.ptype, - pi.srcport, pi.destport, 0); + conversation = find_conversation( &pinfo->src, &pinfo->dst, pinfo->ptype, + pinfo->srcport, pinfo->destport, 0); if ( !conversation){ - conversation = conversation_new( &pi.src, &pi.dst, pi.ptype, - pi.srcport, pi.destport, 0); + conversation = conversation_new( &pinfo->src, &pinfo->dst, pinfo->ptype, + pinfo->srcport, pinfo->destport, 0); } hash_info = conversation_get_proto_data(conversation,proto_socks); if ( !hash_info){ hash_info = g_mem_chunk_alloc(socks_vals); hash_info->start_done_row = G_MAXINT; hash_info->state = None; - hash_info->port = -1; - hash_info->version = GBYTE( pd, offset); /* get version*/ +//XX hash_info->port = -1; + hash_info->port = 0; + hash_info->version = tvb_get_guint8(tvb, offset); /* get version*/ if (( hash_info->version != 4) && /* error test version */ ( hash_info->version != 5)) @@ -987,80 +938,81 @@ dissect_socks(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { hash_info); /* set dissector for now */ - old_conversation_set_dissector(conversation, dissect_socks); + conversation_set_dissector(conversation, dissect_socks); } /* display summary window information */ - if (check_col(fd, COL_PROTOCOL)) - col_set_str(fd, COL_PROTOCOL, "Socks"); + if (check_col(pinfo->fd, COL_PROTOCOL)) + col_set_str(pinfo->fd, COL_PROTOCOL, "Socks"); - if (check_col(fd, COL_INFO)){ + if (check_col(pinfo->fd, COL_INFO)){ if (( hash_info->version == 4) || ( hash_info->version == 5)){ - col_add_fstr(fd, COL_INFO, "Version: %d", + col_add_fstr(pinfo->fd, COL_INFO, "Version: %d", hash_info->version); } else /* unknown version display error */ - col_set_str(fd, COL_INFO, "Unknown"); + col_set_str(pinfo->fd, COL_INFO, "Unknown"); if ( hash_info->command == PING_COMMAND) - col_append_str(fd, COL_INFO, ", Ping Req"); + col_append_str(pinfo->fd, COL_INFO, ", Ping Req"); if ( hash_info->command == TRACERT_COMMAND) - col_append_str(fd, COL_INFO, ", Traceroute Req"); + col_append_str(pinfo->fd, COL_INFO, ", Traceroute Req"); - if ( hash_info->port != -1) - col_append_fstr(fd, COL_INFO, ", Remote Port: %d", +//XX if ( hash_info->port != -1) + if ( hash_info->port != 0) + col_append_fstr(pinfo->fd, COL_INFO, ", Remote Port: %d", hash_info->port); } /* run state machine if needed */ - if ((hash_info->state != Done) && ( !fd->flags.visited)){ + if ((hash_info->state != Done) && ( !pinfo->fd->flags.visited)){ if ( hash_info->version == 4) - state_machine_v4( hash_info, pd, offset, fd); + state_machine_v4( hash_info, tvb, offset, pinfo); else if ( hash_info->version == 5) - state_machine_v5( hash_info, pd, offset, fd); + state_machine_v5( hash_info, tvb, offset, pinfo); if (hash_info->state == Done) { /* if done now */ - hash_info->start_done_row = fd->num; + hash_info->start_done_row = pinfo->fd->num; } } /* if proto tree, decode and display */ if (tree) { - ti = proto_tree_add_item( tree, proto_socks, NullTVB, offset, - END_OF_FRAME, FALSE ); + ti = proto_tree_add_item( tree, proto_socks, tvb, offset, + tvb_length_remaining(tvb, offset), FALSE ); socks_tree = proto_item_add_subtree(ti, ett_socks); if ( hash_info->version == 4) - display_socks_v4( pd, offset, fd, tree, socks_tree, + display_socks_v4(tvb, offset, pinfo, tree, socks_tree, hash_info); else if ( hash_info->version == 5) - display_socks_v5( pd, offset, fd, tree, socks_tree, + display_socks_v5(tvb, offset, pinfo, tree, socks_tree, hash_info); /* if past startup, add the faked stuff */ - if ( fd->num > hash_info->start_done_row){ + if ( pinfo->fd->num > hash_info->start_done_row){ /* add info to tree */ - proto_tree_add_text( socks_tree, NullTVB, offset, 0, + proto_tree_add_text( socks_tree, tvb, offset, 0, "Command: %d (%s)", hash_info->command, get_command_name(hash_info->command)); - proto_tree_add_ipv4( socks_tree, hf_socks_ip_dst, NullTVB, + proto_tree_add_ipv4( socks_tree, hf_socks_ip_dst, tvb, offset, 0, hash_info->dst_addr); /* no fake address for ping & traceroute */ if (( hash_info->command != PING_COMMAND) && ( hash_info->command != TRACERT_COMMAND)){ - proto_tree_add_uint( socks_tree, hf_socks_dstport, NullTVB, + proto_tree_add_uint( socks_tree, hf_socks_dstport, tvb, offset, 0, hash_info->port); } } @@ -1070,8 +1022,8 @@ dissect_socks(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) { /* call next dissector if ready */ - if ( fd->num > hash_info->start_done_row){ - call_next_dissector( pd, offset, fd, tree, hash_info); + if ( pinfo->fd->num > hash_info->start_done_row){ + call_next_dissector(tvb, offset, pinfo, tree, hash_info); } } @@ -1159,6 +1111,6 @@ proto_reg_handoff_socks(void) { /* dissector install routine */ - old_dissector_add("tcp.port", TCP_PORT_SOCKS, dissect_socks, + dissector_add("tcp.port", TCP_PORT_SOCKS, dissect_socks, proto_socks); } |