]> The Tcpdump Group git mirrors - tcpdump/blobdiff - smbutil.c
don't pass on src & dst MAC adresses to the isoclns decoder as MAC adresses
[tcpdump] / smbutil.c
index 505a271d9363f5de660a212b714789c7e12bf743..e80b663628a5ecc8731f14c5cd1a20ee9a812ade 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.19 2002-04-20 09:42:58 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.25 2002-09-05 00:00:25 guy Exp $";
 #endif
 
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+#include <tcpdump-stdinc.h>
 
-#include <netinet/in.h>
-
-#include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#ifdef TIME_WITH_SYS_TIME
-#include <time.h>
-#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, '|'))) {
@@ -338,7 +329,7 @@ write_bits(unsigned int val, char *fmt)
 
 /* convert a UCS2 string into iso-8859-1 string */
 static const char *
-unistr(const char *s, int *len)
+unistr(const u_char *s, int *len)
 {
     static char buf[1000];
     int l=0;
@@ -354,8 +345,8 @@ unistr(const char *s, int *len)
 
     /* maybe it isn't unicode - a cheap trick */
     if (!use_unicode || (s[0] && s[1])) {
-       *len = strlen(s) + 1;
-       return s;
+       *len = strlen((const char *)s) + 1;
+       return (const char *)s;
     }
 
     *len = 0;
@@ -365,7 +356,7 @@ unistr(const 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<maxbuf) {
@@ -400,8 +391,11 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf)
        case '{':
          {
            char bitfmt[128];
-           char *p = strchr(++fmt, '}');
-           int l = PTR_DIFF(p, fmt);
+           char *p;
+           int l;
+
+           p = strchr(++fmt, '}');
+           l = PTR_DIFF(p, fmt);
            strncpy(bitfmt, fmt, l);
            bitfmt[l] = 0;
            fmt = p + 1;
@@ -415,7 +409,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;
          }
@@ -529,7 +523,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;
          }
@@ -539,7 +533,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;
          }
@@ -571,26 +565,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);
@@ -601,9 +597,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;
          }
@@ -671,7 +675,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);
            }
@@ -798,7 +802,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 },