X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/bcf0fb3b48edc9e642c4101e2ccf964a30cdb6f1..08ee0b90d80c315264f2a1dba2e5704c30e51e1f:/smbutil.c diff --git a/smbutil.c b/smbutil.c index 95740daa..71ad60d9 100644 --- a/smbutil.c +++ b/smbutil.c @@ -6,31 +6,30 @@ * or later */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include #include -#include "interface.h" +#include "netdissect.h" #include "extract.h" #include "smb.h" -static u_int32_t stringlen; +static uint32_t stringlen; extern const u_char *startbuf; /* * interpret a 32 bit dos packed date/time to some parameters */ static void -interpret_dos_date(u_int32_t date, struct tm *tp) +interpret_dos_date(uint32_t date, struct tm *tp) { - u_int32_t p0, p1, p2, p3; + uint32_t p0, p1, p2, p3; p0 = date & 0xFF; p1 = ((date & 0xFF00) >> 8) & 0xFF; @@ -50,7 +49,7 @@ interpret_dos_date(u_int32_t date, struct tm *tp) * create a unix date from a dos date */ static time_t -int_unix_date(u_int32_t dos_date) +int_unix_date(uint32_t dos_date) { struct tm t; @@ -72,7 +71,7 @@ int_unix_date(u_int32_t dos_date) static time_t make_unix_date(const u_char *date_ptr) { - u_int32_t dos_date = 0; + uint32_t dos_date = 0; dos_date = EXTRACT_LE_32BITS(date_ptr); @@ -86,7 +85,7 @@ make_unix_date(const u_char *date_ptr) static time_t make_unix_date2(const u_char *date_ptr) { - u_int32_t x, x2; + uint32_t x, x2; x = EXTRACT_LE_32BITS(date_ptr); x2 = ((x & 0xFFFF) << 16) | ((x & 0xFFFF0000) >> 16); @@ -181,12 +180,12 @@ name_ptr(netdissect_options *ndo, /* XXX - this should use the same code that the DNS dissector does */ if ((c & 0xC0) == 0xC0) { - u_int16_t l; + uint16_t l; ND_TCHECK2(*p, 2); if ((p + 1) >= maxbuf) return(NULL); /* name goes past the end of the buffer */ - l = EXTRACT_16BITS(p) & 0x3FFF; + l = EXTRACT_BE_16BITS(p) & 0x3FFF; if (l == 0) { /* We have a pointer that points to itself. */ return(NULL); @@ -238,6 +237,7 @@ name_len(netdissect_options *ndo, return(-1); /* name goes past the end of the buffer */ ND_TCHECK2(*s, 1); s += (*s) + 1; + ND_TCHECK2(*s, 1); } return(PTR_DIFF(s, s0) + 1); @@ -272,8 +272,7 @@ name_type_str(int name_type) } void -print_data(netdissect_options *ndo, - const unsigned char *buf, int len) +smb_print_data(netdissect_options *ndo, const unsigned char *buf, int len) { int i = 0; @@ -341,11 +340,11 @@ write_bits(netdissect_options *ndo, #define MAX_UNISTR_SIZE 1000 static const char * unistr(netdissect_options *ndo, - const u_char *s, u_int32_t *len, int use_unicode) + const u_char *s, uint32_t *len, int use_unicode) { static char buf[MAX_UNISTR_SIZE+1]; size_t l = 0; - u_int32_t strsize; + uint32_t strsize; const u_char *sp; if (use_unicode) { @@ -505,7 +504,7 @@ smb_fdata1(netdissect_options *ndo, { unsigned int x; ND_TCHECK2(buf[0], 2); - x = reverse ? EXTRACT_16BITS(buf) : + x = reverse ? EXTRACT_BE_16BITS(buf) : EXTRACT_LE_16BITS(buf); ND_PRINT((ndo, "%d (0x%x)", x, x)); buf += 2; @@ -516,7 +515,7 @@ smb_fdata1(netdissect_options *ndo, { unsigned int x; ND_TCHECK2(buf[0], 4); - x = reverse ? EXTRACT_32BITS(buf) : + x = reverse ? EXTRACT_BE_32BITS(buf) : EXTRACT_LE_32BITS(buf); ND_PRINT((ndo, "%d (0x%x)", x, x)); buf += 4; @@ -525,9 +524,9 @@ smb_fdata1(netdissect_options *ndo, } case 'L': { - u_int64_t x; + uint64_t x; ND_TCHECK2(buf[0], 8); - x = reverse ? EXTRACT_64BITS(buf) : + x = reverse ? EXTRACT_BE_64BITS(buf) : EXTRACT_LE_64BITS(buf); ND_PRINT((ndo, "%" PRIu64 " (0x%" PRIx64 ")", x, x)); buf += 8; @@ -537,14 +536,14 @@ smb_fdata1(netdissect_options *ndo, case 'M': { /* Weird mixed-endian length values in 64-bit locks */ - u_int32_t x1, x2; - u_int64_t x; + uint32_t x1, x2; + uint64_t x; ND_TCHECK2(buf[0], 8); - x1 = reverse ? EXTRACT_32BITS(buf) : + x1 = reverse ? EXTRACT_BE_32BITS(buf) : EXTRACT_LE_32BITS(buf); - x2 = reverse ? EXTRACT_32BITS(buf + 4) : + x2 = reverse ? EXTRACT_BE_32BITS(buf + 4) : EXTRACT_LE_32BITS(buf + 4); - x = (((u_int64_t)x1) << 32) | x2; + x = (((uint64_t)x1) << 32) | x2; ND_PRINT((ndo, "%" PRIu64 " (0x%" PRIx64 ")", x, x)); buf += 8; fmt++; @@ -564,7 +563,7 @@ smb_fdata1(netdissect_options *ndo, { unsigned int x; ND_TCHECK2(buf[0], 2); - x = reverse ? EXTRACT_16BITS(buf) : + x = reverse ? EXTRACT_BE_16BITS(buf) : EXTRACT_LE_16BITS(buf); ND_PRINT((ndo, "0x%X", x)); buf += 2; @@ -575,7 +574,7 @@ smb_fdata1(netdissect_options *ndo, { unsigned int x; ND_TCHECK2(buf[0], 4); - x = reverse ? EXTRACT_32BITS(buf) : + x = reverse ? EXTRACT_BE_32BITS(buf) : EXTRACT_LE_32BITS(buf); ND_PRINT((ndo, "0x%X", x)); buf += 4; @@ -596,7 +595,7 @@ smb_fdata1(netdissect_options *ndo, case 'd': ND_TCHECK2(buf[0], 2); - stringlen = reverse ? EXTRACT_16BITS(buf) : + stringlen = reverse ? EXTRACT_BE_16BITS(buf) : EXTRACT_LE_16BITS(buf); ND_PRINT((ndo, "%u", stringlen)); buf += 2; @@ -604,7 +603,7 @@ smb_fdata1(netdissect_options *ndo, case 'D': ND_TCHECK2(buf[0], 4); - stringlen = reverse ? EXTRACT_32BITS(buf) : + stringlen = reverse ? EXTRACT_BE_32BITS(buf) : EXTRACT_LE_32BITS(buf); ND_PRINT((ndo, "%u", stringlen)); buf += 4; @@ -618,7 +617,7 @@ smb_fdata1(netdissect_options *ndo, { /*XXX unistr() */ const char *s; - u_int32_t len; + uint32_t len; len = 0; s = unistr(ndo, buf, &len, (*fmt == 'R') ? 0 : unicodestr); @@ -633,7 +632,7 @@ smb_fdata1(netdissect_options *ndo, case 'Y': /* like 'Z', but always ASCII */ { const char *s; - u_int32_t len; + uint32_t len; ND_TCHECK(*buf); if (*buf != 4 && *buf != 2) { @@ -730,7 +729,7 @@ smb_fdata1(netdissect_options *ndo, time_t t; struct tm *lt; const char *tstring; - u_int32_t x; + uint32_t x; switch (atoi(fmt + 1)) { case 1: @@ -861,7 +860,7 @@ smb_fdata(netdissect_options *ndo, if (!depth && buf < maxbuf) { size_t len = PTR_DIFF(maxbuf, buf); ND_PRINT((ndo, "Data: (%lu bytes)\n", (unsigned long)len)); - print_data(ndo, buf, len); + smb_print_data(ndo, buf, len); return(buf + len); } return(buf); @@ -1013,7 +1012,7 @@ smb_errstr(int class, int num) } typedef struct { - u_int32_t code; + uint32_t code; const char *name; } nt_err_code_struct; @@ -1877,7 +1876,7 @@ static const nt_err_code_struct nt_errors[] = { * return an NT error string from a SMB buffer */ const char * -nt_errstr(u_int32_t err) +nt_errstr(uint32_t err) { static char ret[128]; int i;