Include <string.h> to get "strcmp()" declared.
[obnox/wireshark/wip.git] / packet-who.c
index ae8455e930049167345b790bc2b6068c681fa547..23ebc3a1f285a487c0c31c89c1adb3321e04c0a1 100644 (file)
@@ -1,24 +1,23 @@
 /* packet-who.c
  * Routines for who protocol (see man rwhod)
- * Gilbert Ramirez <gram@xiexie.org>
+ * Gilbert Ramirez <gram@alumni.rice.edu>
  *
- * $Id: packet-who.c,v 1.16 2001/04/19 23:02:44 guy Exp $
+ * $Id: packet-who.c,v 1.26 2003/04/30 02:35:20 gerald Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
- * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
 #include <string.h>
 #include <time.h>
 #include <glib.h>
-#include "packet.h"
+#include <epan/packet.h>
 
 
 /*
@@ -46,9 +41,9 @@ RWHOD(8)                 UNIX System Manager's Manual                 RWHOD(8)
      The messages sent and received, are of the form:
 
            struct  outmp {
-0                   char    out_line[8];             tty name 
-8                   char    out_name[8];             user id 
-16                   long    out_time;               time on 
+0                   char    out_line[8];             tty name
+8                   char    out_name[8];             user id
+16                   long    out_time;               time on
            };
 
            struct  whod {
@@ -102,19 +97,19 @@ dissect_who(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_item      *who_ti = NULL;
        gchar           server_name[33];
        double          loadav_5 = 0.0, loadav_10 = 0.0, loadav_15 = 0.0;
-       struct timeval  tv;
+       nstime_t        ts;
 
        /* Summary information */
-       if (check_col(pinfo->fd, COL_PROTOCOL))
-               col_set_str(pinfo->fd, COL_PROTOCOL, "WHO");
-       if (check_col(pinfo->fd, COL_INFO))
-               col_clear(pinfo->fd, COL_INFO);
+       if (check_col(pinfo->cinfo, COL_PROTOCOL))
+               col_set_str(pinfo->cinfo, COL_PROTOCOL, "WHO");
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_clear(pinfo->cinfo, COL_INFO);
 
-       tv.tv_usec = 0;
+       ts.nsecs = 0;
 
        if (tree) {
-               who_ti = proto_tree_add_item(tree, proto_who, tvb, offset,
-                   tvb_length(tvb), FALSE);
+               who_ti = proto_tree_add_item(tree, proto_who, tvb, offset, -1,
+                   FALSE);
                who_tree = proto_item_add_subtree(who_ti, ett_who);
        }
 
@@ -130,20 +125,20 @@ dissect_who(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset += 2;
 
        if (tree) {
-               tv.tv_sec = tvb_get_ntohl(tvb, offset);
+               ts.secs = tvb_get_ntohl(tvb, offset);
                proto_tree_add_time(who_tree, hf_who_sendtime, tvb, offset, 4,
-                   &tv);
+                   &ts);
        }
        offset += 4;
 
        if (tree) {
-               tv.tv_sec = tvb_get_ntohl(tvb, offset);
+               ts.secs = tvb_get_ntohl(tvb, offset);
                proto_tree_add_time(who_tree, hf_who_recvtime, tvb, offset, 4,
-                   &tv);
+                   &ts);
        }
        offset += 4;
 
-       tvb_get_nstringz0(tvb, offset, 32, server_name);
+       tvb_get_nstringz0(tvb, offset, sizeof(server_name), server_name);
        if (tree)
                proto_tree_add_string(who_tree, hf_who_hostname, tvb, offset,
                    32, server_name);
@@ -168,14 +163,14 @@ dissect_who(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        offset += 4;
 
        /* Summary information */
-       if (check_col(pinfo->fd, COL_INFO))
-               col_add_fstr(pinfo->fd, COL_INFO, "%s: %.02f %.02f %.02f",
+       if (check_col(pinfo->cinfo, COL_INFO))
+               col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %.02f %.02f %.02f",
                                server_name, loadav_5, loadav_10, loadav_15);
 
        if (tree) {
-               tv.tv_sec = tvb_get_ntohl(tvb, offset);
+               ts.secs = tvb_get_ntohl(tvb, offset);
                proto_tree_add_time(who_tree, hf_who_boottime, tvb, offset, 4,
-                   &tv);
+                   &ts);
                offset += 4;
 
                dissect_whoent(tvb, offset, who_tree);
@@ -193,13 +188,13 @@ dissect_whoent(tvbuff_t *tvb, int offset, proto_tree *tree)
        proto_tree      *whoent_tree = NULL;
        proto_item      *whoent_ti = NULL;
        int             line_offset = offset;
-       gchar           out_line[9];    
-       gchar           out_name[9];    
-       struct timeval  tv;
+       gchar           out_line[9];
+       gchar           out_name[9];
+       nstime_t        ts;
        int             whoent_num = 0;
        guint32         idle_secs; /* say that out loud... */
 
-       tv.tv_usec = 0;
+       ts.nsecs = 0;
 
        while (tvb_reported_length_remaining(tvb, line_offset) > 0
            && whoent_num < MAX_NUM_WHOENTS) {
@@ -207,19 +202,19 @@ dissect_whoent(tvbuff_t *tvb, int offset, proto_tree *tree)
                    line_offset, SIZE_OF_WHOENT, FALSE);
                whoent_tree = proto_item_add_subtree(whoent_ti, ett_whoent);
 
-               tvb_get_nstringz0(tvb, line_offset, 8, out_line);
+               tvb_get_nstringz0(tvb, line_offset, sizeof(out_line), out_line);
                proto_tree_add_string(whoent_tree, hf_who_tty, tvb, line_offset,
                    8, out_line);
                line_offset += 8;
 
-               tvb_get_nstringz0(tvb, line_offset, 8, out_name);
+               tvb_get_nstringz0(tvb, line_offset, sizeof(out_name), out_name);
                proto_tree_add_string(whoent_tree, hf_who_uid, tvb, line_offset,
                    8, out_name);
                line_offset += 8;
 
-               tv.tv_sec = tvb_get_ntohl(tvb, line_offset);
+               ts.secs = tvb_get_ntohl(tvb, line_offset);
                proto_tree_add_time(whoent_tree, hf_who_timeon, tvb,
-                   line_offset, 4, &tv);
+                   line_offset, 4, &ts);
                line_offset += 4;
 
                idle_secs = tvb_get_ntohl(tvb, line_offset);
@@ -238,59 +233,59 @@ proto_register_who(void)
        static hf_register_info hf[] = {
                { &hf_who_vers,
                { "Version",    "who.vers", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_type,
                { "Type",       "who.type", FT_UINT8, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_sendtime,
                { "Send Time",  "who.sendtime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_recvtime,
                { "Receive Time", "who.recvtime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_hostname,
                { "Hostname", "who.hostname", FT_STRING, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_loadav_5,
                { "Load Average Over Past  5 Minutes", "who.loadav_5", FT_DOUBLE, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_loadav_10,
                { "Load Average Over Past 10 Minutes", "who.loadav_10", FT_DOUBLE, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_loadav_15,
                { "Load Average Over Past 15 Minutes", "who.loadav_15", FT_DOUBLE, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_boottime,
                { "Boot Time", "who.boottime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_whoent,
                { "Who utmp Entry", "who.whoent", FT_NONE, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_tty,
                { "TTY Name", "who.tty", FT_STRING, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_uid,
                { "User ID", "who.uid", FT_STRING, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_timeon,
                { "Time On", "who.timeon", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
 
                { &hf_who_idle,
                { "Time Idle", "who.idle", FT_UINT32, BASE_DEC, NULL, 0x0,
-                       "" }},
+                       "", HFILL }},
        };
 
        static gint *ett[] = {
@@ -306,5 +301,8 @@ proto_register_who(void)
 void
 proto_reg_handoff_who(void)
 {
-       dissector_add("udp.port", UDP_PORT_WHO, dissect_who, proto_who);
+       dissector_handle_t who_handle;
+
+       who_handle = create_dissector_handle(dissect_who, proto_who);
+       dissector_add("udp.port", UDP_PORT_WHO, who_handle);
 }