Home | History | Annotate | Line # | Download | only in dist
print-smb.c revision 1.1.1.5
      1 /*
      2  * Copyright (C) Andrew Tridgell 1995-1999
      3  *
      4  * This software may be distributed either under the terms of the
      5  * BSD-style license that accompanies tcpdump or the GNU GPL version 2
      6  * or later
      7  */
      8 
      9 #ifdef HAVE_CONFIG_H
     10 #include "config.h"
     11 #endif
     12 
     13 #include <netdissect-stdinc.h>
     14 
     15 #include <string.h>
     16 
     17 #include "netdissect.h"
     18 #include "extract.h"
     19 #include "smb.h"
     20 
     21 static const char tstr[] = "[|SMB]";
     22 
     23 static int request = 0;
     24 static int unicodestr = 0;
     25 
     26 const u_char *startbuf = NULL;
     27 
     28 struct smbdescript {
     29     const char *req_f1;
     30     const char *req_f2;
     31     const char *rep_f1;
     32     const char *rep_f2;
     33     void (*fn)(netdissect_options *, const u_char *, const u_char *, const u_char *, const u_char *);
     34 };
     35 
     36 struct smbdescriptint {
     37     const char *req_f1;
     38     const char *req_f2;
     39     const char *rep_f1;
     40     const char *rep_f2;
     41     void (*fn)(netdissect_options *, const u_char *, const u_char *, int, int);
     42 };
     43 
     44 struct smbfns
     45 {
     46     int id;
     47     const char *name;
     48     int flags;
     49     struct smbdescript descript;
     50 };
     51 
     52 struct smbfnsint
     53 {
     54     int id;
     55     const char *name;
     56     int flags;
     57     struct smbdescriptint descript;
     58 };
     59 
     60 #define DEFDESCRIPT	{ NULL, NULL, NULL, NULL, NULL }
     61 
     62 #define FLG_CHAIN	(1 << 0)
     63 
     64 static const struct smbfns *
     65 smbfind(int id, const struct smbfns *list)
     66 {
     67     int sindex;
     68 
     69     for (sindex = 0; list[sindex].name; sindex++)
     70 	if (list[sindex].id == id)
     71 	    return(&list[sindex]);
     72 
     73     return(&list[0]);
     74 }
     75 
     76 static const struct smbfnsint *
     77 smbfindint(int id, const struct smbfnsint *list)
     78 {
     79     int sindex;
     80 
     81     for (sindex = 0; list[sindex].name; sindex++)
     82 	if (list[sindex].id == id)
     83 	    return(&list[sindex]);
     84 
     85     return(&list[0]);
     86 }
     87 
     88 static void
     89 trans2_findfirst(netdissect_options *ndo,
     90                  const u_char *param, const u_char *data, int pcnt, int dcnt)
     91 {
     92     const char *fmt;
     93 
     94     if (request)
     95 	fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP4]\nFile=[S]\n";
     96     else
     97 	fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n";
     98 
     99     smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
    100     if (dcnt) {
    101 	ND_PRINT((ndo, "data:\n"));
    102 	smb_print_data(ndo, data, dcnt);
    103     }
    104 }
    105 
    106 static void
    107 trans2_qfsinfo(netdissect_options *ndo,
    108                const u_char *param, const u_char *data, int pcnt, int dcnt)
    109 {
    110     static int level = 0;
    111     const char *fmt="";
    112 
    113     if (request) {
    114 	ND_TCHECK2(*param, 2);
    115 	level = EXTRACT_LE_16BITS(param);
    116 	fmt = "InfoLevel=[d]\n";
    117 	smb_fdata(ndo, param, fmt, param + pcnt, unicodestr);
    118     } else {
    119 	switch (level) {
    120 	case 1:
    121 	    fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n";
    122 	    break;
    123 	case 2:
    124 	    fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
    125 	    break;
    126 	case 0x105:
    127 	    fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[lD]\nVolume=[C]\n";
    128 	    break;
    129 	default:
    130 	    fmt = "UnknownLevel\n";
    131 	    break;
    132 	}
    133 	smb_fdata(ndo, data, fmt, data + dcnt, unicodestr);
    134     }
    135     if (dcnt) {
    136 	ND_PRINT((ndo, "data:\n"));
    137 	smb_print_data(ndo, data, dcnt);
    138     }
    139     return;
    140 trunc:
    141     ND_PRINT((ndo, "%s", tstr));
    142 }
    143 
    144 static const struct smbfnsint trans2_fns[] = {
    145     { 0, "TRANSACT2_OPEN", 0,
    146 	{ "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]",
    147 	  NULL,
    148 	  "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",
    149 	  NULL, NULL }},
    150     { 1, "TRANSACT2_FINDFIRST", 0,
    151 	{ NULL, NULL, NULL, NULL, trans2_findfirst }},
    152     { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT },
    153     { 3, "TRANSACT2_QFSINFO", 0,
    154 	{ NULL, NULL, NULL, NULL, trans2_qfsinfo }},
    155     { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT },
    156     { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT },
    157     { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT },
    158     { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT },
    159     { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT },
    160     { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT },
    161     { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT },
    162     { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT },
    163     { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT },
    164     { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT },
    165     { -1, NULL, 0, DEFDESCRIPT }
    166 };
    167 
    168 
    169 static void
    170 print_trans2(netdissect_options *ndo,
    171              const u_char *words, const u_char *dat, const u_char *buf, const u_char *maxbuf)
    172 {
    173     u_int bcc;
    174     static const struct smbfnsint *fn = &trans2_fns[0];
    175     const u_char *data, *param;
    176     const u_char *w = words + 1;
    177     const char *f1 = NULL, *f2 = NULL;
    178     int pcnt, dcnt;
    179 
    180     ND_TCHECK(words[0]);
    181     if (request) {
    182 	ND_TCHECK2(w[14 * 2], 2);
    183 	pcnt = EXTRACT_LE_16BITS(w + 9 * 2);
    184 	param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
    185 	dcnt = EXTRACT_LE_16BITS(w + 11 * 2);
    186 	data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
    187 	fn = smbfindint(EXTRACT_LE_16BITS(w + 14 * 2), trans2_fns);
    188     } else {
    189 	if (words[0] == 0) {
    190 	    ND_PRINT((ndo, "%s\n", fn->name));
    191 	    ND_PRINT((ndo, "Trans2Interim\n"));
    192 	    return;
    193 	}
    194 	ND_TCHECK2(w[7 * 2], 2);
    195 	pcnt = EXTRACT_LE_16BITS(w + 3 * 2);
    196 	param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
    197 	dcnt = EXTRACT_LE_16BITS(w + 6 * 2);
    198 	data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
    199     }
    200 
    201     ND_PRINT((ndo, "%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt));
    202 
    203     if (request) {
    204 	if (words[0] == 8) {
    205 	    smb_fdata(ndo, words + 1,
    206 		"Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",
    207 		maxbuf, unicodestr);
    208 	    return;
    209 	} else {
    210 	    smb_fdata(ndo, words + 1,
    211 		"TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[b][P1]\n",
    212 		words + 1 + 14 * 2, unicodestr);
    213 	}
    214 	f1 = fn->descript.req_f1;
    215 	f2 = fn->descript.req_f2;
    216     } else {
    217 	smb_fdata(ndo, words + 1,
    218 	    "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[b][P1]\n",
    219 	    words + 1 + 10 * 2, unicodestr);
    220 	f1 = fn->descript.rep_f1;
    221 	f2 = fn->descript.rep_f2;
    222     }
    223 
    224     ND_TCHECK2(*dat, 2);
    225     bcc = EXTRACT_LE_16BITS(dat);
    226     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    227     if (fn->descript.fn)
    228 	(*fn->descript.fn)(ndo, param, data, pcnt, dcnt);
    229     else {
    230 	smb_fdata(ndo, param, f1 ? f1 : "Parameters=\n", param + pcnt, unicodestr);
    231 	smb_fdata(ndo, data, f2 ? f2 : "Data=\n", data + dcnt, unicodestr);
    232     }
    233     return;
    234 trunc:
    235     ND_PRINT((ndo, "%s", tstr));
    236 }
    237 
    238 static void
    239 print_browse(netdissect_options *ndo,
    240              const u_char *param, int paramlen, const u_char *data, int datalen)
    241 {
    242     const u_char *maxbuf = data + datalen;
    243     int command;
    244 
    245     ND_TCHECK(data[0]);
    246     command = data[0];
    247 
    248     smb_fdata(ndo, param, "BROWSE PACKET\n|Param ", param+paramlen, unicodestr);
    249 
    250     switch (command) {
    251     case 0xF:
    252 	data = smb_fdata(ndo, data,
    253 	    "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
    254 	    maxbuf, unicodestr);
    255 	break;
    256 
    257     case 0x1:
    258 	data = smb_fdata(ndo, data,
    259 	    "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
    260 	    maxbuf, unicodestr);
    261 	break;
    262 
    263     case 0x2:
    264 	data = smb_fdata(ndo, data,
    265 	    "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",
    266 	    maxbuf, unicodestr);
    267 	break;
    268 
    269     case 0xc:
    270 	data = smb_fdata(ndo, data,
    271 	    "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
    272 	    maxbuf, unicodestr);
    273 	break;
    274 
    275     case 0x8:
    276 	data = smb_fdata(ndo, data,
    277 	    "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n",
    278 	    maxbuf, unicodestr);
    279 	break;
    280 
    281     case 0xb:
    282 	data = smb_fdata(ndo, data,
    283 	    "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",
    284 	    maxbuf, unicodestr);
    285 	break;
    286 
    287     case 0x9:
    288 	data = smb_fdata(ndo, data,
    289 	    "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken=[W]\n",
    290 	    maxbuf, unicodestr);
    291 	break;
    292 
    293     case 0xa:
    294 	data = smb_fdata(ndo, data,
    295 	    "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken=[W]\n*Name=[S]\n",
    296 	    maxbuf, unicodestr);
    297 	break;
    298 
    299     case 0xd:
    300 	data = smb_fdata(ndo, data,
    301 	    "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",
    302 	    maxbuf, unicodestr);
    303 	break;
    304 
    305     case 0xe:
    306 	data = smb_fdata(ndo, data,
    307 	    "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf, unicodestr);
    308 	break;
    309 
    310     default:
    311 	data = smb_fdata(ndo, data, "Unknown Browser Frame ", maxbuf, unicodestr);
    312 	break;
    313     }
    314     return;
    315 trunc:
    316     ND_PRINT((ndo, "%s", tstr));
    317 }
    318 
    319 
    320 static void
    321 print_ipc(netdissect_options *ndo,
    322           const u_char *param, int paramlen, const u_char *data, int datalen)
    323 {
    324     if (paramlen)
    325 	smb_fdata(ndo, param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen,
    326 	    unicodestr);
    327     if (datalen)
    328 	smb_fdata(ndo, data, "IPC ", data + datalen, unicodestr);
    329 }
    330 
    331 
    332 static void
    333 print_trans(netdissect_options *ndo,
    334             const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf)
    335 {
    336     u_int bcc;
    337     const char *f1, *f2, *f3, *f4;
    338     const u_char *data, *param;
    339     const u_char *w = words + 1;
    340     int datalen, paramlen;
    341 
    342     if (request) {
    343 	ND_TCHECK2(w[12 * 2], 2);
    344 	paramlen = EXTRACT_LE_16BITS(w + 9 * 2);
    345 	param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
    346 	datalen = EXTRACT_LE_16BITS(w + 11 * 2);
    347 	data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
    348 	f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n";
    349 	f2 = "|Name=[S]\n";
    350 	f3 = "|Param ";
    351 	f4 = "|Data ";
    352     } else {
    353 	ND_TCHECK2(w[7 * 2], 2);
    354 	paramlen = EXTRACT_LE_16BITS(w + 3 * 2);
    355 	param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
    356 	datalen = EXTRACT_LE_16BITS(w + 6 * 2);
    357 	data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
    358 	f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n";
    359 	f2 = "|Unknown ";
    360 	f3 = "|Param ";
    361 	f4 = "|Data ";
    362     }
    363 
    364     smb_fdata(ndo, words + 1, f1, min(words + 1 + 2 * words[0], maxbuf),
    365         unicodestr);
    366 
    367     ND_TCHECK2(*data1, 2);
    368     bcc = EXTRACT_LE_16BITS(data1);
    369     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    370     if (bcc > 0) {
    371 	smb_fdata(ndo, data1 + 2, f2, maxbuf - (paramlen + datalen), unicodestr);
    372 
    373 	if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) {
    374 	    print_browse(ndo, param, paramlen, data, datalen);
    375 	    return;
    376 	}
    377 
    378 	if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) {
    379 	    print_ipc(ndo, param, paramlen, data, datalen);
    380 	    return;
    381 	}
    382 
    383 	if (paramlen)
    384 	    smb_fdata(ndo, param, f3, min(param + paramlen, maxbuf), unicodestr);
    385 	if (datalen)
    386 	    smb_fdata(ndo, data, f4, min(data + datalen, maxbuf), unicodestr);
    387     }
    388     return;
    389 trunc:
    390     ND_PRINT((ndo, "%s", tstr));
    391 }
    392 
    393 
    394 static void
    395 print_negprot(netdissect_options *ndo,
    396               const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    397 {
    398     u_int wct, bcc;
    399     const char *f1 = NULL, *f2 = NULL;
    400 
    401     ND_TCHECK(words[0]);
    402     wct = words[0];
    403     if (request)
    404 	f2 = "*|Dialect=[Y]\n";
    405     else {
    406 	if (wct == 1)
    407 	    f1 = "Core Protocol\nDialectIndex=[d]";
    408 	else if (wct == 17)
    409 	    f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey=";
    410 	else if (wct == 13)
    411 	    f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey=";
    412     }
    413 
    414     if (f1)
    415 	smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
    416 	    unicodestr);
    417     else
    418 	smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
    419 
    420     ND_TCHECK2(*data, 2);
    421     bcc = EXTRACT_LE_16BITS(data);
    422     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    423     if (bcc > 0) {
    424 	if (f2)
    425 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    426 		maxbuf), unicodestr);
    427 	else
    428 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    429     }
    430     return;
    431 trunc:
    432     ND_PRINT((ndo, "%s", tstr));
    433 }
    434 
    435 static void
    436 print_sesssetup(netdissect_options *ndo,
    437                 const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    438 {
    439     u_int wct, bcc;
    440     const char *f1 = NULL, *f2 = NULL;
    441 
    442     ND_TCHECK(words[0]);
    443     wct = words[0];
    444     if (request) {
    445 	if (wct == 10)
    446 	    f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
    447 	else
    448 	    f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n";
    449     } else {
    450 	if (wct == 3) {
    451 	    f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n";
    452 	} else if (wct == 13) {
    453 	    f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n";
    454 	    f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
    455 	}
    456     }
    457 
    458     if (f1)
    459 	smb_fdata(ndo, words + 1, f1, min(words + 1 + wct * 2, maxbuf),
    460 	    unicodestr);
    461     else
    462 	smb_print_data(ndo, words + 1, min(wct * 2, PTR_DIFF(maxbuf, words + 1)));
    463 
    464     ND_TCHECK2(*data, 2);
    465     bcc = EXTRACT_LE_16BITS(data);
    466     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    467     if (bcc > 0) {
    468 	if (f2)
    469 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    470 		maxbuf), unicodestr);
    471 	else
    472 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    473     }
    474     return;
    475 trunc:
    476     ND_PRINT((ndo, "%s", tstr));
    477 }
    478 
    479 static void
    480 print_lockingandx(netdissect_options *ndo,
    481                   const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
    482 {
    483     u_int wct, bcc;
    484     const u_char *maxwords;
    485     const char *f1 = NULL, *f2 = NULL;
    486 
    487     ND_TCHECK(words[0]);
    488     wct = words[0];
    489     if (request) {
    490 	f1 = "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n";
    491 	ND_TCHECK(words[7]);
    492 	if (words[7] & 0x10)
    493 	    f2 = "*Process=[d]\n[P2]Offset=[M]\nLength=[M]\n";
    494 	else
    495 	    f2 = "*Process=[d]\nOffset=[D]\nLength=[D]\n";
    496     } else {
    497 	f1 = "Com2=[w]\nOff2=[d]\n";
    498     }
    499 
    500     maxwords = min(words + 1 + wct * 2, maxbuf);
    501     if (wct)
    502 	smb_fdata(ndo, words + 1, f1, maxwords, unicodestr);
    503 
    504     ND_TCHECK2(*data, 2);
    505     bcc = EXTRACT_LE_16BITS(data);
    506     ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    507     if (bcc > 0) {
    508 	if (f2)
    509 	    smb_fdata(ndo, data + 2, f2, min(data + 2 + EXTRACT_LE_16BITS(data),
    510 		maxbuf), unicodestr);
    511 	else
    512 	    smb_print_data(ndo, data + 2, min(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
    513     }
    514     return;
    515 trunc:
    516     ND_PRINT((ndo, "%s", tstr));
    517 }
    518 
    519 
    520 static const struct smbfns smb_fns[] = {
    521     { -1, "SMBunknown", 0, DEFDESCRIPT },
    522 
    523     { SMBtcon, "SMBtcon", 0,
    524 	{ NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
    525 	  "MaxXmit=[d]\nTreeId=[d]\n", NULL,
    526 	  NULL } },
    527 
    528     { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
    529     { SMBexit,  "SMBexit", 0, DEFDESCRIPT },
    530     { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
    531 
    532     { SMBecho, "SMBecho", 0,
    533 	{ "ReverbCount=[d]\n", NULL,
    534 	  "SequenceNum=[d]\n", NULL,
    535 	  NULL } },
    536 
    537     { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
    538 
    539     { SMBgetatr, "SMBgetatr", 0,
    540 	{ NULL, "Path=[Z]\n",
    541 	  "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL,
    542 	  NULL } },
    543 
    544     { SMBsetatr, "SMBsetatr", 0,
    545 	{ "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
    546 	  NULL, NULL, NULL } },
    547 
    548     { SMBchkpth, "SMBchkpth", 0,
    549        { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    550 
    551     { SMBsearch, "SMBsearch", 0,
    552 	{ "Count=[d]\nAttrib=[A]\n",
    553 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n",
    554 	  "Count=[d]\n",
    555 	  "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
    556 	  NULL } },
    557 
    558     { SMBopen, "SMBopen", 0,
    559 	{ "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
    560 	  "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",
    561 	  NULL, NULL } },
    562 
    563     { SMBcreate, "SMBcreate", 0,
    564 	{ "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
    565 
    566     { SMBmknew, "SMBmknew", 0,
    567 	{ "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
    568 
    569     { SMBunlink, "SMBunlink", 0,
    570 	{ "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
    571 
    572     { SMBread, "SMBread", 0,
    573 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    574 	  "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
    575 
    576     { SMBwrite, "SMBwrite", 0,
    577 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    578 	  "Count=[d]\n", NULL, NULL } },
    579 
    580     { SMBclose, "SMBclose", 0,
    581 	{ "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } },
    582 
    583     { SMBmkdir, "SMBmkdir", 0,
    584 	{ NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    585 
    586     { SMBrmdir, "SMBrmdir", 0,
    587 	{ NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    588 
    589     { SMBdskattr, "SMBdskattr", 0,
    590 	{ NULL, NULL,
    591 	  "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n",
    592 	  NULL, NULL } },
    593 
    594     { SMBmv, "SMBmv", 0,
    595 	{ "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
    596 
    597     /*
    598      * this is a Pathworks specific call, allowing the
    599      * changing of the root path
    600      */
    601     { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
    602 
    603     { SMBlseek, "SMBlseek", 0,
    604 	{ "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
    605 
    606     { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    607 
    608     { SMBsplopen, "SMBsplopen", 0,
    609 	{ "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n",
    610 	  NULL, NULL } },
    611 
    612     { SMBsplclose, "SMBsplclose", 0,
    613 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    614 
    615     { SMBsplretq, "SMBsplretq", 0,
    616 	{ "MaxCount=[d]\nStartIndex=[d]\n", NULL,
    617 	  "Count=[d]\nIndex=[d]\n",
    618 	  "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n",
    619 	  NULL } },
    620 
    621     { SMBsplwr, "SMBsplwr", 0,
    622 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    623 
    624     { SMBlock, "SMBlock", 0,
    625 	{ "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
    626 
    627     { SMBunlock, "SMBunlock", 0,
    628 	{ "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
    629 
    630     /* CORE+ PROTOCOL FOLLOWS */
    631 
    632     { SMBreadbraw, "SMBreadbraw", 0,
    633 	{ "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n",
    634 	  NULL, NULL, NULL, NULL } },
    635 
    636     { SMBwritebraw, "SMBwritebraw", 0,
    637 	{ "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n",
    638 	  NULL, "WriteRawAck", NULL, NULL } },
    639 
    640     { SMBwritec, "SMBwritec", 0,
    641 	{ NULL, NULL, "Count=[d]\n", NULL, NULL } },
    642 
    643     { SMBwriteclose, "SMBwriteclose", 0,
    644 	{ "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
    645 	  NULL, "Count=[d]\n", NULL, NULL } },
    646 
    647     { SMBlockread, "SMBlockread", 0,
    648 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    649 	  "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
    650 
    651     { SMBwriteunlock, "SMBwriteunlock", 0,
    652 	{ "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
    653 	  "Count=[d]\n", NULL, NULL } },
    654 
    655     { SMBreadBmpx, "SMBreadBmpx", 0,
    656 	{ "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n",
    657 	  NULL,
    658 	  "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n",
    659 	  NULL, NULL } },
    660 
    661     { SMBwriteBmpx, "SMBwriteBmpx", 0,
    662 	{ "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL,
    663 	  "Remaining=[d]\n", NULL, NULL } },
    664 
    665     { SMBwriteBs, "SMBwriteBs", 0,
    666 	{ "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",
    667 	  NULL, "Count=[d]\n", NULL, NULL } },
    668 
    669     { SMBsetattrE, "SMBsetattrE", 0,
    670 	{ "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
    671 	  NULL, NULL, NULL } },
    672 
    673     { SMBgetattrE, "SMBgetattrE", 0,
    674 	{ "Handle=[d]\n", NULL,
    675 	  "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",
    676 	  NULL, NULL } },
    677 
    678     { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
    679     { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
    680 
    681     { SMBcopy, "SMBcopy", 0,
    682 	{ "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
    683 	  "CopyCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
    684 
    685     { SMBmove, "SMBmove", 0,
    686 	{ "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
    687 	  "MoveCount=[d]\n",  "|ErrStr=[S]\n",  NULL } },
    688 
    689     { SMBopenX, "SMBopenX", FLG_CHAIN,
    690 	{ "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n",
    691 	  "Path=[S]\n",
    692 	  "Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",
    693 	  NULL, NULL } },
    694 
    695     { SMBreadX, "SMBreadX", FLG_CHAIN,
    696 	{ "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",
    697 	  NULL,
    698 	  "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",
    699 	  NULL, NULL } },
    700 
    701     { SMBwriteX, "SMBwriteX", FLG_CHAIN,
    702 	{ "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",
    703 	  NULL,
    704 	  "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",
    705 	  NULL, NULL } },
    706 
    707     { SMBffirst, "SMBffirst", 0,
    708 	{ "Count=[d]\nAttrib=[A]\n",
    709 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    710 	  "Count=[d]\n",
    711 	  "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
    712 	  NULL } },
    713 
    714     { SMBfunique, "SMBfunique", 0,
    715 	{ "Count=[d]\nAttrib=[A]\n",
    716 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    717 	  "Count=[d]\n",
    718 	  "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
    719 	  NULL } },
    720 
    721     { SMBfclose, "SMBfclose", 0,
    722 	{ "Count=[d]\nAttrib=[A]\n",
    723 	  "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
    724 	  "Count=[d]\n",
    725 	  "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
    726 	  NULL } },
    727 
    728     { SMBfindnclose, "SMBfindnclose", 0,
    729 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    730 
    731     { SMBfindclose, "SMBfindclose", 0,
    732 	{ "Handle=[d]\n", NULL, NULL, NULL, NULL } },
    733 
    734     { SMBsends, "SMBsends", 0,
    735 	{ NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
    736 
    737     { SMBsendstrt, "SMBsendstrt", 0,
    738 	{ NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } },
    739 
    740     { SMBsendend, "SMBsendend", 0,
    741 	{ "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
    742 
    743     { SMBsendtxt, "SMBsendtxt", 0,
    744 	{ "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
    745 
    746     { SMBsendb, "SMBsendb", 0,
    747 	{ NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
    748 
    749     { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
    750     { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
    751     { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
    752 
    753     { SMBnegprot, "SMBnegprot", 0,
    754 	{ NULL, NULL, NULL, NULL, print_negprot } },
    755 
    756     { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
    757 	{ NULL, NULL, NULL, NULL, print_sesssetup } },
    758 
    759     { SMBtconX, "SMBtconX", FLG_CHAIN,
    760 	{ "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",
    761 	  NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[R]\n", NULL } },
    762 
    763     { SMBlockingX, "SMBlockingX", FLG_CHAIN,
    764 	{ NULL, NULL, NULL, NULL, print_lockingandx } },
    765 
    766     { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
    767 
    768     { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
    769     { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
    770     { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
    771     { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
    772 
    773     { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
    774     { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
    775 
    776     { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
    777 	{ "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[ld]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
    778 	  "Path=[C]\n",
    779 	  "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
    780 	  NULL, NULL } },
    781 
    782     { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
    783 
    784     { -1, NULL, 0, DEFDESCRIPT }
    785 };
    786 
    787 
    788 /*
    789  * print a SMB message
    790  */
    791 static void
    792 print_smb(netdissect_options *ndo,
    793           const u_char *buf, const u_char *maxbuf)
    794 {
    795     uint16_t flags2;
    796     int nterrcodes;
    797     int command;
    798     uint32_t nterror;
    799     const u_char *words, *maxwords, *data;
    800     const struct smbfns *fn;
    801     const char *fmt_smbheader =
    802         "[P4]SMB Command   =  [B]\nError class   =  [BP1]\nError code    =  [d]\nFlags1        =  [B]\nFlags2        =  [B][P13]\nTree ID       =  [d]\nProc ID       =  [d]\nUID           =  [d]\nMID           =  [d]\nWord Count    =  [b]\n";
    803     int smboffset;
    804 
    805     ND_TCHECK(buf[9]);
    806     request = (buf[9] & 0x80) ? 0 : 1;
    807     flags2 = EXTRACT_LE_16BITS(&buf[10]);
    808     unicodestr = flags2 & 0x8000;
    809     nterrcodes = flags2 & 0x4000;
    810     startbuf = buf;
    811 
    812     command = buf[4];
    813 
    814     fn = smbfind(command, smb_fns);
    815 
    816     if (ndo->ndo_vflag > 1)
    817 	ND_PRINT((ndo, "\n"));
    818 
    819     ND_PRINT((ndo, "SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY"));
    820 
    821     if (ndo->ndo_vflag < 2)
    822 	return;
    823 
    824     /* print out the header */
    825     smb_fdata(ndo, buf, fmt_smbheader, buf + 33, unicodestr);
    826 
    827     if (nterrcodes) {
    828     	nterror = EXTRACT_LE_32BITS(&buf[5]);
    829 	if (nterror)
    830 	    ND_PRINT((ndo, "NTError = %s\n", nt_errstr(nterror)));
    831     } else {
    832 	if (buf[5])
    833 	    ND_PRINT((ndo, "SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7]))));
    834     }
    835 
    836     smboffset = 32;
    837 
    838     for (;;) {
    839 	const char *f1, *f2;
    840 	int wct;
    841 	u_int bcc;
    842 	int newsmboffset;
    843 
    844 	words = buf + smboffset;
    845 	ND_TCHECK(words[0]);
    846 	wct = words[0];
    847 	data = words + 1 + wct * 2;
    848 	maxwords = min(data, maxbuf);
    849 
    850 	if (request) {
    851 	    f1 = fn->descript.req_f1;
    852 	    f2 = fn->descript.req_f2;
    853 	} else {
    854 	    f1 = fn->descript.rep_f1;
    855 	    f2 = fn->descript.rep_f2;
    856 	}
    857 
    858 	if (fn->descript.fn)
    859 	    (*fn->descript.fn)(ndo, words, data, buf, maxbuf);
    860 	else {
    861 	    if (wct) {
    862 		if (f1)
    863 		    smb_fdata(ndo, words + 1, f1, words + 1 + wct * 2, unicodestr);
    864 		else {
    865 		    int i;
    866 		    int v;
    867 
    868 		    for (i = 0; &words[1 + 2 * i] < maxwords; i++) {
    869 			ND_TCHECK2(words[1 + 2 * i], 2);
    870 			v = EXTRACT_LE_16BITS(words + 1 + 2 * i);
    871 			ND_PRINT((ndo, "smb_vwv[%d]=%d (0x%X)\n", i, v, v));
    872 		    }
    873 		}
    874 	    }
    875 
    876 	    ND_TCHECK2(*data, 2);
    877 	    bcc = EXTRACT_LE_16BITS(data);
    878 	    ND_PRINT((ndo, "smb_bcc=%u\n", bcc));
    879 	    if (f2) {
    880 		if (bcc > 0)
    881 		    smb_fdata(ndo, data + 2, f2, data + 2 + bcc, unicodestr);
    882 	    } else {
    883 		if (bcc > 0) {
    884 		    ND_PRINT((ndo, "smb_buf[]=\n"));
    885 		    smb_print_data(ndo, data + 2, min(bcc, PTR_DIFF(maxbuf, data + 2)));
    886 		}
    887 	    }
    888 	}
    889 
    890 	if ((fn->flags & FLG_CHAIN) == 0)
    891 	    break;
    892 	if (wct == 0)
    893 	    break;
    894 	ND_TCHECK(words[1]);
    895 	command = words[1];
    896 	if (command == 0xFF)
    897 	    break;
    898 	ND_TCHECK2(words[3], 2);
    899 	newsmboffset = EXTRACT_LE_16BITS(words + 3);
    900 
    901 	fn = smbfind(command, smb_fns);
    902 
    903 	ND_PRINT((ndo, "\nSMB PACKET: %s (%s) (CHAINED)\n",
    904 	    fn->name, request ? "REQUEST" : "REPLY"));
    905 	if (newsmboffset <= smboffset) {
    906 	    ND_PRINT((ndo, "Bad andX offset: %u <= %u\n", newsmboffset, smboffset));
    907 	    break;
    908 	}
    909 	smboffset = newsmboffset;
    910     }
    911 
    912     ND_PRINT((ndo, "\n"));
    913     return;
    914 trunc:
    915     ND_PRINT((ndo, "%s", tstr));
    916 }
    917 
    918 
    919 /*
    920  * print a NBT packet received across tcp on port 139
    921  */
    922 void
    923 nbt_tcp_print(netdissect_options *ndo,
    924               const u_char *data, int length)
    925 {
    926     int caplen;
    927     int type;
    928     u_int nbt_len;
    929     const u_char *maxbuf;
    930 
    931     if (length < 4)
    932 	goto trunc;
    933     if (ndo->ndo_snapend < data)
    934 	goto trunc;
    935     caplen = ndo->ndo_snapend - data;
    936     if (caplen < 4)
    937 	goto trunc;
    938     maxbuf = data + caplen;
    939     type = data[0];
    940     nbt_len = EXTRACT_16BITS(data + 2);
    941     length -= 4;
    942     caplen -= 4;
    943 
    944     startbuf = data;
    945 
    946     if (ndo->ndo_vflag < 2) {
    947 	ND_PRINT((ndo, " NBT Session Packet: "));
    948 	switch (type) {
    949 	case 0x00:
    950 	    ND_PRINT((ndo, "Session Message"));
    951 	    break;
    952 
    953 	case 0x81:
    954 	    ND_PRINT((ndo, "Session Request"));
    955 	    break;
    956 
    957 	case 0x82:
    958 	    ND_PRINT((ndo, "Session Granted"));
    959 	    break;
    960 
    961 	case 0x83:
    962 	  {
    963 	    int ecode;
    964 
    965 	    if (nbt_len < 4)
    966 		goto trunc;
    967 	    if (length < 4)
    968 		goto trunc;
    969 	    if (caplen < 4)
    970 		goto trunc;
    971 	    ecode = data[4];
    972 
    973 	    ND_PRINT((ndo, "Session Reject, "));
    974 	    switch (ecode) {
    975 	    case 0x80:
    976 		ND_PRINT((ndo, "Not listening on called name"));
    977 		break;
    978 	    case 0x81:
    979 		ND_PRINT((ndo, "Not listening for calling name"));
    980 		break;
    981 	    case 0x82:
    982 		ND_PRINT((ndo, "Called name not present"));
    983 		break;
    984 	    case 0x83:
    985 		ND_PRINT((ndo, "Called name present, but insufficient resources"));
    986 		break;
    987 	    default:
    988 		ND_PRINT((ndo, "Unspecified error 0x%X", ecode));
    989 		break;
    990 	    }
    991 	  }
    992 	    break;
    993 
    994 	case 0x85:
    995 	    ND_PRINT((ndo, "Session Keepalive"));
    996 	    break;
    997 
    998 	default:
    999 	    data = smb_fdata(ndo, data, "Unknown packet type [rB]", maxbuf, 0);
   1000 	    break;
   1001 	}
   1002     } else {
   1003 	ND_PRINT((ndo, "\n>>> NBT Session Packet\n"));
   1004 	switch (type) {
   1005 	case 0x00:
   1006 	    data = smb_fdata(ndo, data, "[P1]NBT Session Message\nFlags=[B]\nLength=[rd]\n",
   1007 		data + 4, 0);
   1008 	    if (data == NULL)
   1009 		break;
   1010 	    if (nbt_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
   1011 		if ((int)nbt_len > caplen) {
   1012 		    if ((int)nbt_len > length)
   1013 			ND_PRINT((ndo, "WARNING: Packet is continued in later TCP segments\n"));
   1014 		    else
   1015 			ND_PRINT((ndo, "WARNING: Short packet. Try increasing the snap length by %d\n",
   1016 			    nbt_len - caplen));
   1017 		}
   1018 		print_smb(ndo, data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
   1019 	    } else
   1020 		ND_PRINT((ndo, "Session packet:(raw data or continuation?)\n"));
   1021 	    break;
   1022 
   1023 	case 0x81:
   1024 	    data = smb_fdata(ndo, data,
   1025 		"[P1]NBT Session Request\nFlags=[B]\nLength=[rd]\nDestination=[n1]\nSource=[n1]\n",
   1026 		maxbuf, 0);
   1027 	    break;
   1028 
   1029 	case 0x82:
   1030 	    data = smb_fdata(ndo, data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
   1031 	    break;
   1032 
   1033 	case 0x83:
   1034 	  {
   1035 	    const u_char *origdata;
   1036 	    int ecode;
   1037 
   1038 	    origdata = data;
   1039 	    data = smb_fdata(ndo, data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[rd]\nReason=[B]\n",
   1040 		maxbuf, 0);
   1041 	    if (data == NULL)
   1042 		break;
   1043 	    if (nbt_len >= 1 && caplen >= 1) {
   1044 		ecode = origdata[4];
   1045 		switch (ecode) {
   1046 		case 0x80:
   1047 		    ND_PRINT((ndo, "Not listening on called name\n"));
   1048 		    break;
   1049 		case 0x81:
   1050 		    ND_PRINT((ndo, "Not listening for calling name\n"));
   1051 		    break;
   1052 		case 0x82:
   1053 		    ND_PRINT((ndo, "Called name not present\n"));
   1054 		    break;
   1055 		case 0x83:
   1056 		    ND_PRINT((ndo, "Called name present, but insufficient resources\n"));
   1057 		    break;
   1058 		default:
   1059 		    ND_PRINT((ndo, "Unspecified error 0x%X\n", ecode));
   1060 		    break;
   1061 		}
   1062 	    }
   1063 	  }
   1064 	    break;
   1065 
   1066 	case 0x85:
   1067 	    data = smb_fdata(ndo, data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[rd]\n", maxbuf, 0);
   1068 	    break;
   1069 
   1070 	default:
   1071 	    data = smb_fdata(ndo, data, "NBT - Unknown packet type\nType=[B]\n", maxbuf, 0);
   1072 	    break;
   1073 	}
   1074 	ND_PRINT((ndo, "\n"));
   1075     }
   1076     return;
   1077 trunc:
   1078     ND_PRINT((ndo, "%s", tstr));
   1079 }
   1080 
   1081 static const struct tok opcode_str[] = {
   1082 	{ 0,  "QUERY"                   },
   1083 	{ 5,  "REGISTRATION"            },
   1084 	{ 6,  "RELEASE"                 },
   1085 	{ 7,  "WACK"                    },
   1086 	{ 8,  "REFRESH(8)"              },
   1087 	{ 9,  "REFRESH"                 },
   1088 	{ 15, "MULTIHOMED REGISTRATION" },
   1089 	{ 0, NULL }
   1090 };
   1091 
   1092 /*
   1093  * print a NBT packet received across udp on port 137
   1094  */
   1095 void
   1096 nbt_udp137_print(netdissect_options *ndo,
   1097                  const u_char *data, int length)
   1098 {
   1099     const u_char *maxbuf = data + length;
   1100     int name_trn_id, response, opcode, nm_flags, rcode;
   1101     int qdcount, ancount, nscount, arcount;
   1102     const u_char *p;
   1103     int total, i;
   1104 
   1105     ND_TCHECK2(data[10], 2);
   1106     name_trn_id = EXTRACT_16BITS(data);
   1107     response = (data[2] >> 7);
   1108     opcode = (data[2] >> 3) & 0xF;
   1109     nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
   1110     rcode = data[3] & 0xF;
   1111     qdcount = EXTRACT_16BITS(data + 4);
   1112     ancount = EXTRACT_16BITS(data + 6);
   1113     nscount = EXTRACT_16BITS(data + 8);
   1114     arcount = EXTRACT_16BITS(data + 10);
   1115     startbuf = data;
   1116 
   1117     if (maxbuf <= data)
   1118 	return;
   1119 
   1120     if (ndo->ndo_vflag > 1)
   1121 	ND_PRINT((ndo, "\n>>> "));
   1122 
   1123     ND_PRINT((ndo, "NBT UDP PACKET(137): %s", tok2str(opcode_str, "OPUNKNOWN", opcode)));
   1124     if (response) {
   1125         ND_PRINT((ndo, "; %s", rcode ? "NEGATIVE" : "POSITIVE"));
   1126     }
   1127     ND_PRINT((ndo, "; %s; %s", response ? "RESPONSE" : "REQUEST",
   1128               (nm_flags & 1) ? "BROADCAST" : "UNICAST"));
   1129 
   1130     if (ndo->ndo_vflag < 2)
   1131 	return;
   1132 
   1133     ND_PRINT((ndo, "\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n",
   1134 	name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
   1135 	arcount));
   1136 
   1137     p = data + 12;
   1138 
   1139     total = ancount + nscount + arcount;
   1140 
   1141     if (qdcount > 100 || total > 100) {
   1142 	ND_PRINT((ndo, "Corrupt packet??\n"));
   1143 	return;
   1144     }
   1145 
   1146     if (qdcount) {
   1147 	ND_PRINT((ndo, "QuestionRecords:\n"));
   1148 	for (i = 0; i < qdcount; i++) {
   1149 	    p = smb_fdata(ndo, p,
   1150 		"|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
   1151 		maxbuf, 0);
   1152 	    if (p == NULL)
   1153 		goto out;
   1154 	}
   1155     }
   1156 
   1157     if (total) {
   1158 	ND_PRINT((ndo, "\nResourceRecords:\n"));
   1159 	for (i = 0; i < total; i++) {
   1160 	    int rdlen;
   1161 	    int restype;
   1162 
   1163 	    p = smb_fdata(ndo, p, "Name=[n1]\n#", maxbuf, 0);
   1164 	    if (p == NULL)
   1165 		goto out;
   1166 	    restype = EXTRACT_16BITS(p);
   1167 	    p = smb_fdata(ndo, p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8, 0);
   1168 	    if (p == NULL)
   1169 		goto out;
   1170 	    rdlen = EXTRACT_16BITS(p);
   1171 	    ND_PRINT((ndo, "ResourceLength=%d\nResourceData=\n", rdlen));
   1172 	    p += 2;
   1173 	    if (rdlen == 6) {
   1174 		p = smb_fdata(ndo, p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen, 0);
   1175 		if (p == NULL)
   1176 		    goto out;
   1177 	    } else {
   1178 		if (restype == 0x21) {
   1179 		    int numnames;
   1180 
   1181 		    ND_TCHECK(*p);
   1182 		    numnames = p[0];
   1183 		    p = smb_fdata(ndo, p, "NumNames=[B]\n", p + 1, 0);
   1184 		    if (p == NULL)
   1185 			goto out;
   1186 		    while (numnames--) {
   1187 			p = smb_fdata(ndo, p, "Name=[n2]\t#", maxbuf, 0);
   1188 			if (p == NULL)
   1189 			    goto out;
   1190 			ND_TCHECK(*p);
   1191 			if (p[0] & 0x80)
   1192 			    ND_PRINT((ndo, "<GROUP> "));
   1193 			switch (p[0] & 0x60) {
   1194 			case 0x00: ND_PRINT((ndo, "B ")); break;
   1195 			case 0x20: ND_PRINT((ndo, "P ")); break;
   1196 			case 0x40: ND_PRINT((ndo, "M ")); break;
   1197 			case 0x60: ND_PRINT((ndo, "_ ")); break;
   1198 			}
   1199 			if (p[0] & 0x10)
   1200 			    ND_PRINT((ndo, "<DEREGISTERING> "));
   1201 			if (p[0] & 0x08)
   1202 			    ND_PRINT((ndo, "<CONFLICT> "));
   1203 			if (p[0] & 0x04)
   1204 			    ND_PRINT((ndo, "<ACTIVE> "));
   1205 			if (p[0] & 0x02)
   1206 			    ND_PRINT((ndo, "<PERMANENT> "));
   1207 			ND_PRINT((ndo, "\n"));
   1208 			p += 2;
   1209 		    }
   1210 		} else {
   1211 		    smb_print_data(ndo, p, min(rdlen, length - (p - data)));
   1212 		    p += rdlen;
   1213 		}
   1214 	    }
   1215 	}
   1216     }
   1217 
   1218     if (p < maxbuf)
   1219 	smb_fdata(ndo, p, "AdditionalData:\n", maxbuf, 0);
   1220 
   1221 out:
   1222     ND_PRINT((ndo, "\n"));
   1223     return;
   1224 trunc:
   1225     ND_PRINT((ndo, "%s", tstr));
   1226 }
   1227 
   1228 /*
   1229  * Print an SMB-over-TCP packet received across tcp on port 445
   1230  */
   1231 void
   1232 smb_tcp_print(netdissect_options *ndo,
   1233               const u_char * data, int length)
   1234 {
   1235     int caplen;
   1236     u_int smb_len;
   1237     const u_char *maxbuf;
   1238 
   1239     if (length < 4)
   1240 	goto trunc;
   1241     if (ndo->ndo_snapend < data)
   1242 	goto trunc;
   1243     caplen = ndo->ndo_snapend - data;
   1244     if (caplen < 4)
   1245 	goto trunc;
   1246     maxbuf = data + caplen;
   1247     smb_len = EXTRACT_24BITS(data + 1);
   1248     length -= 4;
   1249     caplen -= 4;
   1250 
   1251     startbuf = data;
   1252     data += 4;
   1253 
   1254     if (smb_len >= 4 && caplen >= 4 && memcmp(data,"\377SMB",4) == 0) {
   1255 	if ((int)smb_len > caplen) {
   1256 	    if ((int)smb_len > length)
   1257 		ND_PRINT((ndo, " WARNING: Packet is continued in later TCP segments\n"));
   1258 	    else
   1259 		ND_PRINT((ndo, " WARNING: Short packet. Try increasing the snap length by %d\n",
   1260 		    smb_len - caplen));
   1261 	} else
   1262 	    ND_PRINT((ndo, " "));
   1263 	print_smb(ndo, data, maxbuf > data + smb_len ? data + smb_len : maxbuf);
   1264     } else
   1265 	ND_PRINT((ndo, " SMB-over-TCP packet:(raw data or continuation?)\n"));
   1266     return;
   1267 trunc:
   1268     ND_PRINT((ndo, "%s", tstr));
   1269 }
   1270 
   1271 /*
   1272  * print a NBT packet received across udp on port 138
   1273  */
   1274 void
   1275 nbt_udp138_print(netdissect_options *ndo,
   1276                  const u_char *data, int length)
   1277 {
   1278     const u_char *maxbuf = data + length;
   1279 
   1280     if (maxbuf > ndo->ndo_snapend)
   1281 	maxbuf = ndo->ndo_snapend;
   1282     if (maxbuf <= data)
   1283 	return;
   1284     startbuf = data;
   1285 
   1286     if (ndo->ndo_vflag < 2) {
   1287 	ND_PRINT((ndo, "NBT UDP PACKET(138)"));
   1288 	return;
   1289     }
   1290 
   1291     data = smb_fdata(ndo, data,
   1292 	"\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",
   1293 	maxbuf, 0);
   1294 
   1295     if (data != NULL) {
   1296 	/* If there isn't enough data for "\377SMB", don't check for it. */
   1297 	if (&data[3] >= maxbuf)
   1298 	    goto out;
   1299 
   1300 	if (memcmp(data, "\377SMB",4) == 0)
   1301 	    print_smb(ndo, data, maxbuf);
   1302     }
   1303 out:
   1304     ND_PRINT((ndo, "\n"));
   1305 }
   1306 
   1307 
   1308 /*
   1309    print netbeui frames
   1310 */
   1311 struct nbf_strings {
   1312 	const char	*name;
   1313 	const char	*nonverbose;
   1314 	const char	*verbose;
   1315 } nbf_strings[0x20] = {
   1316 	{ "Add Group Name Query", ", [P23]Name to add=[n2]#",
   1317 	  "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
   1318 	{ "Add Name Query", ", [P23]Name to add=[n2]#",
   1319 	  "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
   1320 	{ "Name In Conflict", NULL, NULL },
   1321 	{ "Status Query", NULL, NULL },
   1322 	{ NULL, NULL, NULL },	/* not used */
   1323 	{ NULL, NULL, NULL },	/* not used */
   1324 	{ NULL, NULL, NULL },	/* not used */
   1325 	{ "Terminate Trace", NULL, NULL },
   1326 	{ "Datagram", NULL,
   1327 	  "[P7]Destination=[n2]\nSource=[n2]\n" },
   1328 	{ "Broadcast Datagram", NULL,
   1329 	  "[P7]Destination=[n2]\nSource=[n2]\n" },
   1330 	{ "Name Query", ", [P7]Name=[n2]#",
   1331 	  "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
   1332 	{ NULL, NULL, NULL },	/* not used */
   1333 	{ NULL, NULL, NULL },	/* not used */
   1334 	{ "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
   1335 	  "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
   1336 	{ "Name Recognized", NULL,
   1337 	  "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
   1338 	{ "Status Response", NULL, NULL },
   1339 	{ NULL, NULL, NULL },	/* not used */
   1340 	{ NULL, NULL, NULL },	/* not used */
   1341 	{ NULL, NULL, NULL },	/* not used */
   1342 	{ "Terminate Trace", NULL, NULL },
   1343 	{ "Data Ack", NULL,
   1344 	  "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1345 	{ "Data First/Middle", NULL,
   1346 	  "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1347 	{ "Data Only/Last", NULL,
   1348 	  "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1349 	{ "Session Confirm", NULL,
   1350 	  "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1351 	{ "Session End", NULL,
   1352 	  "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1353 	{ "Session Initialize", NULL,
   1354 	  "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1355 	{ "No Receive", NULL,
   1356 	  "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1357 	{ "Receive Outstanding", NULL,
   1358 	  "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1359 	{ "Receive Continue", NULL,
   1360 	  "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
   1361 	{ NULL, NULL, NULL },	/* not used */
   1362 	{ NULL, NULL, NULL },	/* not used */
   1363 	{ "Session Alive", NULL, NULL }
   1364 };
   1365 
   1366 void
   1367 netbeui_print(netdissect_options *ndo,
   1368               u_short control, const u_char *data, int length)
   1369 {
   1370     const u_char *maxbuf = data + length;
   1371     int len;
   1372     int command;
   1373     const u_char *data2;
   1374     int is_truncated = 0;
   1375 
   1376     if (maxbuf > ndo->ndo_snapend)
   1377 	maxbuf = ndo->ndo_snapend;
   1378     ND_TCHECK(data[4]);
   1379     len = EXTRACT_LE_16BITS(data);
   1380     command = data[4];
   1381     data2 = data + len;
   1382     if (data2 >= maxbuf) {
   1383 	data2 = maxbuf;
   1384 	is_truncated = 1;
   1385     }
   1386 
   1387     startbuf = data;
   1388 
   1389     if (ndo->ndo_vflag < 2) {
   1390 	ND_PRINT((ndo, "NBF Packet: "));
   1391 	data = smb_fdata(ndo, data, "[P5]#", maxbuf, 0);
   1392     } else {
   1393 	ND_PRINT((ndo, "\n>>> NBF Packet\nType=0x%X ", control));
   1394 	data = smb_fdata(ndo, data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf, 0);
   1395     }
   1396     if (data == NULL)
   1397 	goto out;
   1398 
   1399     if (command > 0x1f || nbf_strings[command].name == NULL) {
   1400 	if (ndo->ndo_vflag < 2)
   1401 	    data = smb_fdata(ndo, data, "Unknown NBF Command#", data2, 0);
   1402 	else
   1403 	    data = smb_fdata(ndo, data, "Unknown NBF Command\n", data2, 0);
   1404     } else {
   1405 	if (ndo->ndo_vflag < 2) {
   1406 	    ND_PRINT((ndo, "%s", nbf_strings[command].name));
   1407 	    if (nbf_strings[command].nonverbose != NULL)
   1408 		data = smb_fdata(ndo, data, nbf_strings[command].nonverbose, data2, 0);
   1409 	} else {
   1410 	    ND_PRINT((ndo, "%s:\n", nbf_strings[command].name));
   1411 	    if (nbf_strings[command].verbose != NULL)
   1412 		data = smb_fdata(ndo, data, nbf_strings[command].verbose, data2, 0);
   1413 	    else
   1414 		ND_PRINT((ndo, "\n"));
   1415 	}
   1416     }
   1417 
   1418     if (ndo->ndo_vflag < 2)
   1419 	return;
   1420 
   1421     if (data == NULL)
   1422 	goto out;
   1423 
   1424     if (is_truncated) {
   1425 	/* data2 was past the end of the buffer */
   1426 	goto out;
   1427     }
   1428 
   1429     /* If this isn't a command that would contain an SMB message, quit. */
   1430     if (command != 0x08 && command != 0x09 && command != 0x15 &&
   1431         command != 0x16)
   1432 	goto out;
   1433 
   1434     /* If there isn't enough data for "\377SMB", don't look for it. */
   1435     if (&data2[3] >= maxbuf)
   1436 	goto out;
   1437 
   1438     if (memcmp(data2, "\377SMB",4) == 0)
   1439 	print_smb(ndo, data2, maxbuf);
   1440     else {
   1441 	int i;
   1442 	for (i = 0; i < 128; i++) {
   1443 	    if (&data2[i + 3] >= maxbuf)
   1444 		break;
   1445 	    if (memcmp(&data2[i], "\377SMB", 4) == 0) {
   1446 		ND_PRINT((ndo, "found SMB packet at %d\n", i));
   1447 		print_smb(ndo, &data2[i], maxbuf);
   1448 		break;
   1449 	    }
   1450 	}
   1451     }
   1452 
   1453 out:
   1454     ND_PRINT((ndo, "\n"));
   1455     return;
   1456 trunc:
   1457     ND_PRINT((ndo, "%s", tstr));
   1458 }
   1459 
   1460 
   1461 /*
   1462  * print IPX-Netbios frames
   1463  */
   1464 void
   1465 ipx_netbios_print(netdissect_options *ndo,
   1466                   const u_char *data, u_int length)
   1467 {
   1468     /*
   1469      * this is a hack till I work out how to parse the rest of the
   1470      * NetBIOS-over-IPX stuff
   1471      */
   1472     int i;
   1473     const u_char *maxbuf;
   1474 
   1475     maxbuf = data + length;
   1476     /* Don't go past the end of the captured data in the packet. */
   1477     if (maxbuf > ndo->ndo_snapend)
   1478 	maxbuf = ndo->ndo_snapend;
   1479     startbuf = data;
   1480     for (i = 0; i < 128; i++) {
   1481 	if (&data[i + 4] > maxbuf)
   1482 	    break;
   1483 	if (memcmp(&data[i], "\377SMB", 4) == 0) {
   1484 	    smb_fdata(ndo, data, "\n>>> IPX transport ", &data[i], 0);
   1485 	    print_smb(ndo, &data[i], maxbuf);
   1486 	    ND_PRINT((ndo, "\n"));
   1487 	    break;
   1488 	}
   1489     }
   1490     if (i == 128)
   1491 	smb_fdata(ndo, data, "\n>>> Unknown IPX ", maxbuf, 0);
   1492 }
   1493