Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-socks.c
index b52ca16ecc1679ce0c018955f8b19c1a1c05bcec..a623c06b1a581d1a34985d5911c03f854ece674b 100644 (file)
@@ -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.26 2001/10/30 10:40:38 guy Exp $
+ * $Id: packet-socks.c,v 1.42 2002/08/02 23:36:03 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #endif
 
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <stdio.h>
 #include <string.h>
 #include <glib.h>
 
-#ifdef NEED_SNPRINTF_H
-# include "snprintf.h"
-#endif
-
-#include "packet.h"
-#include "resolv.h"
+#include <epan/packet.h>
+#include <epan/resolv.h>
 #include "alignment.h"
-#include "conversation.h"
+#include <epan/conversation.h>
 
 #include "packet-tcp.h"
 #include "packet-udp.h"
-#include "strutil.h"
+#include <epan/strutil.h>
 
 
 #define compare_packet(X) (X == (pinfo->fd->num))
@@ -119,8 +107,16 @@ static int hf_socks_ip_dst = -1;
 static int hf_socks_ip6_dst = -1;
 static int hf_user_name = -1;
 static int hf_socks_dstport = -1;
-static int hf_socks_command = -1;
+static int hf_socks_cmd = -1;
+static int hf_socks_results = -1;
+static int hf_socks_results_4 = -1;
+static int hf_socks_results_5 = -1;
+
+
+/************* Dissector handles ***********/
 
+static dissector_handle_t socks_handle;
+static dissector_handle_t socks_udp_handle;
 
 /************* State Machine names ***********/
 
@@ -178,6 +174,7 @@ static char *address_type_table[] = {
 
 /* String table for the V4 reply status messages */
 
+#ifdef __JUNK__
 static char *reply_table_v4[] = {
        "Granted",
        "Rejected or Failed",
@@ -185,10 +182,19 @@ static char *reply_table_v4[] = {
        "Rejected because the client program and identd report different user-ids",
        "Unknown"
 };
+#endif
 
+static const value_string reply_table_v4[] = {
+       {90, "Granted"},
+       {91, "Rejected or Failed"},
+       {92, "Rejected because SOCKS server cannot connect to identd on the client"},
+       {93, "Rejected because the client program and identd report different user-ids"},
+       {0, NULL}
+};
 
 /* String table for the V5 reply status messages */
 
+#ifdef __JUNK__
 static char *reply_table_v5[] = {
        "Succeeded",
        "General SOCKS server failure",
@@ -201,7 +207,29 @@ static char *reply_table_v5[] = {
        "Address type not supported",
        "Unknown"
 };
+#endif 
+
+static const value_string reply_table_v5[] = {
+       {0, "Succeeded"},
+       {1, "General SOCKS server failure"},
+       {2, "Connection not allowed by ruleset"},
+       {3, "Network unreachable"},
+       {4, "Host unreachable"},
+       {5, "Connection refused"},
+       {6, "TTL expired"},
+       {7, "Command not supported"},
+       {8, "Address type not supported"}
+};
 
+static const value_string cmd_strings[] = {
+       {0, "Unknow"},
+       {1, "Connect"},
+       {2, "Bind"}, 
+       {3, "UdpAssociate"},
+       {0x80, "Ping"},
+       {0x81, "Traceroute"},
+       {0, NULL}
+};
 
 #define socks_hash_init_count 20
 #define socks_hash_val_length (sizeof(socks_hash_entry_t))
@@ -212,7 +240,7 @@ static GMemChunk *socks_vals = NULL;
 /************************* Support routines ***************************/
 
 
-static int display_string(tvbuff_t *tvb, int offset, packet_info *pinfo,
+static int display_string(tvbuff_t *tvb, int offset,
        proto_tree *tree, char *label){
 
 /* display a string with a length, characters encoding */
@@ -223,11 +251,10 @@ static int display_string(tvbuff_t *tvb, int offset, packet_info *pinfo,
        proto_tree      *name_tree;
        proto_item      *ti;
 
-
        char temp[ 256];
        int length = tvb_get_guint8(tvb, offset);
 
-       strncpy( temp, tvb_get_ptr(tvb, offset+1, -1), length);
+       tvb_memcpy(tvb, (guint8 *)temp, offset+1, length);
        temp[ length ] = 0;
   
        ti = proto_tree_add_text(tree, tvb, offset, length + 1,
@@ -236,7 +263,7 @@ static int display_string(tvbuff_t *tvb, int offset, packet_info *pinfo,
 
        name_tree = proto_item_add_subtree(ti, ett_socks_name);
 
-       proto_tree_add_text( name_tree, tvb, offset, 1, "Length: %d", length);
+       proto_tree_add_text( name_tree, tvb, offset, 1, "Length: %u", length);
 
        ++offset;
 
@@ -279,8 +306,7 @@ static char *get_command_name( guint Number){
 }
 
 
-static int display_address(tvbuff_t *tvb, int offset,
-               packet_info *pinfo, proto_tree *tree) {
+static int display_address(tvbuff_t *tvb, int offset, proto_tree *tree) {
 
 /* decode and display the v5 address, return offset of next byte */
 
@@ -300,7 +326,7 @@ static int display_address(tvbuff_t *tvb, int offset,
        }       
        else if ( a_type == 3){ /* domain name address */
 
-               offset += display_string(tvb, offset, pinfo, tree,
+               offset += display_string(tvb, offset, tree,
                        "Remote name");
        }
        else if ( a_type == 4){ /* IPv6 address */
@@ -362,15 +388,15 @@ socks_udp_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
 
        hash_info = conversation_get_proto_data(conversation, proto_socks);
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "Socks");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "Socks");
 
-       if (check_col(pinfo->fd, COL_INFO))
-               col_add_fstr(pinfo->fd, COL_INFO, "Version: 5, UDP Associated packet");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_add_fstr(pinfo->cinfo, COL_INFO, "Version: 5, UDP Associated packet");
                        
        if ( tree) {
-               ti = proto_tree_add_protocol_format( tree, proto_socks, tvb, offset,
-                       tvb_length_remaining(tvb, offset), "Socks" );
+               ti = proto_tree_add_protocol_format( tree, proto_socks, tvb,
+                       offset, -1, "Socks" );
 
                socks_tree = proto_item_add_subtree(ti, ett_socks);
 
@@ -381,7 +407,7 @@ socks_udp_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
                ++offset;
        
 
-               offset = display_address( tvb, offset, pinfo, socks_tree);
+               offset = display_address( tvb, offset, socks_tree);
                hash_info->udp_remote_port = tvb_get_ntohs(tvb, offset);
                
                proto_tree_add_uint( socks_tree, hf_socks_dstport, tvb,
@@ -404,14 +430,14 @@ socks_udp_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
 
         *ptr = hash_info->udp_remote_port;
        
-       decode_udp_ports( tvb, offset, &pi, tree, pinfo->srcport, pinfo->destport);
+       decode_udp_ports( tvb, offset, pinfo, tree, pinfo->srcport, pinfo->destport);
  
         *ptr = hash_info->udp_port;
 
 }
 
                        
-void 
+static void 
 new_udp_conversation( socks_hash_entry_t *hash_info, packet_info *pinfo){
 
        conversation_t *conversation = conversation_new( &pinfo->src, &pinfo->dst,  PT_UDP,
@@ -420,7 +446,7 @@ new_udp_conversation( socks_hash_entry_t *hash_info, packet_info *pinfo){
        g_assert( conversation);
        
        conversation_add_proto_data(conversation, proto_socks, hash_info);
-       conversation_set_dissector(conversation, socks_udp_dissector);
+       conversation_set_dissector(conversation, socks_udp_handle);
 }
 
 
@@ -428,19 +454,19 @@ new_udp_conversation( socks_hash_entry_t *hash_info, packet_info *pinfo){
 
 /**************** Protocol Tree Display routines  ******************/
 
-void
+static void
 display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo,
-       proto_tree *parent, proto_tree *tree, socks_hash_entry_t *hash_info) {
+       proto_tree *tree, socks_hash_entry_t *hash_info) {
 
 
-/* Display the protocol tree for the V5 version. This routine uses the */
+/* Display the protocol tree for the V4 version. This routine uses the */
 /* stored conversation information to decide what to do with the row.  */
 /* Per packet information would have been better to do this, but we    */
 /* didn't have that when I wrote this. And I didn't expect this to get */
 /* so messy.                                                           */
 
 
-       int command;
+       guint command;
 
                                        /* Display command from client */
        if (compare_packet( hash_info->connect_row)){
@@ -471,7 +497,7 @@ display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo,
                if ( tvb_offset_exists(tvb, offset)) {
                                                /* display user name    */
                        proto_tree_add_string( tree, hf_user_name, tvb, offset, 
-                               strlen( tvb_get_ptr(tvb, offset, -1)) + 1,
+                               tvb_strsize(tvb, offset),
                                tvb_get_ptr(tvb, offset, -1));
                }
 
@@ -480,13 +506,13 @@ display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo,
        
        else if ( compare_packet( hash_info->cmd_reply_row)){
                                 
-               proto_tree_add_text( tree, tvb, offset, 1,
-                       "Version: %u (should be 0) ", tvb_get_guint8(tvb, offset));
+               proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1,
+                               FALSE);
                ++offset;
                                                /* Do results code      */
-               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))]);
+               proto_tree_add_item( tree, hf_socks_results_4, tvb, offset, 1, FALSE);
+               proto_tree_add_item_hidden(tree, hf_socks_results, tvb, offset, 1, FALSE);
+
                ++offset;
 
                                                /* Do remote port       */
@@ -504,16 +530,16 @@ display_socks_v4(tvbuff_t *tvb, int offset, packet_info *pinfo,
 /* Should perhaps do TCP reassembly as well */
                if ( tvb_offset_exists(tvb, offset)) {
                        proto_tree_add_text( tree, tvb, offset,
-                               strlen( tvb_get_ptr(tvb, offset, -1)),
+                               tvb_strsize(tvb, offset),
                                "User Name: %s", tvb_get_ptr(tvb, offset, -1));
                }
        }
 }                      
 
 
-void 
+static void 
 display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo,
-       proto_tree *parent, proto_tree *tree, socks_hash_entry_t *hash_info) {
+       proto_tree *tree, socks_hash_entry_t *hash_info) {
        
 /* Display the protocol tree for the version. This routine uses the    */
 /* stored conversation information to decide what to do with the row.  */
@@ -532,7 +558,7 @@ display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo,
                proto_item      *ti;
 
                                                /* Do version   */
-               proto_tree_add_uint( tree, hf_socks_ver, tvb, offset, 1,
+               proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1,
                                hash_info->version);
                ++offset;
 
@@ -569,14 +595,13 @@ display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo,
        }                                       /* handle user/password auth */
        else if (compare_packet( hash_info->user_name_auth_row)) {
 
-               proto_tree_add_text( tree, tvb, offset, 1,
-                               "Version: %u ", hash_info->version);
+               proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1, FALSE);
                ++offset;
                                                /* process user name    */
-               offset += display_string( tvb, offset, pinfo, tree,
+               offset += display_string( tvb, offset, tree,
                                "User name");
                                                /* process password     */
-               offset += display_string( tvb, offset, pinfo, tree,
+               offset += display_string( tvb, offset, tree,
                                "Password");
        }                                       
                                        /* command to the server */     
@@ -585,28 +610,29 @@ display_socks_v5(tvbuff_t *tvb, int offset, packet_info *pinfo,
                 (compare_packet( hash_info->cmd_reply_row)) ||
                 (compare_packet( hash_info->bind_reply_row))){
 
-               proto_tree_add_text( tree, tvb, offset, 1,
-                       "Version: %u ", hash_info->version);
+               proto_tree_add_item( tree, hf_socks_ver, tvb, offset, 1, FALSE);
 
                ++offset;
 
                command = tvb_get_guint8(tvb, offset);
                
                if (compare_packet( hash_info->command_row))
-                       proto_tree_add_text( tree, tvb, offset, 1, "Command: %u (%s)",
-                               command,  get_command_name( command));
-               else
-                       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))]);
+                       proto_tree_add_uint( tree, hf_socks_cmd, tvb, offset, 1,
+                           command);
+
+               else {
+                       proto_tree_add_item( tree, hf_socks_results_5, tvb, offset, 1, FALSE);
+                       proto_tree_add_item_hidden(tree, hf_socks_results, tvb, offset, 1, FALSE);
+               }
+
                ++offset;
 
                proto_tree_add_text( tree, tvb, offset, 1,
                        "Reserved: 0x%0x (should = 0x00)", tvb_get_guint8(tvb, offset)); 
                ++offset;
 
-               offset = display_address(tvb, offset, pinfo, tree);
-
+               offset = display_address(tvb, offset, tree);
+/*XXX Add remote port for search somehow */
                                                /* Do remote port       */
                proto_tree_add_text( tree, tvb, offset, 2,
                                "%sPort: %d",
@@ -632,8 +658,8 @@ state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
 
        if ( hash_info->state == None) {                /* new connection */
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Connect to server request");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connect to server request");
 
                hash_info->state = Connecting;  /* change state         */
 
@@ -653,12 +679,22 @@ state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
 
                offset += 8;
                
-               if ( !tvb_offset_exists(tvb, offset))   /* if no user name */
+               if ( !tvb_offset_exists(tvb, offset)) { /* if no user name */
                                                        /* change state */
                        hash_info->state = V4UserNameWait;
-               
-                       
-               hash_info->connect_offset += strlen( tvb_get_ptr(tvb, offset, -1)) + 1;
+                       /*
+                        * XXX - add 1, or leave it alone?
+                        * We were adding "strlen(...) + 1".
+                        */
+                       hash_info->connect_offset += 1;
+               } else {
+                       /*
+                        * Add in the length of the user name.
+                        * XXX - what if the user name is split between
+                        * TCP segments?
+                        */
+                       hash_info->connect_offset += tvb_strsize(tvb, offset);
+               }
                
                if ( !hash_info->dst_addr){             /* if no dest address */
                                                        /* if more data */
@@ -672,8 +708,8 @@ state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
                                                /* waiting for V4 user name */
        }else if ( hash_info->state == V4UserNameWait){ 
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Connect Request (User name)");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connect Request (User name)");
 
                hash_info->v4_user_name_row = get_packet_ptr;
 /*XXX may need to check for domain name here */
@@ -688,8 +724,8 @@ state_machine_v4( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
        }
        else if ( hash_info->state == Connecting){
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Connect Response");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connect Response");
 
                                                /* save packet pointer  */
                hash_info->cmd_reply_row = get_packet_ptr;
@@ -716,8 +752,8 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
 
        if ( hash_info->state == None) {
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Connect to server request");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connect to server request");
 
                hash_info->state = Connecting;  /* change state         */
                hash_info->connect_row = get_packet_ptr;        
@@ -730,8 +766,8 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
 
                guint AuthMethod = tvb_get_guint8(tvb, offset + 1);
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Connect to server response");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " Connect to server response");
 
                hash_info->auth_method_row = get_packet_ptr;
 
@@ -755,8 +791,8 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
 
                hash_info->command = tvb_get_guint8(tvb, offset + 1); /* get command */
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_fstr(pinfo->fd, COL_INFO, " Command Request - %s",
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_fstr(pinfo->cinfo, COL_INFO, " Command Request - %s",
                                get_command_name(hash_info->command));
 
                hash_info->state = V5Reply;
@@ -777,8 +813,8 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
        else if ( hash_info->state == V5Reply) {        /* V5 Command Reply */
 
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_fstr(pinfo->fd, COL_INFO, " Command Response - %s",
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_fstr(pinfo->cinfo, COL_INFO, " Command Response - %s",
                                get_command_name(hash_info->command));
 
                hash_info->cmd_reply_row = get_packet_ptr;
@@ -807,15 +843,15 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
        }
        else if ( hash_info->state == V5BindReply) {    /* V5 Bind Second Reply */
 
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " Command Response: Bind remote host info");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, 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(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO,
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO,
                                " User authentication response");
 
                hash_info->user_name_auth_row = get_packet_ptr;
@@ -824,8 +860,8 @@ state_machine_v5( socks_hash_entry_t *hash_info, tvbuff_t *tvb,
        }
        else if ( hash_info->state == AuthReply){       /* V5 User Auth reply */
                hash_info->cmd_reply_row = get_packet_ptr;
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, " User authentication reply");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, " User authentication reply");
                hash_info->state = V5Command;
        }
 }
@@ -838,14 +874,14 @@ display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tr
 /* Display the ping/trace_route conversation */
 
 
-               const u_char    *data, *dataend;
-               const u_char   *lineend, *eol;
+               const guchar    *data, *dataend;
+               const guchar   *lineend, *eol;
                int             linelen;
 
                                        /* handle the end command */
                if ( pinfo->destport == TCP_PORT_SOCKS){
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, ", Terminate Request");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Terminate Request");
                
                if ( tree)
                        proto_tree_add_text(tree, tvb, offset, 1,
@@ -854,11 +890,11 @@ display_ping_and_tracert(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tr
                                "Traceroute: End command");
        }
                else{           /* display the PING or Traceroute results */
-               if (check_col(pinfo->fd, COL_INFO))
-                       col_append_str(pinfo->fd, COL_INFO, ", Results");
+               if (check_col(pinfo->cinfo, COL_INFO))
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Results");
 
                if ( tree){
-                       proto_tree_add_text(tree, tvb, offset, END_OF_FRAME,
+                       proto_tree_add_text(tree, tvb, offset, -1,
                                (hash_info->command  == PING_COMMAND) ?
                                "Ping Results:" :
                                "Traceroute Results");
@@ -937,7 +973,6 @@ dissect_socks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
                hash_info = g_mem_chunk_alloc(socks_vals);
                hash_info->start_done_row = G_MAXINT;
                hash_info->state = None;
-//XX           hash_info->port = -1;
                hash_info->port = 0;
                hash_info->version = tvb_get_guint8(tvb, offset); /* get version*/
 
@@ -949,31 +984,31 @@ dissect_socks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
                        hash_info);
 
                                                /* set dissector for now */
-               conversation_set_dissector(conversation, dissect_socks);
+               conversation_set_dissector(conversation, socks_handle);
        }
 
 /* display summary window information  */
 
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "Socks");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "Socks");
 
-       if (check_col(pinfo->fd, COL_INFO)){
+       if (check_col(pinfo->cinfo, COL_INFO)){
                if (( hash_info->version == 4) || ( hash_info->version == 5)){
-                       col_add_fstr(pinfo->fd, COL_INFO, "Version: %d",
+                       col_add_fstr(pinfo->cinfo, COL_INFO, "Version: %d",
                                hash_info->version);
                }               
                else                    /* unknown version display error */
-                       col_set_str(pinfo->fd, COL_INFO, "Unknown");
+                       col_set_str(pinfo->cinfo, COL_INFO, "Unknown");
                
 
                if ( hash_info->command == PING_COMMAND)
-                       col_append_str(pinfo->fd, COL_INFO, ", Ping Req");
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Ping Req");
                if ( hash_info->command == TRACERT_COMMAND)
-                       col_append_str(pinfo->fd, COL_INFO, ", Traceroute Req");
+                       col_append_str(pinfo->cinfo, COL_INFO, ", Traceroute Req");
                
-//XX           if ( hash_info->port != -1)
+/*XXX          if ( hash_info->port != -1) */
                if ( hash_info->port != 0)
-                       col_append_fstr(pinfo->fd, COL_INFO, ", Remote Port: %d",
+                       col_append_fstr(pinfo->cinfo, COL_INFO, ", Remote Port: %d",
                                hash_info->port);
        }
 
@@ -996,17 +1031,17 @@ dissect_socks(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
 /* if proto tree, decode and display */
 
        if (tree) {                     
-               ti = proto_tree_add_item( tree, proto_socks, tvb, offset,
-                       tvb_length_remaining(tvb, offset), FALSE );
+               ti = proto_tree_add_item( tree, proto_socks, tvb, offset, -1,
+                       FALSE );
 
                socks_tree = proto_item_add_subtree(ti, ett_socks);
 
                if ( hash_info->version == 4)
-                       display_socks_v4(tvb, offset, pinfo, tree, socks_tree,
+                       display_socks_v4(tvb, offset, pinfo, socks_tree,
                                hash_info);
                        
                else if ( hash_info->version == 5)
-                       display_socks_v5(tvb, offset, pinfo, tree, socks_tree,
+                       display_socks_v5(tvb, offset, pinfo, socks_tree,
                                hash_info);
 
                                /* if past startup, add the faked stuff */
@@ -1073,7 +1108,7 @@ proto_register_socks( void){
     
 
                { &hf_socks_ver,
-                       { "Version", "socks.ver", FT_UINT8, BASE_DEC, NULL,
+                       { "Version", "socks.version", FT_UINT8, BASE_DEC, NULL,
                                0x0, "", HFILL
                        }
                },
@@ -1083,7 +1118,7 @@ proto_register_socks( void){
                        }
                },
                { &hf_socks_ip6_dst,
-                       { "Remote Address", "socks.dstV6", FT_IPv6, BASE_NONE, NULL,
+                       { "Remote Address(ipv6)", "socks.dstV6", FT_IPv6, BASE_NONE, NULL,
                                0x0, "", HFILL
                        }
                },
@@ -1098,8 +1133,23 @@ proto_register_socks( void){
                                BASE_DEC, NULL, 0x0, "", HFILL
                        }
                },
-               { &hf_socks_command,
-                       { "Command", "socks.command", FT_UINT16,
+               { &hf_socks_cmd,
+                       { "Command", "socks.command", FT_UINT8,
+                               BASE_DEC,  VALS(cmd_strings), 0x0, "", HFILL
+                       }
+               },
+               { &hf_socks_results_4,
+                       { "Results(V4)", "socks.results_v4", FT_UINT8,
+                               BASE_DEC, VALS(reply_table_v4), 0x0, "", HFILL
+                       }
+               },
+               { &hf_socks_results_5,
+                       { "Results(V5)", "socks.results_v5", FT_UINT8,
+                               BASE_DEC, VALS(reply_table_v5), 0x0, "", HFILL
+                       }
+               },
+               { &hf_socks_results,
+                       { "Results(V5)", "socks.results", FT_UINT8,
                                BASE_DEC, NULL, 0x0, "", HFILL
                        }
                }
@@ -1114,6 +1164,10 @@ proto_register_socks( void){
        proto_register_subtree_array(ett, array_length(ett));  
 
        register_init_routine( &socks_reinit);  /* register re-init routine */
+
+       socks_udp_handle = create_dissector_handle(socks_udp_dissector,
+           proto_socks);
+       socks_handle = create_dissector_handle(dissect_socks, proto_socks);
 }
 
 
@@ -1122,6 +1176,5 @@ proto_reg_handoff_socks(void) {
 
        /* dissector install routine */ 
  
-       dissector_add("tcp.port", TCP_PORT_SOCKS, dissect_socks,
-           proto_socks);
+       dissector_add("tcp.port", TCP_PORT_SOCKS, socks_handle);
 }