]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
Use nd_ types, add EXTRACT_ calls.
[tcpdump] / print-smb.c
index b306cd1d267d0fc497d2ea26c41ec1fe1e5b1adc..b3f855bd1316242ebe4a5bd94145244a29b6246e 100644 (file)
@@ -25,6 +25,8 @@ static const char tstr[] = "[|SMB]";
 static int request = 0;
 static int unicodestr = 0;
 
+extern const u_char *startbuf;
+
 const u_char *startbuf = NULL;
 
 struct smbdescript {
@@ -245,7 +247,7 @@ print_browse(netdissect_options *ndo,
     int command;
 
     ND_TCHECK_1(data);
-    command = data[0];
+    command = EXTRACT_U_1(data);
 
     smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
 
@@ -363,8 +365,9 @@ print_trans(netdissect_options *ndo,
        f4 = "|Data ";
     }
 
-    smb_fdata(ndo, words + 1, f1, min(words + 1 + 2 * words[0], maxbuf),
-        unicodestr);
+    smb_fdata(ndo, words + 1, f1,
+              min(words + 1 + 2 * EXTRACT_U_1(words), maxbuf),
+              unicodestr);
 
     ND_TCHECK_2(data1);
     bcc = EXTRACT_LE_U_2(data1);
@@ -401,7 +404,7 @@ print_negprot(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = words[0];
+    wct = EXTRACT_U_1(words);
     if (request)
        f2 = "*|Dialect=[Y]\n";
     else {
@@ -443,7 +446,7 @@ print_sesssetup(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = words[0];
+    wct = EXTRACT_U_1(words);
     if (request) {
        if (wct == 10)
            f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
@@ -489,7 +492,7 @@ print_lockingandx(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = words[0];
+    wct = EXTRACT_U_1(words);
     if (request) {
        f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n";
        ND_TCHECK_1(words + 7);
@@ -808,10 +811,10 @@ print_smb(netdissect_options *ndo,
     int smboffset;
 
     ND_TCHECK_1(buf + 9);
-    request = (buf[9] & 0x80) ? 0 : 1;
+    request = (EXTRACT_U_1(buf + 9) & 0x80) ? 0 : 1;
     startbuf = buf;
 
-    command = buf[4];
+    command = EXTRACT_U_1(buf + 4);
 
     fn = smbfind(command, smb_fns);
 
@@ -851,7 +854,7 @@ print_smb(netdissect_options *ndo,
 
        words = buf + smboffset;
        ND_TCHECK_1(words);
-       wct = words[0];
+       wct = EXTRACT_U_1(words);
        data = words + 1 + wct * 2;
        maxwords = min(data, maxbuf);
 
@@ -873,8 +876,8 @@ print_smb(netdissect_options *ndo,
                    int i;
                    int v;
 
-                   for (i = 0; &words[1 + 2 * i] < maxwords; i++) {
-                       ND_TCHECK_2(words + (1 + 2 * i));
+                   for (i = 0; words + 1 + 2 * i < maxwords; i++) {
+                       ND_TCHECK_2(words + 1 + 2 * i);
                        v = EXTRACT_LE_U_2(words + 1 + 2 * i);
                        ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v));
                    }
@@ -900,7 +903,7 @@ print_smb(netdissect_options *ndo,
        if (wct == 0)
            break;
        ND_TCHECK_1(words + 1);
-       command = words[1];
+       command = EXTRACT_U_1(words + 1);
        if (command == 0xFF)
            break;
        ND_TCHECK_2(words + 3);
@@ -944,7 +947,9 @@ nbt_tcp_print(netdissect_options *ndo,
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
-    type = data[0];
+    ND_TCHECK_1(data);
+    type = EXTRACT_U_1(data);
+    ND_TCHECK_2(data + 2);
     nbt_len = EXTRACT_BE_U_2(data + 2);
     length -= 4;
     caplen -= 4;
@@ -976,7 +981,7 @@ nbt_tcp_print(netdissect_options *ndo,
                goto trunc;
            if (caplen < 4)
                goto trunc;
-           ecode = data[4];
+           ecode = EXTRACT_U_1(data + 4);
 
            ND_PRINT((ndo, "Session Reject, "));
            switch (ecode) {
@@ -1049,7 +1054,7 @@ nbt_tcp_print(netdissect_options *ndo,
            if (data == NULL)
                break;
            if (nbt_len >= 1 && caplen >= 1) {
-               ecode = origdata[4];
+               ecode = EXTRACT_U_1(origdata + 4);
                switch (ecode) {
                case 0x80:
                    ND_PRINT((ndo, "Not listening on called name\n"));
@@ -1112,10 +1117,10 @@ nbt_udp137_print(netdissect_options *ndo,
 
     ND_TCHECK_2(data + 10);
     name_trn_id = EXTRACT_BE_U_2(data);
-    response = (data[2] >> 7);
-    opcode = (data[2] >> 3) & 0xF;
-    nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
-    rcode = data[3] & 0xF;
+    response = (EXTRACT_U_1(data + 2) >> 7);
+    opcode = (EXTRACT_U_1(data + 2) >> 3) & 0xF;
+    nm_flags = ((EXTRACT_U_1(data + 2) & 0x7) << 4) + (EXTRACT_U_1(data + 3) >> 4);
+    rcode = EXTRACT_U_1(data + 3) & 0xF;
     qdcount = EXTRACT_BE_U_2(data + 4);
     ancount = EXTRACT_BE_U_2(data + 6);
     nscount = EXTRACT_BE_U_2(data + 8);
@@ -1189,7 +1194,7 @@ nbt_udp137_print(netdissect_options *ndo,
                    int numnames;
 
                    ND_TCHECK_1(p);
-                   numnames = p[0];
+                   numnames = EXTRACT_U_1(p);
                    p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
                    if (p == NULL)
                        goto out;
@@ -1387,7 +1392,7 @@ netbeui_print(netdissect_options *ndo,
        maxbuf = ndo->ndo_snapend;
     ND_TCHECK_1(data + 4);
     len = EXTRACT_LE_U_2(data);
-    command = data[4];
+    command = EXTRACT_U_1(data + 4);
     data2 = data + len;
     if (data2 >= maxbuf) {
        data2 = maxbuf;