print-smb.c 43 KB

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