X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/75e82d625d628cf62187681fc481ae5c060cdcff..fe0fcd92e3ae841f7ccf84b250df1ec4afdaecbc:/smbutil.c diff --git a/smbutil.c b/smbutil.c index 729885fc..d2a08f2b 100644 --- a/smbutil.c +++ b/smbutil.c @@ -11,24 +11,15 @@ #endif #ifndef lint -static const char rcsid[] = - "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.20 2002-04-25 04:54:03 guy Exp $"; +static const char rcsid[] _U_ = + "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.28 2003-11-16 09:36:43 guy Exp $"; #endif -#include -#include -#include -#include +#include -#include - -#include #include #include #include -#ifdef TIME_WITH_SYS_TIME -#include -#endif #include "interface.h" #include "extract.h" @@ -261,10 +252,10 @@ print_asc(const unsigned char *buf, int len) safeputchar(buf[i]); } -static char * +static const char * name_type_str(int name_type) { - char *f = NULL; + const char *f = NULL; switch (name_type) { case 0: f = "Workstation"; break; @@ -322,9 +313,9 @@ print_data(const unsigned char *buf, int len) static void -write_bits(unsigned int val, char *fmt) +write_bits(unsigned int val, const char *fmt) { - char *p = fmt; + const char *p = fmt; int i = 0; while ((p = strchr(fmt, '|'))) { @@ -365,7 +356,7 @@ unistr(const u_char *s, int *len) *len = 1; } - while (l < (sizeof(buf) - 1) && s[0] && s[1] == 0) { + while (l < (int)(sizeof(buf) - 1) && s[0] && s[1] == 0) { buf[l] = s[0]; s += 2; l++; @@ -380,7 +371,7 @@ static const u_char * smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) { int reverse = 0; - char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; + const char *attrib_fmt = "READONLY|HIDDEN|SYSTEM|VOLUME|DIR|ARCHIVE|"; int len; while (*fmt && buf sizeof(bitfmt) - 1) + l = sizeof(bitfmt)-1; + strncpy(bitfmt, fmt, l); - bitfmt[l] = 0; + bitfmt[l] = '\0'; fmt = p + 1; write_bits(buf[0], bitfmt); buf++; @@ -418,7 +413,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) int l = atoi(fmt + 1); buf += l; fmt++; - while (isdigit(*fmt)) + while (isdigit((unsigned char)*fmt)) fmt++; break; } @@ -532,7 +527,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) printf("%-*.*s", l, l, buf); buf += l; fmt++; - while (isdigit(*fmt)) + while (isdigit((unsigned char)*fmt)) fmt++; break; } @@ -542,7 +537,7 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) while (l--) printf("%02x", *buf++); fmt++; - while (isdigit(*fmt)) + while (isdigit((unsigned char)*fmt)) fmt++; break; } @@ -574,26 +569,28 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) break; } fmt++; - while (isdigit(*fmt)) + while (isdigit((unsigned char)*fmt)) fmt++; break; } case 'T': { time_t t; - int x; + struct tm *lt; + const char *tstring; + u_int32_t x; x = EXTRACT_LE_32BITS(buf); switch (atoi(fmt + 1)) { case 1: - if (x == 0 || x == -1 || x == 0xFFFFFFFF) + if (x == 0 || x == 0xFFFFFFFF) t = 0; else t = make_unix_date(buf); buf += 4; break; case 2: - if (x == 0 || x == -1 || x == 0xFFFFFFFF) + if (x == 0 || x == 0xFFFFFFFF) t = 0; else t = make_unix_date2(buf); @@ -604,9 +601,17 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf) buf += 8; break; } - printf("%s", t ? asctime(localtime(&t)) : "NULL\n"); + if (t != 0) { + lt = localtime(&t); + if (lt != NULL) + tstring = asctime(lt); + else + tstring = "(Can't convert time)\n"; + } else + tstring = "NULL\n"; + printf("%s", tstring); fmt++; - while (isdigit(*fmt)) + while (isdigit((unsigned char)*fmt)) fmt++; break; } @@ -674,7 +679,7 @@ smb_fdata(const u_char *buf, const char *fmt, const u_char *maxbuf) return(buf); memset(s, 0, sizeof(s)); p = strchr(fmt, ']'); - if (p - fmt + 1 > sizeof(s)) { + if ((size_t)(p - fmt + 1) > sizeof(s)) { /* overrun */ return(buf); } @@ -801,7 +806,7 @@ err_code_struct hard_msgs[] = { static struct { int code; - char *class; + const char *class; err_code_struct *err_msgs; } err_classes[] = { { 0, "SUCCESS", NULL },