Rename function and variables for dissecting an NT service Account Control
[obnox/wireshark/wip.git] / packet-rlogin.c
index c93f096d651c194db43fa5a8d626edea2e23ae65..1b36be4d72a41d7047637b908fd36bd00102ca53 100644 (file)
@@ -2,7 +2,7 @@
  * Routines for unix rlogin packet dissection
  * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
  *
- * $Id: packet-rlogin.c,v 1.20 2001/09/30 23:14:43 guy Exp $
+ * $Id: packet-rlogin.c,v 1.26 2002/01/24 09:20:51 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -41,8 +41,8 @@
 #include <string.h>
 #include <glib.h>
 
-#include "packet.h"
-#include "conversation.h"
+#include <epan/packet.h>
+#include <epan/conversation.h>
 
 #include "packet-tcp.h"
 
@@ -171,8 +171,8 @@ rlogin_state_machine( rlogin_hash_entry_t *hash_info, tvbuff_t *tvb,
                tvb_memcpy(tvb, (guint8 *)hash_info->name, 0, stringlen);
                hash_info->name[stringlen] = '\0';
                
-               if (check_col(pinfo->fd, COL_INFO))     /* update summary */
-                       col_append_str(pinfo->fd, COL_INFO,
+               if (check_col(pinfo->cinfo, COL_INFO))  /* update summary */
+                       col_append_str(pinfo->cinfo, COL_INFO,
                            ", User information");
        }               
 }
@@ -189,8 +189,7 @@ static void rlogin_display( rlogin_hash_entry_t *hash_info, tvbuff_t *tvb,
        gint            ti_offset;
        proto_item      *user_info_item,  *window_info_item;
 
-       ti = proto_tree_add_item( tree, proto_rlogin, tvb, 0,
-                       tvb_length(tvb), FALSE);
+       ti = proto_tree_add_item( tree, proto_rlogin, tvb, 0, -1, FALSE);
 
        rlogin_tree = proto_item_add_subtree(ti, ett_rlogin);
 
@@ -198,7 +197,13 @@ static void rlogin_display( rlogin_hash_entry_t *hash_info, tvbuff_t *tvb,
        if ( length == 0)                       /* exit if no captured data */
                return;
 
-       if ( tcpinfo->urgent_pointer &&         /* if control message */
+       /*
+        * XXX - this works only if the urgent pointer points to something
+        * in this segment; to make it work if the urgent pointer points
+        * to something past this segment, we'd have to remember the urgent
+        * pointer setting for this conversation.
+        */
+       if ( tcpinfo->urgent &&                 /* if urgent pointer set */
             length >= tcpinfo->urgent_pointer) {       /* and it's in this frame */
 
                int urgent_offset = tcpinfo->urgent_pointer - 1;
@@ -237,7 +242,7 @@ static void rlogin_display( rlogin_hash_entry_t *hash_info, tvbuff_t *tvb,
                 * First frame of conversation, hence user info?
                 */
                user_info_item = proto_tree_add_item( rlogin_tree, hf_user_info, tvb,
-                       offset, tvb_length_remaining(tvb, offset), FALSE);
+                       offset, -1, FALSE);
 
                /*
                 * Do server user name.
@@ -327,17 +332,17 @@ static void rlogin_display( rlogin_hash_entry_t *hash_info, tvbuff_t *tvb,
                /*
                 * There's more data in the frame.
                 */
-               proto_tree_add_text(rlogin_tree, tvb, offset,
-                   tvb_length_remaining(tvb, offset), "Data");
+               proto_tree_add_text(rlogin_tree, tvb, offset, -1, "Data");
        }
 }      
 
 static void
 dissect_rlogin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 {
-       struct tcpinfo *tcpinfo = pinfo->private;
+       struct tcpinfo *tcpinfo = pinfo->private_data;
        conversation_t *conversation;
        rlogin_hash_entry_t *hash_info;
+       guint length;
        gint ti_offset;
 
                                                /* Lookup this connection*/
@@ -358,14 +363,14 @@ dissect_rlogin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        hash_info);
        }
        
-       if (check_col(pinfo->fd, COL_PROTOCOL))         /* update protocol  */
-               col_set_str(pinfo->fd, COL_PROTOCOL, "Rlogin");
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))              /* update protocol  */
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "Rlogin");
 
-       if (check_col(pinfo->fd, COL_INFO)){            /* display packet info*/
+       if (check_col(pinfo->cinfo, COL_INFO)){         /* display packet info*/
 
                char temp[1000];
                
-               col_clear(pinfo->fd, COL_INFO);
+               col_clear(pinfo->cinfo, COL_INFO);
                if ( hash_info->name[0]) {
                        strcpy( temp, "User name: ");
                        strcat( temp, hash_info->name);
@@ -374,33 +379,37 @@ dissect_rlogin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                else 
                        temp[0] = 0;
 
-               if ( tvb_get_guint8(tvb, 0) == '\0')
-                       strcat( temp, "Start Handshake"); 
-               else if ( tcpinfo->urgent_pointer)
-                       strcat( temp, "Control Message"); 
-
-               else {                          /* check for terminal info */
-                       ti_offset = tvb_find_guint8(tvb, 0, -1, 0xff);
-                       if (ti_offset != -1 &&
-                           tvb_bytes_exist(tvb, ti_offset + 1, 1) &&
-                           tvb_get_guint8(tvb, ti_offset + 1) == 0xff)
-                               strcat( temp, "Terminal Info");
-                       else {
-                               int i;
-                               int bytes_to_copy;
-
-                               strcat( temp, "Data: ");
-                               i = strlen( temp);
-                               bytes_to_copy = tvb_length(tvb);
-                               if (bytes_to_copy > 128)
-                                       bytes_to_copy = 128;
-                               tvb_memcpy(tvb, (guint8 *)&temp[i], 0,
-                                   bytes_to_copy);
-                               temp[i + bytes_to_copy] = '\0';
+               length = tvb_length(tvb);
+               if (length != 0) {
+                       if ( tvb_get_guint8(tvb, 0) == '\0')
+                               strcat( temp, "Start Handshake"); 
+                       else if ( tcpinfo->urgent &&
+                                 length >= tcpinfo->urgent_pointer )
+                               strcat( temp, "Control Message"); 
+
+                       else {                  /* check for terminal info */
+                               ti_offset = tvb_find_guint8(tvb, 0, -1, 0xff);
+                               if (ti_offset != -1 &&
+                                   tvb_bytes_exist(tvb, ti_offset + 1, 1) &&
+                                   tvb_get_guint8(tvb, ti_offset + 1) == 0xff)
+                                       strcat( temp, "Terminal Info");
+                               else {
+                                       int i;
+                                       int bytes_to_copy;
+
+                                       strcat( temp, "Data: ");
+                                       i = strlen( temp);
+                                       bytes_to_copy = tvb_length(tvb);
+                                       if (bytes_to_copy > 128)
+                                               bytes_to_copy = 128;
+                                       tvb_memcpy(tvb, (guint8 *)&temp[i], 0,
+                                           bytes_to_copy);
+                                       temp[i + bytes_to_copy] = '\0';
+                               }
                        }
                }               
 
-               col_add_str(pinfo->fd, COL_INFO, temp);
+               col_add_str(pinfo->cinfo, COL_INFO, temp);
        }
 
        rlogin_state_machine( hash_info, tvb, pinfo);
@@ -473,6 +482,8 @@ proto_reg_handoff_rlogin(void) {
 
        /* dissector install routine */ 
  
-       dissector_add("tcp.port", TCP_PORT_RLOGIN, dissect_rlogin,
-           proto_rlogin);
+       dissector_handle_t rlogin_handle;
+
+       rlogin_handle = create_dissector_handle(dissect_rlogin, proto_rlogin);
+       dissector_add("tcp.port", TCP_PORT_RLOGIN, rlogin_handle);
 }