X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/d5142e3b82bf482bf75f1d3fd27fb4d31fd51e66..39bafa636678ca3b0aa1ad88e2cdaedd06f5a33d:/smbutil.c diff --git a/smbutil.c b/smbutil.c index 6e509ecf..fa5e133f 100644 --- a/smbutil.c +++ b/smbutil.c @@ -6,9 +6,7 @@ * or later */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" @@ -251,7 +249,7 @@ name_len(netdissect_options *ndo, s += GET_U_1(s) + 1; ND_TCHECK_1(s); } - return(ND_BYTES_BETWEEN(s, s0) + 1); + return(ND_BYTES_BETWEEN(s0, s) + 1); trunc: return(-1); /* name goes past the end of the buffer */ @@ -334,7 +332,7 @@ write_bits(netdissect_options *ndo, u_int i = 0; while ((p = strchr(fmt, '|'))) { - u_int l = ND_BYTES_BETWEEN(p, fmt); + u_int l = ND_BYTES_BETWEEN(fmt, p); if (l && (val & (1 << i))) ND_PRINT("%.*s ", (int)l, fmt); fmt = p + 1; @@ -388,7 +386,7 @@ unistr(netdissect_options *ndo, char (*buf)[MAX_UNISTR_SIZE+1], } } if (!use_unicode) { - while (strsize != 0) { + while (strsize != 0) { c = GET_U_1(s); s++; strsize--; @@ -493,7 +491,7 @@ smb_fdata1(netdissect_options *ndo, u_int l; p = strchr(++fmt, '}'); - l = ND_BYTES_BETWEEN(p, fmt); + l = ND_BYTES_BETWEEN(fmt, p); if (l > sizeof(bitfmt) - 1) l = sizeof(bitfmt)-1; @@ -742,8 +740,9 @@ smb_fdata1(netdissect_options *ndo, switch (t) { case 1: - name_type = name_extract(ndo, startbuf, ND_BYTES_BETWEEN(buf, startbuf), - maxbuf, nbuf); + name_type = name_extract(ndo, startbuf, + ND_BYTES_BETWEEN(startbuf, buf), + maxbuf, nbuf); if (name_type < 0) goto trunc; len = name_len(ndo, buf, maxbuf); @@ -768,9 +767,8 @@ smb_fdata1(netdissect_options *ndo, case 'T': { time_t t; - struct tm *lt; const char *tstring; - char buffer[sizeof("Www Mmm dd hh:mm:ss yyyyy\n")]; + char buffer[sizeof("Www Mmm dd hh:mm:ss yyyyy")]; uint32_t x; switch (atoi(fmt + 1)) { @@ -800,16 +798,11 @@ smb_fdata1(netdissect_options *ndo, break; } if (t != 0) { - lt = localtime(&t); - if (lt != NULL) { - strftime(buffer, sizeof(buffer), "%a %b %e %T %Y%n", lt); - tstring = buffer; - } - else - tstring = "(Can't convert time)\n"; + tstring = nd_format_time(buffer, sizeof(buffer), "%Y-%m-%d %T", + localtime(&t)); } else - tstring = "NULL\n"; - ND_PRINT("%s", tstring); + tstring = "NULL"; + ND_PRINT("%s\n", tstring); fmt++; while (ND_ASCII_ISDIGIT(*fmt)) fmt++; @@ -939,7 +932,7 @@ smb_fdata(netdissect_options *ndo, } } if (!depth && buf < maxbuf) { - u_int len = ND_BYTES_BETWEEN(maxbuf, buf); + u_int len = ND_BYTES_BETWEEN(buf, maxbuf); ND_PRINT("Data: (%u bytes)\n", len); smb_data_print(ndo, buf, len); return(buf + len);