2 * Routines for who protocol (see man rwhod)
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-who.c,v 1.25 2002/08/28 21:00:37 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include <epan/packet.h>
38 RWHOD(8) UNIX System Manager's Manual RWHOD(8)
41 The messages sent and received, are of the form:
44 0 char out_line[8]; tty name
45 8 char out_name[8]; user id
46 16 long out_time; time on
55 12 char wd_hostname[32];
60 (20 each) int we_idle;
61 } wd_we[1024 / sizeof (struct whoent)];
64 Linux 2.0 May 13, 1997 2
69 static int proto_who = -1;
70 static int hf_who_vers = -1;
71 static int hf_who_type = -1;
72 static int hf_who_sendtime = -1;
73 static int hf_who_recvtime = -1;
74 static int hf_who_hostname = -1;
75 static int hf_who_loadav_5 = -1;
76 static int hf_who_loadav_10 = -1;
77 static int hf_who_loadav_15 = -1;
78 static int hf_who_boottime = -1;
79 static int hf_who_whoent = -1;
80 static int hf_who_tty = -1;
81 static int hf_who_uid = -1;
82 static int hf_who_timeon = -1;
83 static int hf_who_idle = -1;
85 static gint ett_who = -1;
86 static gint ett_whoent = -1;
88 #define UDP_PORT_WHO 513
90 static void dissect_whoent(tvbuff_t *tvb, int offset, proto_tree *tree);
93 dissect_who(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
96 proto_tree *who_tree = NULL;
97 proto_item *who_ti = NULL;
98 gchar server_name[33];
99 double loadav_5 = 0.0, loadav_10 = 0.0, loadav_15 = 0.0;
102 /* Summary information */
103 if (check_col(pinfo->cinfo, COL_PROTOCOL))
104 col_set_str(pinfo->cinfo, COL_PROTOCOL, "WHO");
105 if (check_col(pinfo->cinfo, COL_INFO))
106 col_clear(pinfo->cinfo, COL_INFO);
111 who_ti = proto_tree_add_item(tree, proto_who, tvb, offset, -1,
113 who_tree = proto_item_add_subtree(who_ti, ett_who);
117 proto_tree_add_item(who_tree, hf_who_vers, tvb, offset, 1, FALSE);
121 proto_tree_add_item(who_tree, hf_who_type, tvb, offset, 1, FALSE);
128 ts.secs = tvb_get_ntohl(tvb, offset);
129 proto_tree_add_time(who_tree, hf_who_sendtime, tvb, offset, 4,
135 ts.secs = tvb_get_ntohl(tvb, offset);
136 proto_tree_add_time(who_tree, hf_who_recvtime, tvb, offset, 4,
141 tvb_get_nstringz0(tvb, offset, 32, server_name);
143 proto_tree_add_string(who_tree, hf_who_hostname, tvb, offset,
147 loadav_5 = (double) tvb_get_ntohl(tvb, offset) / 100.0;
149 proto_tree_add_double(who_tree, hf_who_loadav_5, tvb, offset,
153 loadav_10 = (double) tvb_get_ntohl(tvb, offset) / 100.0;
155 proto_tree_add_double(who_tree, hf_who_loadav_10, tvb, offset,
159 loadav_15 = (double) tvb_get_ntohl(tvb, offset) / 100.0;
161 proto_tree_add_double(who_tree, hf_who_loadav_15, tvb, offset,
165 /* Summary information */
166 if (check_col(pinfo->cinfo, COL_INFO))
167 col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %.02f %.02f %.02f",
168 server_name, loadav_5, loadav_10, loadav_15);
171 ts.secs = tvb_get_ntohl(tvb, offset);
172 proto_tree_add_time(who_tree, hf_who_boottime, tvb, offset, 4,
176 dissect_whoent(tvb, offset, who_tree);
180 /* The man page says that (1024 / sizeof(struct whoent)) is the maximum number
181 * of whoent structures in the packet. */
182 #define SIZE_OF_WHOENT 24
183 #define MAX_NUM_WHOENTS (1024 / SIZE_OF_WHOENT)
186 dissect_whoent(tvbuff_t *tvb, int offset, proto_tree *tree)
188 proto_tree *whoent_tree = NULL;
189 proto_item *whoent_ti = NULL;
190 int line_offset = offset;
195 guint32 idle_secs; /* say that out loud... */
199 while (tvb_reported_length_remaining(tvb, line_offset) > 0
200 && whoent_num < MAX_NUM_WHOENTS) {
201 whoent_ti = proto_tree_add_item(tree, hf_who_whoent, tvb,
202 line_offset, SIZE_OF_WHOENT, FALSE);
203 whoent_tree = proto_item_add_subtree(whoent_ti, ett_whoent);
205 tvb_get_nstringz0(tvb, line_offset, 8, out_line);
206 proto_tree_add_string(whoent_tree, hf_who_tty, tvb, line_offset,
210 tvb_get_nstringz0(tvb, line_offset, 8, out_name);
211 proto_tree_add_string(whoent_tree, hf_who_uid, tvb, line_offset,
215 ts.secs = tvb_get_ntohl(tvb, line_offset);
216 proto_tree_add_time(whoent_tree, hf_who_timeon, tvb,
217 line_offset, 4, &ts);
220 idle_secs = tvb_get_ntohl(tvb, line_offset);
221 proto_tree_add_uint_format(whoent_tree, hf_who_idle, tvb,
222 line_offset, 4, idle_secs, "Idle: %s",
223 time_secs_to_str(idle_secs));
231 proto_register_who(void)
233 static hf_register_info hf[] = {
235 { "Version", "who.vers", FT_UINT8, BASE_DEC, NULL, 0x0,
239 { "Type", "who.type", FT_UINT8, BASE_DEC, NULL, 0x0,
243 { "Send Time", "who.sendtime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
247 { "Receive Time", "who.recvtime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
251 { "Hostname", "who.hostname", FT_STRING, BASE_NONE, NULL, 0x0,
255 { "Load Average Over Past 5 Minutes", "who.loadav_5", FT_DOUBLE, BASE_NONE, NULL, 0x0,
259 { "Load Average Over Past 10 Minutes", "who.loadav_10", FT_DOUBLE, BASE_NONE, NULL, 0x0,
263 { "Load Average Over Past 15 Minutes", "who.loadav_15", FT_DOUBLE, BASE_NONE, NULL, 0x0,
267 { "Boot Time", "who.boottime", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
271 { "Who utmp Entry", "who.whoent", FT_NONE, BASE_NONE, NULL, 0x0,
275 { "TTY Name", "who.tty", FT_STRING, BASE_NONE, NULL, 0x0,
279 { "User ID", "who.uid", FT_STRING, BASE_NONE, NULL, 0x0,
283 { "Time On", "who.timeon", FT_ABSOLUTE_TIME, BASE_NONE, NULL, 0x0,
287 { "Time Idle", "who.idle", FT_UINT32, BASE_DEC, NULL, 0x0,
291 static gint *ett[] = {
296 proto_who = proto_register_protocol("Who", "WHO", "who");
297 proto_register_field_array(proto_who, hf, array_length(hf));
298 proto_register_subtree_array(ett, array_length(ett));
302 proto_reg_handoff_who(void)
304 dissector_handle_t who_handle;
306 who_handle = create_dissector_handle(dissect_who, proto_who);
307 dissector_add("udp.port", UDP_PORT_WHO, who_handle);