print-atalk.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. /*
  2. * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
  3. * The Regents of the University of California. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. */
  21. /* \summary: AppleTalk printer */
  22. #ifdef HAVE_CONFIG_H
  23. #include "config.h"
  24. #endif
  25. #include <netdissect-stdinc.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28. #include "netdissect.h"
  29. #include "addrtoname.h"
  30. #include "ethertype.h"
  31. #include "extract.h"
  32. #include "appletalk.h"
  33. static const char tstr[] = "[|atalk]";
  34. static const struct tok type2str[] = {
  35. { ddpRTMP, "rtmp" },
  36. { ddpRTMPrequest, "rtmpReq" },
  37. { ddpECHO, "echo" },
  38. { ddpIP, "IP" },
  39. { ddpARP, "ARP" },
  40. { ddpKLAP, "KLAP" },
  41. { 0, NULL }
  42. };
  43. struct aarp {
  44. uint16_t htype, ptype;
  45. uint8_t halen, palen;
  46. uint16_t op;
  47. uint8_t hsaddr[6];
  48. uint8_t psaddr[4];
  49. uint8_t hdaddr[6];
  50. uint8_t pdaddr[4];
  51. };
  52. static void atp_print(netdissect_options *, const struct atATP *, u_int);
  53. static void atp_bitmap_print(netdissect_options *, u_char);
  54. static void nbp_print(netdissect_options *, const struct atNBP *, u_int, u_short, u_char, u_char);
  55. static const struct atNBPtuple *nbp_tuple_print(netdissect_options *ndo, const struct atNBPtuple *,
  56. const u_char *,
  57. u_short, u_char, u_char);
  58. static const struct atNBPtuple *nbp_name_print(netdissect_options *, const struct atNBPtuple *,
  59. const u_char *);
  60. static const char *ataddr_string(netdissect_options *, u_short, u_char);
  61. static void ddp_print(netdissect_options *, const u_char *, u_int, int, u_short, u_char, u_char);
  62. static const char *ddpskt_string(netdissect_options *, int);
  63. /*
  64. * Print LLAP packets received on a physical LocalTalk interface.
  65. */
  66. u_int
  67. ltalk_if_print(netdissect_options *ndo,
  68. const struct pcap_pkthdr *h, const u_char *p)
  69. {
  70. u_int hdrlen;
  71. hdrlen = llap_print(ndo, p, h->len);
  72. if (hdrlen == 0) {
  73. /* Cut short by the snapshot length. */
  74. return (h->caplen);
  75. }
  76. return (hdrlen);
  77. }
  78. /*
  79. * Print AppleTalk LLAP packets.
  80. */
  81. u_int
  82. llap_print(netdissect_options *ndo,
  83. register const u_char *bp, u_int length)
  84. {
  85. register const struct LAP *lp;
  86. register const struct atDDP *dp;
  87. register const struct atShortDDP *sdp;
  88. u_short snet;
  89. u_int hdrlen;
  90. if (length < sizeof(*lp)) {
  91. ND_PRINT((ndo, " [|llap %u]", length));
  92. return (length);
  93. }
  94. if (!ND_TTEST2(*bp, sizeof(*lp))) {
  95. ND_PRINT((ndo, " [|llap]"));
  96. return (0); /* cut short by the snapshot length */
  97. }
  98. lp = (const struct LAP *)bp;
  99. bp += sizeof(*lp);
  100. length -= sizeof(*lp);
  101. hdrlen = sizeof(*lp);
  102. switch (lp->type) {
  103. case lapShortDDP:
  104. if (length < ddpSSize) {
  105. ND_PRINT((ndo, " [|sddp %u]", length));
  106. return (length);
  107. }
  108. if (!ND_TTEST2(*bp, ddpSSize)) {
  109. ND_PRINT((ndo, " [|sddp]"));
  110. return (0); /* cut short by the snapshot length */
  111. }
  112. sdp = (const struct atShortDDP *)bp;
  113. ND_PRINT((ndo, "%s.%s",
  114. ataddr_string(ndo, 0, lp->src), ddpskt_string(ndo, sdp->srcSkt)));
  115. ND_PRINT((ndo, " > %s.%s:",
  116. ataddr_string(ndo, 0, lp->dst), ddpskt_string(ndo, sdp->dstSkt)));
  117. bp += ddpSSize;
  118. length -= ddpSSize;
  119. hdrlen += ddpSSize;
  120. ddp_print(ndo, bp, length, sdp->type, 0, lp->src, sdp->srcSkt);
  121. break;
  122. case lapDDP:
  123. if (length < ddpSize) {
  124. ND_PRINT((ndo, " [|ddp %u]", length));
  125. return (length);
  126. }
  127. if (!ND_TTEST2(*bp, ddpSize)) {
  128. ND_PRINT((ndo, " [|ddp]"));
  129. return (0); /* cut short by the snapshot length */
  130. }
  131. dp = (const struct atDDP *)bp;
  132. snet = EXTRACT_16BITS(&dp->srcNet);
  133. ND_PRINT((ndo, "%s.%s", ataddr_string(ndo, snet, dp->srcNode),
  134. ddpskt_string(ndo, dp->srcSkt)));
  135. ND_PRINT((ndo, " > %s.%s:",
  136. ataddr_string(ndo, EXTRACT_16BITS(&dp->dstNet), dp->dstNode),
  137. ddpskt_string(ndo, dp->dstSkt)));
  138. bp += ddpSize;
  139. length -= ddpSize;
  140. hdrlen += ddpSize;
  141. ddp_print(ndo, bp, length, dp->type, snet, dp->srcNode, dp->srcSkt);
  142. break;
  143. #ifdef notdef
  144. case lapKLAP:
  145. klap_print(bp, length);
  146. break;
  147. #endif
  148. default:
  149. ND_PRINT((ndo, "%d > %d at-lap#%d %u",
  150. lp->src, lp->dst, lp->type, length));
  151. break;
  152. }
  153. return (hdrlen);
  154. }
  155. /*
  156. * Print EtherTalk/TokenTalk packets (or FDDITalk, or whatever it's called
  157. * when it runs over FDDI; yes, I've seen FDDI captures with AppleTalk
  158. * packets in them).
  159. */
  160. void
  161. atalk_print(netdissect_options *ndo,
  162. register const u_char *bp, u_int length)
  163. {
  164. register const struct atDDP *dp;
  165. u_short snet;
  166. if(!ndo->ndo_eflag)
  167. ND_PRINT((ndo, "AT "));
  168. if (length < ddpSize) {
  169. ND_PRINT((ndo, " [|ddp %u]", length));
  170. return;
  171. }
  172. if (!ND_TTEST2(*bp, ddpSize)) {
  173. ND_PRINT((ndo, " [|ddp]"));
  174. return;
  175. }
  176. dp = (const struct atDDP *)bp;
  177. snet = EXTRACT_16BITS(&dp->srcNet);
  178. ND_PRINT((ndo, "%s.%s", ataddr_string(ndo, snet, dp->srcNode),
  179. ddpskt_string(ndo, dp->srcSkt)));
  180. ND_PRINT((ndo, " > %s.%s: ",
  181. ataddr_string(ndo, EXTRACT_16BITS(&dp->dstNet), dp->dstNode),
  182. ddpskt_string(ndo, dp->dstSkt)));
  183. bp += ddpSize;
  184. length -= ddpSize;
  185. ddp_print(ndo, bp, length, dp->type, snet, dp->srcNode, dp->srcSkt);
  186. }
  187. /* XXX should probably pass in the snap header and do checks like arp_print() */
  188. void
  189. aarp_print(netdissect_options *ndo,
  190. register const u_char *bp, u_int length)
  191. {
  192. register const struct aarp *ap;
  193. #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
  194. ND_PRINT((ndo, "aarp "));
  195. ap = (const struct aarp *)bp;
  196. if (!ND_TTEST(*ap)) {
  197. /* Just bail if we don't have the whole chunk. */
  198. ND_PRINT((ndo, " [|aarp]"));
  199. return;
  200. }
  201. if (length < sizeof(*ap)) {
  202. ND_PRINT((ndo, " [|aarp %u]", length));
  203. return;
  204. }
  205. if (EXTRACT_16BITS(&ap->htype) == 1 &&
  206. EXTRACT_16BITS(&ap->ptype) == ETHERTYPE_ATALK &&
  207. ap->halen == 6 && ap->palen == 4 )
  208. switch (EXTRACT_16BITS(&ap->op)) {
  209. case 1: /* request */
  210. ND_PRINT((ndo, "who-has %s tell %s", AT(pdaddr), AT(psaddr)));
  211. return;
  212. case 2: /* response */
  213. ND_PRINT((ndo, "reply %s is-at %s", AT(psaddr), etheraddr_string(ndo, ap->hsaddr)));
  214. return;
  215. case 3: /* probe (oy!) */
  216. ND_PRINT((ndo, "probe %s tell %s", AT(pdaddr), AT(psaddr)));
  217. return;
  218. }
  219. ND_PRINT((ndo, "len %u op %u htype %u ptype %#x halen %u palen %u",
  220. length, EXTRACT_16BITS(&ap->op), EXTRACT_16BITS(&ap->htype),
  221. EXTRACT_16BITS(&ap->ptype), ap->halen, ap->palen));
  222. }
  223. /*
  224. * Print AppleTalk Datagram Delivery Protocol packets.
  225. */
  226. static void
  227. ddp_print(netdissect_options *ndo,
  228. register const u_char *bp, register u_int length, register int t,
  229. register u_short snet, register u_char snode, u_char skt)
  230. {
  231. switch (t) {
  232. case ddpNBP:
  233. nbp_print(ndo, (const struct atNBP *)bp, length, snet, snode, skt);
  234. break;
  235. case ddpATP:
  236. atp_print(ndo, (const struct atATP *)bp, length);
  237. break;
  238. case ddpEIGRP:
  239. eigrp_print(ndo, bp, length);
  240. break;
  241. default:
  242. ND_PRINT((ndo, " at-%s %d", tok2str(type2str, NULL, t), length));
  243. break;
  244. }
  245. }
  246. static void
  247. atp_print(netdissect_options *ndo,
  248. register const struct atATP *ap, u_int length)
  249. {
  250. char c;
  251. uint32_t data;
  252. if ((const u_char *)(ap + 1) > ndo->ndo_snapend) {
  253. /* Just bail if we don't have the whole chunk. */
  254. ND_PRINT((ndo, "%s", tstr));
  255. return;
  256. }
  257. if (length < sizeof(*ap)) {
  258. ND_PRINT((ndo, " [|atp %u]", length));
  259. return;
  260. }
  261. length -= sizeof(*ap);
  262. switch (ap->control & 0xc0) {
  263. case atpReqCode:
  264. ND_PRINT((ndo, " atp-req%s %d",
  265. ap->control & atpXO? " " : "*",
  266. EXTRACT_16BITS(&ap->transID)));
  267. atp_bitmap_print(ndo, ap->bitmap);
  268. if (length != 0)
  269. ND_PRINT((ndo, " [len=%u]", length));
  270. switch (ap->control & (atpEOM|atpSTS)) {
  271. case atpEOM:
  272. ND_PRINT((ndo, " [EOM]"));
  273. break;
  274. case atpSTS:
  275. ND_PRINT((ndo, " [STS]"));
  276. break;
  277. case atpEOM|atpSTS:
  278. ND_PRINT((ndo, " [EOM,STS]"));
  279. break;
  280. }
  281. break;
  282. case atpRspCode:
  283. ND_PRINT((ndo, " atp-resp%s%d:%d (%u)",
  284. ap->control & atpEOM? "*" : " ",
  285. EXTRACT_16BITS(&ap->transID), ap->bitmap, length));
  286. switch (ap->control & (atpXO|atpSTS)) {
  287. case atpXO:
  288. ND_PRINT((ndo, " [XO]"));
  289. break;
  290. case atpSTS:
  291. ND_PRINT((ndo, " [STS]"));
  292. break;
  293. case atpXO|atpSTS:
  294. ND_PRINT((ndo, " [XO,STS]"));
  295. break;
  296. }
  297. break;
  298. case atpRelCode:
  299. ND_PRINT((ndo, " atp-rel %d", EXTRACT_16BITS(&ap->transID)));
  300. atp_bitmap_print(ndo, ap->bitmap);
  301. /* length should be zero */
  302. if (length)
  303. ND_PRINT((ndo, " [len=%u]", length));
  304. /* there shouldn't be any control flags */
  305. if (ap->control & (atpXO|atpEOM|atpSTS)) {
  306. c = '[';
  307. if (ap->control & atpXO) {
  308. ND_PRINT((ndo, "%cXO", c));
  309. c = ',';
  310. }
  311. if (ap->control & atpEOM) {
  312. ND_PRINT((ndo, "%cEOM", c));
  313. c = ',';
  314. }
  315. if (ap->control & atpSTS) {
  316. ND_PRINT((ndo, "%cSTS", c));
  317. c = ',';
  318. }
  319. ND_PRINT((ndo, "]"));
  320. }
  321. break;
  322. default:
  323. ND_PRINT((ndo, " atp-0x%x %d (%u)", ap->control,
  324. EXTRACT_16BITS(&ap->transID), length));
  325. break;
  326. }
  327. data = EXTRACT_32BITS(&ap->userData);
  328. if (data != 0)
  329. ND_PRINT((ndo, " 0x%x", data));
  330. }
  331. static void
  332. atp_bitmap_print(netdissect_options *ndo,
  333. register u_char bm)
  334. {
  335. register char c;
  336. register int i;
  337. /*
  338. * The '& 0xff' below is needed for compilers that want to sign
  339. * extend a u_char, which is the case with the Ultrix compiler.
  340. * (gcc is smart enough to eliminate it, at least on the Sparc).
  341. */
  342. if ((bm + 1) & (bm & 0xff)) {
  343. c = '<';
  344. for (i = 0; bm; ++i) {
  345. if (bm & 1) {
  346. ND_PRINT((ndo, "%c%d", c, i));
  347. c = ',';
  348. }
  349. bm >>= 1;
  350. }
  351. ND_PRINT((ndo, ">"));
  352. } else {
  353. for (i = 0; bm; ++i)
  354. bm >>= 1;
  355. if (i > 1)
  356. ND_PRINT((ndo, "<0-%d>", i - 1));
  357. else
  358. ND_PRINT((ndo, "<0>"));
  359. }
  360. }
  361. static void
  362. nbp_print(netdissect_options *ndo,
  363. register const struct atNBP *np, u_int length, register u_short snet,
  364. register u_char snode, register u_char skt)
  365. {
  366. register const struct atNBPtuple *tp =
  367. (const struct atNBPtuple *)((const u_char *)np + nbpHeaderSize);
  368. int i;
  369. const u_char *ep;
  370. if (length < nbpHeaderSize) {
  371. ND_PRINT((ndo, " truncated-nbp %u", length));
  372. return;
  373. }
  374. length -= nbpHeaderSize;
  375. if (length < 8) {
  376. /* must be room for at least one tuple */
  377. ND_PRINT((ndo, " truncated-nbp %u", length + nbpHeaderSize));
  378. return;
  379. }
  380. /* ep points to end of available data */
  381. ep = ndo->ndo_snapend;
  382. if ((const u_char *)tp > ep) {
  383. ND_PRINT((ndo, "%s", tstr));
  384. return;
  385. }
  386. switch (i = np->control & 0xf0) {
  387. case nbpBrRq:
  388. case nbpLkUp:
  389. ND_PRINT((ndo, i == nbpLkUp? " nbp-lkup %d:":" nbp-brRq %d:", np->id));
  390. if ((const u_char *)(tp + 1) > ep) {
  391. ND_PRINT((ndo, "%s", tstr));
  392. return;
  393. }
  394. (void)nbp_name_print(ndo, tp, ep);
  395. /*
  396. * look for anomalies: the spec says there can only
  397. * be one tuple, the address must match the source
  398. * address and the enumerator should be zero.
  399. */
  400. if ((np->control & 0xf) != 1)
  401. ND_PRINT((ndo, " [ntup=%d]", np->control & 0xf));
  402. if (tp->enumerator)
  403. ND_PRINT((ndo, " [enum=%d]", tp->enumerator));
  404. if (EXTRACT_16BITS(&tp->net) != snet ||
  405. tp->node != snode || tp->skt != skt)
  406. ND_PRINT((ndo, " [addr=%s.%d]",
  407. ataddr_string(ndo, EXTRACT_16BITS(&tp->net),
  408. tp->node), tp->skt));
  409. break;
  410. case nbpLkUpReply:
  411. ND_PRINT((ndo, " nbp-reply %d:", np->id));
  412. /* print each of the tuples in the reply */
  413. for (i = np->control & 0xf; --i >= 0 && tp; )
  414. tp = nbp_tuple_print(ndo, tp, ep, snet, snode, skt);
  415. break;
  416. default:
  417. ND_PRINT((ndo, " nbp-0x%x %d (%u)", np->control, np->id, length));
  418. break;
  419. }
  420. }
  421. /* print a counted string */
  422. static const char *
  423. print_cstring(netdissect_options *ndo,
  424. register const char *cp, register const u_char *ep)
  425. {
  426. register u_int length;
  427. if (cp >= (const char *)ep) {
  428. ND_PRINT((ndo, "%s", tstr));
  429. return (0);
  430. }
  431. length = *cp++;
  432. /* Spec says string can be at most 32 bytes long */
  433. if (length > 32) {
  434. ND_PRINT((ndo, "[len=%u]", length));
  435. return (0);
  436. }
  437. while ((int)--length >= 0) {
  438. if (cp >= (const char *)ep) {
  439. ND_PRINT((ndo, "%s", tstr));
  440. return (0);
  441. }
  442. ND_PRINT((ndo, "%c", *cp++));
  443. }
  444. return (cp);
  445. }
  446. static const struct atNBPtuple *
  447. nbp_tuple_print(netdissect_options *ndo,
  448. register const struct atNBPtuple *tp, register const u_char *ep,
  449. register u_short snet, register u_char snode, register u_char skt)
  450. {
  451. register const struct atNBPtuple *tpn;
  452. if ((const u_char *)(tp + 1) > ep) {
  453. ND_PRINT((ndo, "%s", tstr));
  454. return 0;
  455. }
  456. tpn = nbp_name_print(ndo, tp, ep);
  457. /* if the enumerator isn't 1, print it */
  458. if (tp->enumerator != 1)
  459. ND_PRINT((ndo, "(%d)", tp->enumerator));
  460. /* if the socket doesn't match the src socket, print it */
  461. if (tp->skt != skt)
  462. ND_PRINT((ndo, " %d", tp->skt));
  463. /* if the address doesn't match the src address, it's an anomaly */
  464. if (EXTRACT_16BITS(&tp->net) != snet || tp->node != snode)
  465. ND_PRINT((ndo, " [addr=%s]",
  466. ataddr_string(ndo, EXTRACT_16BITS(&tp->net), tp->node)));
  467. return (tpn);
  468. }
  469. static const struct atNBPtuple *
  470. nbp_name_print(netdissect_options *ndo,
  471. const struct atNBPtuple *tp, register const u_char *ep)
  472. {
  473. register const char *cp = (const char *)tp + nbpTupleSize;
  474. ND_PRINT((ndo, " "));
  475. /* Object */
  476. ND_PRINT((ndo, "\""));
  477. if ((cp = print_cstring(ndo, cp, ep)) != NULL) {
  478. /* Type */
  479. ND_PRINT((ndo, ":"));
  480. if ((cp = print_cstring(ndo, cp, ep)) != NULL) {
  481. /* Zone */
  482. ND_PRINT((ndo, "@"));
  483. if ((cp = print_cstring(ndo, cp, ep)) != NULL)
  484. ND_PRINT((ndo, "\""));
  485. }
  486. }
  487. return ((const struct atNBPtuple *)cp);
  488. }
  489. #define HASHNAMESIZE 4096
  490. struct hnamemem {
  491. int addr;
  492. char *name;
  493. struct hnamemem *nxt;
  494. };
  495. static struct hnamemem hnametable[HASHNAMESIZE];
  496. static const char *
  497. ataddr_string(netdissect_options *ndo,
  498. u_short atnet, u_char athost)
  499. {
  500. register struct hnamemem *tp, *tp2;
  501. register int i = (atnet << 8) | athost;
  502. char nambuf[256+1];
  503. static int first = 1;
  504. FILE *fp;
  505. /*
  506. * if this is the first call, see if there's an AppleTalk
  507. * number to name map file.
  508. */
  509. if (first && (first = 0, !ndo->ndo_nflag)
  510. && (fp = fopen("/etc/atalk.names", "r"))) {
  511. char line[256];
  512. int i1, i2;
  513. while (fgets(line, sizeof(line), fp)) {
  514. if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
  515. continue;
  516. if (sscanf(line, "%d.%d %256s", &i1, &i2, nambuf) == 3)
  517. /* got a hostname. */
  518. i2 |= (i1 << 8);
  519. else if (sscanf(line, "%d %256s", &i1, nambuf) == 2)
  520. /* got a net name */
  521. i2 = (i1 << 8) | 255;
  522. else
  523. continue;
  524. for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
  525. tp->nxt; tp = tp->nxt)
  526. ;
  527. tp->addr = i2;
  528. tp->nxt = newhnamemem(ndo);
  529. tp->name = strdup(nambuf);
  530. if (tp->name == NULL)
  531. (*ndo->ndo_error)(ndo,
  532. "ataddr_string: strdup(nambuf)");
  533. }
  534. fclose(fp);
  535. }
  536. for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
  537. if (tp->addr == i)
  538. return (tp->name);
  539. /* didn't have the node name -- see if we've got the net name */
  540. i |= 255;
  541. for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt)
  542. if (tp2->addr == i) {
  543. tp->addr = (atnet << 8) | athost;
  544. tp->nxt = newhnamemem(ndo);
  545. (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
  546. tp2->name, athost);
  547. tp->name = strdup(nambuf);
  548. if (tp->name == NULL)
  549. (*ndo->ndo_error)(ndo,
  550. "ataddr_string: strdup(nambuf)");
  551. return (tp->name);
  552. }
  553. tp->addr = (atnet << 8) | athost;
  554. tp->nxt = newhnamemem(ndo);
  555. if (athost != 255)
  556. (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet, athost);
  557. else
  558. (void)snprintf(nambuf, sizeof(nambuf), "%d", atnet);
  559. tp->name = strdup(nambuf);
  560. if (tp->name == NULL)
  561. (*ndo->ndo_error)(ndo, "ataddr_string: strdup(nambuf)");
  562. return (tp->name);
  563. }
  564. static const struct tok skt2str[] = {
  565. { rtmpSkt, "rtmp" }, /* routing table maintenance */
  566. { nbpSkt, "nis" }, /* name info socket */
  567. { echoSkt, "echo" }, /* AppleTalk echo protocol */
  568. { zipSkt, "zip" }, /* zone info protocol */
  569. { 0, NULL }
  570. };
  571. static const char *
  572. ddpskt_string(netdissect_options *ndo,
  573. register int skt)
  574. {
  575. static char buf[8];
  576. if (ndo->ndo_nflag) {
  577. (void)snprintf(buf, sizeof(buf), "%d", skt);
  578. return (buf);
  579. }
  580. return (tok2str(skt2str, "%d", skt));
  581. }