Add a "time_msecs_to_str()" routine, to turn a time interval, expressed

as a 32-bit number of milliseconds, to a descriptive string.

Use that in the MS Browser dissector.

svn path=/trunk/; revision=3708
This commit is contained in:
Guy Harris 2001-07-13 00:27:51 +00:00
parent 01710d371c
commit 82a553e9c9
3 changed files with 72 additions and 7 deletions

View File

@ -1,7 +1,7 @@
/* to_str.h
* Routines for utilities to convert various other types to strings.
*
* $Id: to_str.c,v 1.8 2001/05/31 06:47:59 guy Exp $
* $Id: to_str.c,v 1.9 2001/07/13 00:27:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -320,6 +320,66 @@ time_secs_to_str(guint32 time)
return cur;
}
gchar *
time_msecs_to_str(guint32 time)
{
static gchar str[3][8+1+4+2+2+5+2+2+7+2+2+11+1];
static gchar *cur, *p;
int hours, mins, secs;
int msecs;
int do_comma;
if (cur == &str[0][0]) {
cur = &str[1][0];
} else if (cur == &str[1][0]) {
cur = &str[2][0];
} else {
cur = &str[0][0];
}
if (time == 0) {
sprintf(cur, "0 time");
return cur;
}
msecs = time % 1000;
time /= 1000;
secs = time % 60;
time /= 60;
mins = time % 60;
time /= 60;
hours = time % 24;
time /= 24;
p = cur;
if (time != 0) {
sprintf(p, "%u day%s", time, PLURALIZE(time));
p += strlen(p);
do_comma = 1;
} else
do_comma = 0;
if (hours != 0) {
sprintf(p, "%s%u hour%s", COMMA(do_comma), hours, PLURALIZE(hours));
p += strlen(p);
do_comma = 1;
} else
do_comma = 0;
if (mins != 0) {
sprintf(p, "%s%u minute%s", COMMA(do_comma), mins, PLURALIZE(mins));
p += strlen(p);
do_comma = 1;
} else
do_comma = 0;
if (secs != 0) {
if (msecs != 0)
sprintf(p, "%s%u.%03u seconds", COMMA(do_comma), secs, msecs);
else
sprintf(p, "%s%u second%s", COMMA(do_comma), secs, PLURALIZE(secs));
}
return cur;
}
static const char *mon_names[12] = {
"Jan",
"Feb",

View File

@ -1,7 +1,7 @@
/* to_str.h
* Definitions for utilities to convert various other types to strings.
*
* $Id: to_str.h,v 1.2 2001/04/01 06:32:10 hagbard Exp $
* $Id: to_str.h,v 1.3 2001/07/13 00:27:51 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@ -52,6 +52,7 @@ gchar* ipxnet_to_string(const guint8 *ad);
gchar* ipxnet_to_str_punct(const guint32 ad, char punct);
gchar* vines_addr_to_str(const guint8 *addrp);
gchar* time_secs_to_str(guint32);
gchar* time_msecs_to_str(guint32);
gchar* abs_time_to_str(struct timeval*);
void display_signed_time(gchar *, int, gint32, gint32);
gchar* rel_time_to_str(struct timeval*);

View File

@ -2,7 +2,7 @@
* Routines for SMB Browser packet dissection
* Copyright 1999, Richard Sharpe <rsharpe@ns.aus.com>
*
* $Id: packet-smb-browse.c,v 1.10 2001/07/13 00:01:35 guy Exp $
* $Id: packet-smb-browse.c,v 1.11 2001/07/13 00:27:49 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -539,6 +539,7 @@ dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr
guint8 server_count;
int i;
guint32 criterion;
guint32 uptime;
if (!proto_is_protocol_enabled(proto_smb_browse)) {
return FALSE;
@ -578,9 +579,8 @@ dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr
periodicity = tvb_get_letohl(tvb, offset);
proto_tree_add_uint_format(tree, hf_periodicity, tvb, offset, 4,
periodicity,
"Update Periodicity: %u.%03u sec",
periodicity/1000,
periodicity%1000);
"Update Periodicity: %s",
time_msecs_to_str(periodicity));
offset += 4;
/* server name */
@ -686,7 +686,11 @@ dissect_mailslot_browse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tr
offset += 4;
/* server uptime */
proto_tree_add_item(tree, hf_server_uptime, tvb, offset, 4, TRUE);
uptime = tvb_get_letohl(tvb, offset);
proto_tree_add_uint_format(tree, hf_server_uptime,
tvb, offset, 4, uptime,
"Uptime: %s",
time_msecs_to_str(uptime));
offset += 4;
/* next 4 bytes must be zero */