]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-smb.c
IPoIB: Add the output with -e for a capture test
[tcpdump] / print-smb.c
index 6592c5eb531af6b0684c7719fb77336243dfd307..961ef643cf3f6e70025ec1170b2e44201a308e5c 100644 (file)
@@ -115,7 +115,7 @@ trans2_qfsinfo(netdissect_options *ndo,
 
     if (request) {
        ND_TCHECK_2(param);
-       level = EXTRACT_LE_U_2(param);
+       level = GET_LE_U_2(param);
        fmt = "InfoLevel=[u]\n";
        smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
     } else {
@@ -183,28 +183,28 @@ print_trans2(netdissect_options *ndo,
     ND_TCHECK_1(words);
     if (request) {
        ND_TCHECK_2(w + (14 * 2));
-       pcnt = EXTRACT_LE_U_2(w + 9 * 2);
-       param = buf + EXTRACT_LE_U_2(w + 10 * 2);
-       dcnt = EXTRACT_LE_U_2(w + 11 * 2);
-       data = buf + EXTRACT_LE_U_2(w + 12 * 2);
-       fn = smbfindint(EXTRACT_LE_U_2(w + 14 * 2), trans2_fns);
+       pcnt = GET_LE_U_2(w + 9 * 2);
+       param = buf + GET_LE_U_2(w + 10 * 2);
+       dcnt = GET_LE_U_2(w + 11 * 2);
+       data = buf + GET_LE_U_2(w + 12 * 2);
+       fn = smbfindint(GET_LE_U_2(w + 14 * 2), trans2_fns);
     } else {
-       if (EXTRACT_U_1(words) == 0) {
+       if (GET_U_1(words) == 0) {
            ND_PRINT("%s\n", fn->name);
            ND_PRINT("Trans2Interim\n");
            return;
        }
        ND_TCHECK_2(w + (7 * 2));
-       pcnt = EXTRACT_LE_U_2(w + 3 * 2);
-       param = buf + EXTRACT_LE_U_2(w + 4 * 2);
-       dcnt = EXTRACT_LE_U_2(w + 6 * 2);
-       data = buf + EXTRACT_LE_U_2(w + 7 * 2);
+       pcnt = GET_LE_U_2(w + 3 * 2);
+       param = buf + GET_LE_U_2(w + 4 * 2);
+       dcnt = GET_LE_U_2(w + 6 * 2);
+       data = buf + GET_LE_U_2(w + 7 * 2);
     }
 
     ND_PRINT("%s param_length=%u data_length=%u\n", fn->name, pcnt, dcnt);
 
     if (request) {
-       if (EXTRACT_U_1(words) == 8) {
+       if (GET_U_1(words) == 8) {
            smb_fdata(ndo, words + 1,
                "Trans2Secondary\nTotParam=[u]\nTotData=[u]\nParamCnt=[u]\nParamOff=[u]\nParamDisp=[u]\nDataCnt=[u]\nDataOff=[u]\nDataDisp=[u]\nHandle=[u]\n",
                maxbuf, unicodestr);
@@ -225,7 +225,7 @@ print_trans2(netdissect_options *ndo,
     }
 
     ND_TCHECK_2(dat);
-    bcc = EXTRACT_LE_U_2(dat);
+    bcc = GET_LE_U_2(dat);
     ND_PRINT("smb_bcc=%u\n", bcc);
     if (fn->descript.fn)
        (*fn->descript.fn)(ndo, param, data, pcnt, dcnt);
@@ -246,7 +246,7 @@ print_browse(netdissect_options *ndo,
     u_int command;
 
     ND_TCHECK_1(data);
-    command = EXTRACT_U_1(data);
+    command = GET_U_1(data);
 
     smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
 
@@ -344,20 +344,20 @@ print_trans(netdissect_options *ndo,
 
     if (request) {
        ND_TCHECK_2(w + (12 * 2));
-       paramlen = EXTRACT_LE_U_2(w + 9 * 2);
-       param = buf + EXTRACT_LE_U_2(w + 10 * 2);
-       datalen = EXTRACT_LE_U_2(w + 11 * 2);
-       data = buf + EXTRACT_LE_U_2(w + 12 * 2);
+       paramlen = GET_LE_U_2(w + 9 * 2);
+       param = buf + GET_LE_U_2(w + 10 * 2);
+       datalen = GET_LE_U_2(w + 11 * 2);
+       data = buf + GET_LE_U_2(w + 12 * 2);
        f1 = "TotParamCnt=[u]\nTotDataCnt=[u]\nMaxParmCnt=[u]\nMaxDataCnt=[u]\nMaxSCnt=[u]\nTransFlags=[w]\nRes1=[w]\nRes2=[w]\nRes3=[w]\nParamCnt=[u]\nParamOff=[u]\nDataCnt=[u]\nDataOff=[u]\nSUCnt=[u]\n";
        f2 = "|Name=[S]\n";
        f3 = "|Param ";
        f4 = "|Data ";
     } else {
        ND_TCHECK_2(w + (7 * 2));
-       paramlen = EXTRACT_LE_U_2(w + 3 * 2);
-       param = buf + EXTRACT_LE_U_2(w + 4 * 2);
-       datalen = EXTRACT_LE_U_2(w + 6 * 2);
-       data = buf + EXTRACT_LE_U_2(w + 7 * 2);
+       paramlen = GET_LE_U_2(w + 3 * 2);
+       param = buf + GET_LE_U_2(w + 4 * 2);
+       datalen = GET_LE_U_2(w + 6 * 2);
+       data = buf + GET_LE_U_2(w + 7 * 2);
        f1 = "TotParamCnt=[u]\nTotDataCnt=[u]\nRes1=[u]\nParamCnt=[u]\nParamOff=[u]\nRes2=[u]\nDataCnt=[u]\nDataOff=[u]\nRes3=[u]\nLsetup=[u]\n";
        f2 = "|Unknown ";
        f3 = "|Param ";
@@ -365,11 +365,11 @@ print_trans(netdissect_options *ndo,
     }
 
     smb_fdata(ndo, words + 1, f1,
-              min(words + 1 + 2 * EXTRACT_U_1(words), maxbuf),
+              min(words + 1 + 2 * GET_U_1(words), maxbuf),
               unicodestr);
 
     ND_TCHECK_2(data1);
-    bcc = EXTRACT_LE_U_2(data1);
+    bcc = GET_LE_U_2(data1);
     ND_PRINT("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
@@ -403,7 +403,7 @@ print_negprot(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = EXTRACT_U_1(words);
+    wct = GET_U_1(words);
     if (request)
        f2 = "*|Dialect=[Y]\n";
     else {
@@ -419,18 +419,18 @@ print_negprot(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       smb_data_print(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
 
     ND_TCHECK_2(data);
-    bcc = EXTRACT_LE_U_2(data);
+    bcc = GET_LE_U_2(data);
     ND_PRINT("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_U_2(data),
+           smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data),
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(EXTRACT_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -445,7 +445,7 @@ print_sesssetup(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = EXTRACT_U_1(words);
+    wct = GET_U_1(words);
     if (request) {
        if (wct == 10)
            f1 = "Com2=[w]\nOff2=[u]\nBufSize=[u]\nMpxMax=[u]\nVcNum=[u]\nSessionKey=[W]\nPassLen=[u]\nCryptLen=[u]\nCryptOff=[u]\nPass&Name=\n";
@@ -464,18 +464,18 @@ print_sesssetup(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
            unicodestr);
     else
-       smb_data_print(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
+       smb_data_print(ndo, words + 1, min(wct * 2, ND_BYTES_BETWEEN(maxbuf, words + 1)));
 
     ND_TCHECK_2(data);
-    bcc = EXTRACT_LE_U_2(data);
+    bcc = GET_LE_U_2(data);
     ND_PRINT("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_U_2(data),
+           smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data),
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(EXTRACT_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -491,11 +491,11 @@ print_lockingandx(netdissect_options *ndo,
     const char *f1 = NULL, *f2 = NULL;
 
     ND_TCHECK_1(words);
-    wct = EXTRACT_U_1(words);
+    wct = GET_U_1(words);
     if (request) {
        f1 = "Com2=[w]\nOff2=[u]\nHandle=[u]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[u]\nLockCount=[u]\n";
        ND_TCHECK_1(words + 7);
-       if (EXTRACT_U_1(words + 7) & 0x10)
+       if (GET_U_1(words + 7) & 0x10)
            f2 = "*Process=[u]\n[P2]Offset=[M]\nLength=[M]\n";
        else
            f2 = "*Process=[u]\nOffset=[D]\nLength=[U]\n";
@@ -508,15 +508,15 @@ print_lockingandx(netdissect_options *ndo,
        smb_fdata(ndo, words + 1, f1, maxwords, unicodestr);
 
     ND_TCHECK_2(data);
-    bcc = EXTRACT_LE_U_2(data);
+    bcc = GET_LE_U_2(data);
     ND_PRINT("smb_bcc=%u\n", bcc);
     if (bcc > 0) {
        if (f2)
-           smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_U_2(data),
+           smb_fdata(ndo, data + 2, f2, min(data + 2 + GET_LE_U_2(data),
                                              maxbuf), unicodestr);
        else
            smb_data_print(ndo, data + 2,
-                           min(EXTRACT_LE_U_2(data), PTR_DIFF(maxbuf, data + 2)));
+                           min(GET_LE_U_2(data), ND_BYTES_BETWEEN(maxbuf, data + 2)));
     }
     return;
 trunc:
@@ -810,10 +810,10 @@ print_smb(netdissect_options *ndo,
     u_int smboffset;
 
     ND_TCHECK_1(buf + 9);
-    request = (EXTRACT_U_1(buf + 9) & 0x80) ? 0 : 1;
+    request = (GET_U_1(buf + 9) & 0x80) ? 0 : 1;
     startbuf = buf;
 
-    command = EXTRACT_U_1(buf + 4);
+    command = GET_U_1(buf + 4);
 
     fn = smbfind(command, smb_fns);
 
@@ -826,7 +826,7 @@ print_smb(netdissect_options *ndo,
        return;
 
     ND_TCHECK_2(buf + 10);
-    flags2 = EXTRACT_LE_U_2(buf + 10);
+    flags2 = GET_LE_U_2(buf + 10);
     unicodestr = flags2 & 0x8000;
     nterrcodes = flags2 & 0x4000;
 
@@ -834,13 +834,13 @@ print_smb(netdissect_options *ndo,
     smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
 
     if (nterrcodes) {
-       nterror = EXTRACT_LE_U_4(buf + 5);
+       nterror = GET_LE_U_4(buf + 5);
        if (nterror)
            ND_PRINT("NTError = %s\n", nt_errstr(nterror));
     } else {
-       if (EXTRACT_U_1(buf + 5))
-           ND_PRINT("SMBError = %s\n", smb_errstr(EXTRACT_U_1(buf + 5),
-                     EXTRACT_LE_U_2(buf + 7)));
+       if (GET_U_1(buf + 5))
+           ND_PRINT("SMBError = %s\n", smb_errstr(GET_U_1(buf + 5),
+                                                   GET_LE_U_2(buf + 7)));
     }
 
     smboffset = 32;
@@ -853,7 +853,7 @@ print_smb(netdissect_options *ndo,
 
        words = buf + smboffset;
        ND_TCHECK_1(words);
-       wct = EXTRACT_U_1(words);
+       wct = GET_U_1(words);
        data = words + 1 + wct * 2;
        maxwords = min(data, maxbuf);
 
@@ -877,14 +877,14 @@ print_smb(netdissect_options *ndo,
 
                    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);
+                       v = GET_LE_U_2(words + 1 + 2 * i);
                        ND_PRINT("smb_vwv[%u]=%u (0x%X)\n", i, v, v);
                    }
                }
            }
 
            ND_TCHECK_2(data);
-           bcc = EXTRACT_LE_U_2(data);
+           bcc = GET_LE_U_2(data);
            ND_PRINT("smb_bcc=%u\n", bcc);
            if (f2) {
                if (bcc > 0)
@@ -892,7 +892,7 @@ print_smb(netdissect_options *ndo,
            } else {
                if (bcc > 0) {
                    ND_PRINT("smb_buf[]=\n");
-                   smb_data_print(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
+                   smb_data_print(ndo, data + 2, min(bcc, ND_BYTES_BETWEEN(maxbuf, data + 2)));
                }
            }
        }
@@ -902,11 +902,11 @@ print_smb(netdissect_options *ndo,
        if (wct == 0)
            break;
        ND_TCHECK_1(words + 1);
-       command = EXTRACT_U_1(words + 1);
+       command = GET_U_1(words + 1);
        if (command == 0xFF)
            break;
        ND_TCHECK_2(words + 3);
-       newsmboffset = EXTRACT_LE_U_2(words + 3);
+       newsmboffset = GET_LE_U_2(words + 3);
 
        fn = smbfind(command, smb_fns);
 
@@ -948,9 +948,9 @@ nbt_tcp_print(netdissect_options *ndo,
        goto trunc;
     maxbuf = data + caplen;
     ND_TCHECK_1(data);
-    type = EXTRACT_U_1(data);
+    type = GET_U_1(data);
     ND_TCHECK_2(data + 2);
-    nbt_len = EXTRACT_BE_U_2(data + 2);
+    nbt_len = GET_BE_U_2(data + 2);
     length -= 4;
     caplen -= 4;
 
@@ -981,7 +981,7 @@ nbt_tcp_print(netdissect_options *ndo,
                goto trunc;
            if (caplen < 4)
                goto trunc;
-           ecode = EXTRACT_U_1(data + 4);
+           ecode = GET_U_1(data + 4);
 
            ND_PRINT("Session Reject, ");
            switch (ecode) {
@@ -1054,7 +1054,7 @@ nbt_tcp_print(netdissect_options *ndo,
            if (data == NULL)
                break;
            if (nbt_len >= 1 && caplen >= 1) {
-               ecode = EXTRACT_U_1(origdata + 4);
+               ecode = GET_U_1(origdata + 4);
                switch (ecode) {
                case 0x80:
                    ND_PRINT("Not listening on called name\n");
@@ -1117,15 +1117,15 @@ nbt_udp137_print(netdissect_options *ndo,
 
     ndo->ndo_protocol = "nbt_udp137";
     ND_TCHECK_2(data + 10);
-    name_trn_id = EXTRACT_BE_U_2(data);
-    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);
-    arcount = EXTRACT_BE_U_2(data + 10);
+    name_trn_id = GET_BE_U_2(data);
+    response = (GET_U_1(data + 2) >> 7);
+    opcode = (GET_U_1(data + 2) >> 3) & 0xF;
+    nm_flags = ((GET_U_1(data + 2) & 0x7) << 4) + (GET_U_1(data + 3) >> 4);
+    rcode = GET_U_1(data + 3) & 0xF;
+    qdcount = GET_BE_U_2(data + 4);
+    ancount = GET_BE_U_2(data + 6);
+    nscount = GET_BE_U_2(data + 8);
+    arcount = GET_BE_U_2(data + 10);
     startbuf = data;
 
     if (maxbuf <= data)
@@ -1178,12 +1178,12 @@ nbt_udp137_print(netdissect_options *ndo,
            if (p == NULL)
                goto out;
            ND_TCHECK_2(p);
-           restype = EXTRACT_BE_U_2(p);
+           restype = GET_BE_U_2(p);
            p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rU]\n", p + 8, 0);
            if (p == NULL)
                goto out;
            ND_TCHECK_2(p);
-           rdlen = EXTRACT_BE_U_2(p);
+           rdlen = GET_BE_U_2(p);
            ND_PRINT("ResourceLength=%u\nResourceData=\n", rdlen);
            p += 2;
            if (rdlen == 6) {
@@ -1195,7 +1195,7 @@ nbt_udp137_print(netdissect_options *ndo,
                    u_int numnames;
 
                    ND_TCHECK_1(p);
-                   numnames = EXTRACT_U_1(p);
+                   numnames = GET_U_1(p);
                    p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
                    if (p == NULL)
                        goto out;
@@ -1206,21 +1206,21 @@ nbt_udp137_print(netdissect_options *ndo,
                        ND_TCHECK_1(p);
                        if (p >= maxbuf)
                            goto out;
-                       if (EXTRACT_U_1(p) & 0x80)
+                       if (GET_U_1(p) & 0x80)
                            ND_PRINT("<GROUP> ");
-                       switch (EXTRACT_U_1(p) & 0x60) {
+                       switch (GET_U_1(p) & 0x60) {
                        case 0x00: ND_PRINT("B "); break;
                        case 0x20: ND_PRINT("P "); break;
                        case 0x40: ND_PRINT("M "); break;
                        case 0x60: ND_PRINT("_ "); break;
                        }
-                       if (EXTRACT_U_1(p) & 0x10)
+                       if (GET_U_1(p) & 0x10)
                            ND_PRINT("<DEREGISTERING> ");
-                       if (EXTRACT_U_1(p) & 0x08)
+                       if (GET_U_1(p) & 0x08)
                            ND_PRINT("<CONFLICT> ");
-                       if (EXTRACT_U_1(p) & 0x04)
+                       if (GET_U_1(p) & 0x04)
                            ND_PRINT("<ACTIVE> ");
-                       if (EXTRACT_U_1(p) & 0x02)
+                       if (GET_U_1(p) & 0x02)
                            ND_PRINT("<PERMANENT> ");
                        ND_PRINT("\n");
                        p += 2;
@@ -1266,7 +1266,7 @@ smb_tcp_print(netdissect_options *ndo,
     if (caplen < 4)
        goto trunc;
     maxbuf = data + caplen;
-    smb_len = EXTRACT_BE_U_3(data + 1);
+    smb_len = GET_BE_U_3(data + 1);
     length -= 4;
     caplen -= 4;
 
@@ -1400,8 +1400,8 @@ netbeui_print(netdissect_options *ndo,
     if (maxbuf > ndo->ndo_snapend)
        maxbuf = ndo->ndo_snapend;
     ND_TCHECK_1(data + 4);
-    len = EXTRACT_LE_U_2(data);
-    command = EXTRACT_U_1(data + 4);
+    len = GET_LE_U_2(data);
+    command = GET_U_1(data + 4);
     data2 = data + len;
     if (data2 >= maxbuf) {
        data2 = maxbuf;