addrtoname.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*
  2. * Copyright (c) 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. * Internet, ethernet, port, and protocol string to address
  22. * and address to string conversion routines
  23. */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include <netdissect-stdinc.h>
  28. #ifdef USE_ETHER_NTOHOST
  29. #ifdef HAVE_NETINET_IF_ETHER_H
  30. struct mbuf; /* Squelch compiler warnings on some platforms for */
  31. struct rtentry; /* declarations in <net/if.h> */
  32. #include <net/if.h> /* for "struct ifnet" in "struct arpcom" on Solaris */
  33. #include <netinet/if_ether.h>
  34. #endif /* HAVE_NETINET_IF_ETHER_H */
  35. #ifdef NETINET_ETHER_H_DECLARES_ETHER_NTOHOST
  36. #include <netinet/ether.h>
  37. #endif /* NETINET_ETHER_H_DECLARES_ETHER_NTOHOST */
  38. #if !defined(HAVE_DECL_ETHER_NTOHOST) || !HAVE_DECL_ETHER_NTOHOST
  39. #ifndef HAVE_STRUCT_ETHER_ADDR
  40. struct ether_addr {
  41. unsigned char ether_addr_octet[6];
  42. };
  43. #endif
  44. extern int ether_ntohost(char *, const struct ether_addr *);
  45. #endif
  46. #endif /* USE_ETHER_NTOHOST */
  47. #include <pcap.h>
  48. #include <pcap-namedb.h>
  49. #include <signal.h>
  50. #include <stdio.h>
  51. #include <string.h>
  52. #include <stdlib.h>
  53. #include "netdissect.h"
  54. #include "addrtoname.h"
  55. #include "addrtostr.h"
  56. #include "ethertype.h"
  57. #include "llc.h"
  58. #include "setsignal.h"
  59. #include "extract.h"
  60. #include "oui.h"
  61. #ifndef ETHER_ADDR_LEN
  62. #define ETHER_ADDR_LEN 6
  63. #endif
  64. /*
  65. * hash tables for whatever-to-name translations
  66. *
  67. * ndo_error() called on strdup(3) failure
  68. */
  69. #define HASHNAMESIZE 4096
  70. struct hnamemem {
  71. uint32_t addr;
  72. const char *name;
  73. struct hnamemem *nxt;
  74. };
  75. static struct hnamemem hnametable[HASHNAMESIZE];
  76. static struct hnamemem tporttable[HASHNAMESIZE];
  77. static struct hnamemem uporttable[HASHNAMESIZE];
  78. static struct hnamemem eprototable[HASHNAMESIZE];
  79. static struct hnamemem dnaddrtable[HASHNAMESIZE];
  80. static struct hnamemem ipxsaptable[HASHNAMESIZE];
  81. #ifdef _WIN32
  82. /*
  83. * fake gethostbyaddr for Win2k/XP
  84. * gethostbyaddr() returns incorrect value when AF_INET6 is passed
  85. * to 3rd argument.
  86. *
  87. * h_name in struct hostent is only valid.
  88. */
  89. static struct hostent *
  90. win32_gethostbyaddr(const char *addr, int len, int type)
  91. {
  92. static struct hostent host;
  93. static char hostbuf[NI_MAXHOST];
  94. char hname[NI_MAXHOST];
  95. struct sockaddr_in6 addr6;
  96. host.h_name = hostbuf;
  97. switch (type) {
  98. case AF_INET:
  99. return gethostbyaddr(addr, len, type);
  100. break;
  101. case AF_INET6:
  102. memset(&addr6, 0, sizeof(addr6));
  103. addr6.sin6_family = AF_INET6;
  104. memcpy(&addr6.sin6_addr, addr, len);
  105. if (getnameinfo((struct sockaddr *)&addr6, sizeof(addr6),
  106. hname, sizeof(hname), NULL, 0, 0)) {
  107. return NULL;
  108. } else {
  109. strcpy(host.h_name, hname);
  110. return &host;
  111. }
  112. break;
  113. default:
  114. return NULL;
  115. }
  116. }
  117. #define gethostbyaddr win32_gethostbyaddr
  118. #endif /* _WIN32 */
  119. struct h6namemem {
  120. struct in6_addr addr;
  121. char *name;
  122. struct h6namemem *nxt;
  123. };
  124. static struct h6namemem h6nametable[HASHNAMESIZE];
  125. struct enamemem {
  126. u_short e_addr0;
  127. u_short e_addr1;
  128. u_short e_addr2;
  129. const char *e_name;
  130. u_char *e_nsap; /* used only for nsaptable[] */
  131. struct enamemem *e_nxt;
  132. };
  133. static struct enamemem enametable[HASHNAMESIZE];
  134. static struct enamemem nsaptable[HASHNAMESIZE];
  135. struct bsnamemem {
  136. u_short bs_addr0;
  137. u_short bs_addr1;
  138. u_short bs_addr2;
  139. const char *bs_name;
  140. u_char *bs_bytes;
  141. unsigned int bs_nbytes;
  142. struct bsnamemem *bs_nxt;
  143. };
  144. static struct bsnamemem bytestringtable[HASHNAMESIZE];
  145. struct protoidmem {
  146. uint32_t p_oui;
  147. u_short p_proto;
  148. const char *p_name;
  149. struct protoidmem *p_nxt;
  150. };
  151. static struct protoidmem protoidtable[HASHNAMESIZE];
  152. /*
  153. * A faster replacement for inet_ntoa().
  154. */
  155. const char *
  156. intoa(uint32_t addr)
  157. {
  158. register char *cp;
  159. register u_int byte;
  160. register int n;
  161. static char buf[sizeof(".xxx.xxx.xxx.xxx")];
  162. NTOHL(addr);
  163. cp = buf + sizeof(buf);
  164. *--cp = '\0';
  165. n = 4;
  166. do {
  167. byte = addr & 0xff;
  168. *--cp = byte % 10 + '0';
  169. byte /= 10;
  170. if (byte > 0) {
  171. *--cp = byte % 10 + '0';
  172. byte /= 10;
  173. if (byte > 0)
  174. *--cp = byte + '0';
  175. }
  176. *--cp = '.';
  177. addr >>= 8;
  178. } while (--n > 0);
  179. return cp + 1;
  180. }
  181. static uint32_t f_netmask;
  182. static uint32_t f_localnet;
  183. /*
  184. * Return a name for the IP address pointed to by ap. This address
  185. * is assumed to be in network byte order.
  186. *
  187. * NOTE: ap is *NOT* necessarily part of the packet data (not even if
  188. * this is being called with the "ipaddr_string()" macro), so you
  189. * *CANNOT* use the ND_TCHECK{2}/ND_TTEST{2} macros on it. Furthermore,
  190. * even in cases where it *is* part of the packet data, the caller
  191. * would still have to check for a null return value, even if it's
  192. * just printing the return value with "%s" - not all versions of
  193. * printf print "(null)" with "%s" and a null pointer, some of them
  194. * don't check for a null pointer and crash in that case.
  195. *
  196. * The callers of this routine should, before handing this routine
  197. * a pointer to packet data, be sure that the data is present in
  198. * the packet buffer. They should probably do those checks anyway,
  199. * as other data at that layer might not be IP addresses, and it
  200. * also needs to check whether they're present in the packet buffer.
  201. */
  202. const char *
  203. getname(netdissect_options *ndo, const u_char *ap)
  204. {
  205. register struct hostent *hp;
  206. uint32_t addr;
  207. struct hnamemem *p;
  208. memcpy(&addr, ap, sizeof(addr));
  209. p = &hnametable[addr & (HASHNAMESIZE-1)];
  210. for (; p->nxt; p = p->nxt) {
  211. if (p->addr == addr)
  212. return (p->name);
  213. }
  214. p->addr = addr;
  215. p->nxt = newhnamemem(ndo);
  216. /*
  217. * Print names unless:
  218. * (1) -n was given.
  219. * (2) Address is foreign and -f was given. (If -f was not
  220. * given, f_netmask and f_localnet are 0 and the test
  221. * evaluates to true)
  222. */
  223. if (!ndo->ndo_nflag &&
  224. (addr & f_netmask) == f_localnet) {
  225. hp = gethostbyaddr((char *)&addr, 4, AF_INET);
  226. if (hp) {
  227. char *dotp;
  228. p->name = strdup(hp->h_name);
  229. if (p->name == NULL)
  230. (*ndo->ndo_error)(ndo,
  231. "getname: strdup(hp->h_name)");
  232. if (ndo->ndo_Nflag) {
  233. /* Remove domain qualifications */
  234. dotp = strchr(p->name, '.');
  235. if (dotp)
  236. *dotp = '\0';
  237. }
  238. return (p->name);
  239. }
  240. }
  241. p->name = strdup(intoa(addr));
  242. if (p->name == NULL)
  243. (*ndo->ndo_error)(ndo, "getname: strdup(intoa(addr))");
  244. return (p->name);
  245. }
  246. /*
  247. * Return a name for the IP6 address pointed to by ap. This address
  248. * is assumed to be in network byte order.
  249. */
  250. const char *
  251. getname6(netdissect_options *ndo, const u_char *ap)
  252. {
  253. register struct hostent *hp;
  254. union {
  255. struct in6_addr addr;
  256. struct for_hash_addr {
  257. char fill[14];
  258. uint16_t d;
  259. } addra;
  260. } addr;
  261. struct h6namemem *p;
  262. register const char *cp;
  263. char ntop_buf[INET6_ADDRSTRLEN];
  264. memcpy(&addr, ap, sizeof(addr));
  265. p = &h6nametable[addr.addra.d & (HASHNAMESIZE-1)];
  266. for (; p->nxt; p = p->nxt) {
  267. if (memcmp(&p->addr, &addr, sizeof(addr)) == 0)
  268. return (p->name);
  269. }
  270. p->addr = addr.addr;
  271. p->nxt = newh6namemem(ndo);
  272. /*
  273. * Do not print names if -n was given.
  274. */
  275. if (!ndo->ndo_nflag) {
  276. hp = gethostbyaddr((char *)&addr, sizeof(addr), AF_INET6);
  277. if (hp) {
  278. char *dotp;
  279. p->name = strdup(hp->h_name);
  280. if (p->name == NULL)
  281. (*ndo->ndo_error)(ndo,
  282. "getname6: strdup(hp->h_name)");
  283. if (ndo->ndo_Nflag) {
  284. /* Remove domain qualifications */
  285. dotp = strchr(p->name, '.');
  286. if (dotp)
  287. *dotp = '\0';
  288. }
  289. return (p->name);
  290. }
  291. }
  292. cp = addrtostr6(ap, ntop_buf, sizeof(ntop_buf));
  293. p->name = strdup(cp);
  294. if (p->name == NULL)
  295. (*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
  296. return (p->name);
  297. }
  298. static const char hex[16] = "0123456789abcdef";
  299. /* Find the hash node that corresponds the ether address 'ep' */
  300. static inline struct enamemem *
  301. lookup_emem(netdissect_options *ndo, const u_char *ep)
  302. {
  303. register u_int i, j, k;
  304. struct enamemem *tp;
  305. k = (ep[0] << 8) | ep[1];
  306. j = (ep[2] << 8) | ep[3];
  307. i = (ep[4] << 8) | ep[5];
  308. tp = &enametable[(i ^ j) & (HASHNAMESIZE-1)];
  309. while (tp->e_nxt)
  310. if (tp->e_addr0 == i &&
  311. tp->e_addr1 == j &&
  312. tp->e_addr2 == k)
  313. return tp;
  314. else
  315. tp = tp->e_nxt;
  316. tp->e_addr0 = i;
  317. tp->e_addr1 = j;
  318. tp->e_addr2 = k;
  319. tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
  320. if (tp->e_nxt == NULL)
  321. (*ndo->ndo_error)(ndo, "lookup_emem: calloc");
  322. return tp;
  323. }
  324. /*
  325. * Find the hash node that corresponds to the bytestring 'bs'
  326. * with length 'nlen'
  327. */
  328. static inline struct bsnamemem *
  329. lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
  330. const unsigned int nlen)
  331. {
  332. struct bsnamemem *tp;
  333. register u_int i, j, k;
  334. if (nlen >= 6) {
  335. k = (bs[0] << 8) | bs[1];
  336. j = (bs[2] << 8) | bs[3];
  337. i = (bs[4] << 8) | bs[5];
  338. } else if (nlen >= 4) {
  339. k = (bs[0] << 8) | bs[1];
  340. j = (bs[2] << 8) | bs[3];
  341. i = 0;
  342. } else
  343. i = j = k = 0;
  344. tp = &bytestringtable[(i ^ j) & (HASHNAMESIZE-1)];
  345. while (tp->bs_nxt)
  346. if (nlen == tp->bs_nbytes &&
  347. tp->bs_addr0 == i &&
  348. tp->bs_addr1 == j &&
  349. tp->bs_addr2 == k &&
  350. memcmp((const char *)bs, (const char *)(tp->bs_bytes), nlen) == 0)
  351. return tp;
  352. else
  353. tp = tp->bs_nxt;
  354. tp->bs_addr0 = i;
  355. tp->bs_addr1 = j;
  356. tp->bs_addr2 = k;
  357. tp->bs_bytes = (u_char *) calloc(1, nlen);
  358. if (tp->bs_bytes == NULL)
  359. (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
  360. memcpy(tp->bs_bytes, bs, nlen);
  361. tp->bs_nbytes = nlen;
  362. tp->bs_nxt = (struct bsnamemem *)calloc(1, sizeof(*tp));
  363. if (tp->bs_nxt == NULL)
  364. (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
  365. return tp;
  366. }
  367. /* Find the hash node that corresponds the NSAP 'nsap' */
  368. static inline struct enamemem *
  369. lookup_nsap(netdissect_options *ndo, register const u_char *nsap,
  370. register u_int nsap_length)
  371. {
  372. register u_int i, j, k;
  373. struct enamemem *tp;
  374. const u_char *ensap;
  375. if (nsap_length > 6) {
  376. ensap = nsap + nsap_length - 6;
  377. k = (ensap[0] << 8) | ensap[1];
  378. j = (ensap[2] << 8) | ensap[3];
  379. i = (ensap[4] << 8) | ensap[5];
  380. }
  381. else
  382. i = j = k = 0;
  383. tp = &nsaptable[(i ^ j) & (HASHNAMESIZE-1)];
  384. while (tp->e_nxt)
  385. if (nsap_length == tp->e_nsap[0] &&
  386. tp->e_addr0 == i &&
  387. tp->e_addr1 == j &&
  388. tp->e_addr2 == k &&
  389. memcmp((const char *)nsap,
  390. (char *)&(tp->e_nsap[1]), nsap_length) == 0)
  391. return tp;
  392. else
  393. tp = tp->e_nxt;
  394. tp->e_addr0 = i;
  395. tp->e_addr1 = j;
  396. tp->e_addr2 = k;
  397. tp->e_nsap = (u_char *)malloc(nsap_length + 1);
  398. if (tp->e_nsap == NULL)
  399. (*ndo->ndo_error)(ndo, "lookup_nsap: malloc");
  400. tp->e_nsap[0] = (u_char)nsap_length; /* guaranteed < ISONSAP_MAX_LENGTH */
  401. memcpy((char *)&tp->e_nsap[1], (const char *)nsap, nsap_length);
  402. tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
  403. if (tp->e_nxt == NULL)
  404. (*ndo->ndo_error)(ndo, "lookup_nsap: calloc");
  405. return tp;
  406. }
  407. /* Find the hash node that corresponds the protoid 'pi'. */
  408. static inline struct protoidmem *
  409. lookup_protoid(netdissect_options *ndo, const u_char *pi)
  410. {
  411. register u_int i, j;
  412. struct protoidmem *tp;
  413. /* 5 octets won't be aligned */
  414. i = (((pi[0] << 8) + pi[1]) << 8) + pi[2];
  415. j = (pi[3] << 8) + pi[4];
  416. /* XXX should be endian-insensitive, but do big-endian testing XXX */
  417. tp = &protoidtable[(i ^ j) & (HASHNAMESIZE-1)];
  418. while (tp->p_nxt)
  419. if (tp->p_oui == i && tp->p_proto == j)
  420. return tp;
  421. else
  422. tp = tp->p_nxt;
  423. tp->p_oui = i;
  424. tp->p_proto = j;
  425. tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
  426. if (tp->p_nxt == NULL)
  427. (*ndo->ndo_error)(ndo, "lookup_protoid: calloc");
  428. return tp;
  429. }
  430. const char *
  431. etheraddr_string(netdissect_options *ndo, register const u_char *ep)
  432. {
  433. register int i;
  434. register char *cp;
  435. register struct enamemem *tp;
  436. int oui;
  437. char buf[BUFSIZE];
  438. tp = lookup_emem(ndo, ep);
  439. if (tp->e_name)
  440. return (tp->e_name);
  441. #ifdef USE_ETHER_NTOHOST
  442. if (!ndo->ndo_nflag) {
  443. char buf2[BUFSIZE];
  444. if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
  445. tp->e_name = strdup(buf2);
  446. if (tp->e_name == NULL)
  447. (*ndo->ndo_error)(ndo,
  448. "etheraddr_string: strdup(buf2)");
  449. return (tp->e_name);
  450. }
  451. }
  452. #endif
  453. cp = buf;
  454. oui = EXTRACT_24BITS(ep);
  455. *cp++ = hex[*ep >> 4 ];
  456. *cp++ = hex[*ep++ & 0xf];
  457. for (i = 5; --i >= 0;) {
  458. *cp++ = ':';
  459. *cp++ = hex[*ep >> 4 ];
  460. *cp++ = hex[*ep++ & 0xf];
  461. }
  462. if (!ndo->ndo_nflag) {
  463. snprintf(cp, BUFSIZE - (2 + 5*3), " (oui %s)",
  464. tok2str(oui_values, "Unknown", oui));
  465. } else
  466. *cp = '\0';
  467. tp->e_name = strdup(buf);
  468. if (tp->e_name == NULL)
  469. (*ndo->ndo_error)(ndo, "etheraddr_string: strdup(buf)");
  470. return (tp->e_name);
  471. }
  472. const char *
  473. le64addr_string(netdissect_options *ndo, const u_char *ep)
  474. {
  475. const unsigned int len = 8;
  476. register u_int i;
  477. register char *cp;
  478. register struct bsnamemem *tp;
  479. char buf[BUFSIZE];
  480. tp = lookup_bytestring(ndo, ep, len);
  481. if (tp->bs_name)
  482. return (tp->bs_name);
  483. cp = buf;
  484. for (i = len; i > 0 ; --i) {
  485. *cp++ = hex[*(ep + i - 1) >> 4];
  486. *cp++ = hex[*(ep + i - 1) & 0xf];
  487. *cp++ = ':';
  488. }
  489. cp --;
  490. *cp = '\0';
  491. tp->bs_name = strdup(buf);
  492. if (tp->bs_name == NULL)
  493. (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
  494. return (tp->bs_name);
  495. }
  496. const char *
  497. linkaddr_string(netdissect_options *ndo, const u_char *ep,
  498. const unsigned int type, const unsigned int len)
  499. {
  500. register u_int i;
  501. register char *cp;
  502. register struct bsnamemem *tp;
  503. if (len == 0)
  504. return ("<empty>");
  505. if (type == LINKADDR_ETHER && len == ETHER_ADDR_LEN)
  506. return (etheraddr_string(ndo, ep));
  507. if (type == LINKADDR_FRELAY)
  508. return (q922_string(ndo, ep, len));
  509. tp = lookup_bytestring(ndo, ep, len);
  510. if (tp->bs_name)
  511. return (tp->bs_name);
  512. tp->bs_name = cp = (char *)malloc(len*3);
  513. if (tp->bs_name == NULL)
  514. (*ndo->ndo_error)(ndo, "linkaddr_string: malloc");
  515. *cp++ = hex[*ep >> 4];
  516. *cp++ = hex[*ep++ & 0xf];
  517. for (i = len-1; i > 0 ; --i) {
  518. *cp++ = ':';
  519. *cp++ = hex[*ep >> 4];
  520. *cp++ = hex[*ep++ & 0xf];
  521. }
  522. *cp = '\0';
  523. return (tp->bs_name);
  524. }
  525. const char *
  526. etherproto_string(netdissect_options *ndo, u_short port)
  527. {
  528. register char *cp;
  529. register struct hnamemem *tp;
  530. register uint32_t i = port;
  531. char buf[sizeof("0000")];
  532. for (tp = &eprototable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
  533. if (tp->addr == i)
  534. return (tp->name);
  535. tp->addr = i;
  536. tp->nxt = newhnamemem(ndo);
  537. cp = buf;
  538. NTOHS(port);
  539. *cp++ = hex[port >> 12 & 0xf];
  540. *cp++ = hex[port >> 8 & 0xf];
  541. *cp++ = hex[port >> 4 & 0xf];
  542. *cp++ = hex[port & 0xf];
  543. *cp++ = '\0';
  544. tp->name = strdup(buf);
  545. if (tp->name == NULL)
  546. (*ndo->ndo_error)(ndo, "etherproto_string: strdup(buf)");
  547. return (tp->name);
  548. }
  549. const char *
  550. protoid_string(netdissect_options *ndo, register const u_char *pi)
  551. {
  552. register u_int i, j;
  553. register char *cp;
  554. register struct protoidmem *tp;
  555. char buf[sizeof("00:00:00:00:00")];
  556. tp = lookup_protoid(ndo, pi);
  557. if (tp->p_name)
  558. return tp->p_name;
  559. cp = buf;
  560. if ((j = *pi >> 4) != 0)
  561. *cp++ = hex[j];
  562. *cp++ = hex[*pi++ & 0xf];
  563. for (i = 4; (int)--i >= 0;) {
  564. *cp++ = ':';
  565. if ((j = *pi >> 4) != 0)
  566. *cp++ = hex[j];
  567. *cp++ = hex[*pi++ & 0xf];
  568. }
  569. *cp = '\0';
  570. tp->p_name = strdup(buf);
  571. if (tp->p_name == NULL)
  572. (*ndo->ndo_error)(ndo, "protoid_string: strdup(buf)");
  573. return (tp->p_name);
  574. }
  575. #define ISONSAP_MAX_LENGTH 20
  576. const char *
  577. isonsap_string(netdissect_options *ndo, const u_char *nsap,
  578. register u_int nsap_length)
  579. {
  580. register u_int nsap_idx;
  581. register char *cp;
  582. register struct enamemem *tp;
  583. if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
  584. return ("isonsap_string: illegal length");
  585. tp = lookup_nsap(ndo, nsap, nsap_length);
  586. if (tp->e_name)
  587. return tp->e_name;
  588. tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
  589. if (cp == NULL)
  590. (*ndo->ndo_error)(ndo, "isonsap_string: malloc");
  591. for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
  592. *cp++ = hex[*nsap >> 4];
  593. *cp++ = hex[*nsap++ & 0xf];
  594. if (((nsap_idx & 1) == 0) &&
  595. (nsap_idx + 1 < nsap_length)) {
  596. *cp++ = '.';
  597. }
  598. }
  599. *cp = '\0';
  600. return (tp->e_name);
  601. }
  602. const char *
  603. tcpport_string(netdissect_options *ndo, u_short port)
  604. {
  605. register struct hnamemem *tp;
  606. register uint32_t i = port;
  607. char buf[sizeof("00000")];
  608. for (tp = &tporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
  609. if (tp->addr == i)
  610. return (tp->name);
  611. tp->addr = i;
  612. tp->nxt = newhnamemem(ndo);
  613. (void)snprintf(buf, sizeof(buf), "%u", i);
  614. tp->name = strdup(buf);
  615. if (tp->name == NULL)
  616. (*ndo->ndo_error)(ndo, "tcpport_string: strdup(buf)");
  617. return (tp->name);
  618. }
  619. const char *
  620. udpport_string(netdissect_options *ndo, register u_short port)
  621. {
  622. register struct hnamemem *tp;
  623. register uint32_t i = port;
  624. char buf[sizeof("00000")];
  625. for (tp = &uporttable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
  626. if (tp->addr == i)
  627. return (tp->name);
  628. tp->addr = i;
  629. tp->nxt = newhnamemem(ndo);
  630. (void)snprintf(buf, sizeof(buf), "%u", i);
  631. tp->name = strdup(buf);
  632. if (tp->name == NULL)
  633. (*ndo->ndo_error)(ndo, "udpport_string: strdup(buf)");
  634. return (tp->name);
  635. }
  636. const char *
  637. ipxsap_string(netdissect_options *ndo, u_short port)
  638. {
  639. register char *cp;
  640. register struct hnamemem *tp;
  641. register uint32_t i = port;
  642. char buf[sizeof("0000")];
  643. for (tp = &ipxsaptable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
  644. if (tp->addr == i)
  645. return (tp->name);
  646. tp->addr = i;
  647. tp->nxt = newhnamemem(ndo);
  648. cp = buf;
  649. NTOHS(port);
  650. *cp++ = hex[port >> 12 & 0xf];
  651. *cp++ = hex[port >> 8 & 0xf];
  652. *cp++ = hex[port >> 4 & 0xf];
  653. *cp++ = hex[port & 0xf];
  654. *cp++ = '\0';
  655. tp->name = strdup(buf);
  656. if (tp->name == NULL)
  657. (*ndo->ndo_error)(ndo, "ipxsap_string: strdup(buf)");
  658. return (tp->name);
  659. }
  660. static void
  661. init_servarray(netdissect_options *ndo)
  662. {
  663. struct servent *sv;
  664. register struct hnamemem *table;
  665. register int i;
  666. char buf[sizeof("0000000000")];
  667. while ((sv = getservent()) != NULL) {
  668. int port = ntohs(sv->s_port);
  669. i = port & (HASHNAMESIZE-1);
  670. if (strcmp(sv->s_proto, "tcp") == 0)
  671. table = &tporttable[i];
  672. else if (strcmp(sv->s_proto, "udp") == 0)
  673. table = &uporttable[i];
  674. else
  675. continue;
  676. while (table->name)
  677. table = table->nxt;
  678. if (ndo->ndo_nflag) {
  679. (void)snprintf(buf, sizeof(buf), "%d", port);
  680. table->name = strdup(buf);
  681. } else
  682. table->name = strdup(sv->s_name);
  683. if (table->name == NULL)
  684. (*ndo->ndo_error)(ndo, "init_servarray: strdup");
  685. table->addr = port;
  686. table->nxt = newhnamemem(ndo);
  687. }
  688. endservent();
  689. }
  690. static const struct eproto {
  691. const char *s;
  692. u_short p;
  693. } eproto_db[] = {
  694. { "pup", ETHERTYPE_PUP },
  695. { "xns", ETHERTYPE_NS },
  696. { "ip", ETHERTYPE_IP },
  697. { "ip6", ETHERTYPE_IPV6 },
  698. { "arp", ETHERTYPE_ARP },
  699. { "rarp", ETHERTYPE_REVARP },
  700. { "sprite", ETHERTYPE_SPRITE },
  701. { "mopdl", ETHERTYPE_MOPDL },
  702. { "moprc", ETHERTYPE_MOPRC },
  703. { "decnet", ETHERTYPE_DN },
  704. { "lat", ETHERTYPE_LAT },
  705. { "sca", ETHERTYPE_SCA },
  706. { "lanbridge", ETHERTYPE_LANBRIDGE },
  707. { "vexp", ETHERTYPE_VEXP },
  708. { "vprod", ETHERTYPE_VPROD },
  709. { "atalk", ETHERTYPE_ATALK },
  710. { "atalkarp", ETHERTYPE_AARP },
  711. { "loopback", ETHERTYPE_LOOPBACK },
  712. { "decdts", ETHERTYPE_DECDTS },
  713. { "decdns", ETHERTYPE_DECDNS },
  714. { (char *)0, 0 }
  715. };
  716. static void
  717. init_eprotoarray(netdissect_options *ndo)
  718. {
  719. register int i;
  720. register struct hnamemem *table;
  721. for (i = 0; eproto_db[i].s; i++) {
  722. int j = htons(eproto_db[i].p) & (HASHNAMESIZE-1);
  723. table = &eprototable[j];
  724. while (table->name)
  725. table = table->nxt;
  726. table->name = eproto_db[i].s;
  727. table->addr = htons(eproto_db[i].p);
  728. table->nxt = newhnamemem(ndo);
  729. }
  730. }
  731. static const struct protoidlist {
  732. const u_char protoid[5];
  733. const char *name;
  734. } protoidlist[] = {
  735. {{ 0x00, 0x00, 0x0c, 0x01, 0x07 }, "CiscoMLS" },
  736. {{ 0x00, 0x00, 0x0c, 0x20, 0x00 }, "CiscoCDP" },
  737. {{ 0x00, 0x00, 0x0c, 0x20, 0x01 }, "CiscoCGMP" },
  738. {{ 0x00, 0x00, 0x0c, 0x20, 0x03 }, "CiscoVTP" },
  739. {{ 0x00, 0xe0, 0x2b, 0x00, 0xbb }, "ExtremeEDP" },
  740. {{ 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
  741. };
  742. /*
  743. * SNAP proto IDs with org code 0:0:0 are actually encapsulated Ethernet
  744. * types.
  745. */
  746. static void
  747. init_protoidarray(netdissect_options *ndo)
  748. {
  749. register int i;
  750. register struct protoidmem *tp;
  751. const struct protoidlist *pl;
  752. u_char protoid[5];
  753. protoid[0] = 0;
  754. protoid[1] = 0;
  755. protoid[2] = 0;
  756. for (i = 0; eproto_db[i].s; i++) {
  757. u_short etype = htons(eproto_db[i].p);
  758. memcpy((char *)&protoid[3], (char *)&etype, 2);
  759. tp = lookup_protoid(ndo, protoid);
  760. tp->p_name = strdup(eproto_db[i].s);
  761. if (tp->p_name == NULL)
  762. (*ndo->ndo_error)(ndo,
  763. "init_protoidarray: strdup(eproto_db[i].s)");
  764. }
  765. /* Hardwire some SNAP proto ID names */
  766. for (pl = protoidlist; pl->name != NULL; ++pl) {
  767. tp = lookup_protoid(ndo, pl->protoid);
  768. /* Don't override existing name */
  769. if (tp->p_name != NULL)
  770. continue;
  771. tp->p_name = pl->name;
  772. }
  773. }
  774. static const struct etherlist {
  775. const u_char addr[6];
  776. const char *name;
  777. } etherlist[] = {
  778. {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, "Broadcast" },
  779. {{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, NULL }
  780. };
  781. /*
  782. * Initialize the ethers hash table. We take two different approaches
  783. * depending on whether or not the system provides the ethers name
  784. * service. If it does, we just wire in a few names at startup,
  785. * and etheraddr_string() fills in the table on demand. If it doesn't,
  786. * then we suck in the entire /etc/ethers file at startup. The idea
  787. * is that parsing the local file will be fast, but spinning through
  788. * all the ethers entries via NIS & next_etherent might be very slow.
  789. *
  790. * XXX pcap_next_etherent doesn't belong in the pcap interface, but
  791. * since the pcap module already does name-to-address translation,
  792. * it's already does most of the work for the ethernet address-to-name
  793. * translation, so we just pcap_next_etherent as a convenience.
  794. */
  795. static void
  796. init_etherarray(netdissect_options *ndo)
  797. {
  798. register const struct etherlist *el;
  799. register struct enamemem *tp;
  800. #ifdef USE_ETHER_NTOHOST
  801. char name[256];
  802. #else
  803. register struct pcap_etherent *ep;
  804. register FILE *fp;
  805. /* Suck in entire ethers file */
  806. fp = fopen(PCAP_ETHERS_FILE, "r");
  807. if (fp != NULL) {
  808. while ((ep = pcap_next_etherent(fp)) != NULL) {
  809. tp = lookup_emem(ndo, ep->addr);
  810. tp->e_name = strdup(ep->name);
  811. if (tp->e_name == NULL)
  812. (*ndo->ndo_error)(ndo,
  813. "init_etherarray: strdup(ep->addr)");
  814. }
  815. (void)fclose(fp);
  816. }
  817. #endif
  818. /* Hardwire some ethernet names */
  819. for (el = etherlist; el->name != NULL; ++el) {
  820. tp = lookup_emem(ndo, el->addr);
  821. /* Don't override existing name */
  822. if (tp->e_name != NULL)
  823. continue;
  824. #ifdef USE_ETHER_NTOHOST
  825. /*
  826. * Use YP/NIS version of name if available.
  827. */
  828. if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
  829. tp->e_name = strdup(name);
  830. if (tp->e_name == NULL)
  831. (*ndo->ndo_error)(ndo,
  832. "init_etherarray: strdup(name)");
  833. continue;
  834. }
  835. #endif
  836. tp->e_name = el->name;
  837. }
  838. }
  839. static const struct tok ipxsap_db[] = {
  840. { 0x0000, "Unknown" },
  841. { 0x0001, "User" },
  842. { 0x0002, "User Group" },
  843. { 0x0003, "PrintQueue" },
  844. { 0x0004, "FileServer" },
  845. { 0x0005, "JobServer" },
  846. { 0x0006, "Gateway" },
  847. { 0x0007, "PrintServer" },
  848. { 0x0008, "ArchiveQueue" },
  849. { 0x0009, "ArchiveServer" },
  850. { 0x000a, "JobQueue" },
  851. { 0x000b, "Administration" },
  852. { 0x000F, "Novell TI-RPC" },
  853. { 0x0017, "Diagnostics" },
  854. { 0x0020, "NetBIOS" },
  855. { 0x0021, "NAS SNA Gateway" },
  856. { 0x0023, "NACS AsyncGateway" },
  857. { 0x0024, "RemoteBridge/RoutingService" },
  858. { 0x0026, "BridgeServer" },
  859. { 0x0027, "TCP/IP Gateway" },
  860. { 0x0028, "Point-to-point X.25 BridgeServer" },
  861. { 0x0029, "3270 Gateway" },
  862. { 0x002a, "CHI Corp" },
  863. { 0x002c, "PC Chalkboard" },
  864. { 0x002d, "TimeSynchServer" },
  865. { 0x002e, "ARCserve5.0/PalindromeBackup" },
  866. { 0x0045, "DI3270 Gateway" },
  867. { 0x0047, "AdvertisingPrintServer" },
  868. { 0x004a, "NetBlazerModems" },
  869. { 0x004b, "BtrieveVAP" },
  870. { 0x004c, "NetwareSQL" },
  871. { 0x004d, "XtreeNetwork" },
  872. { 0x0050, "BtrieveVAP4.11" },
  873. { 0x0052, "QuickLink" },
  874. { 0x0053, "PrintQueueUser" },
  875. { 0x0058, "Multipoint X.25 Router" },
  876. { 0x0060, "STLB/NLM" },
  877. { 0x0064, "ARCserve" },
  878. { 0x0066, "ARCserve3.0" },
  879. { 0x0072, "WAN CopyUtility" },
  880. { 0x007a, "TES-NetwareVMS" },
  881. { 0x0092, "WATCOM Debugger/EmeraldTapeBackupServer" },
  882. { 0x0095, "DDA OBGYN" },
  883. { 0x0098, "NetwareAccessServer" },
  884. { 0x009a, "Netware for VMS II/NamedPipeServer" },
  885. { 0x009b, "NetwareAccessServer" },
  886. { 0x009e, "PortableNetwareServer/SunLinkNVT" },
  887. { 0x00a1, "PowerchuteAPC UPS" },
  888. { 0x00aa, "LAWserve" },
  889. { 0x00ac, "CompaqIDA StatusMonitor" },
  890. { 0x0100, "PIPE STAIL" },
  891. { 0x0102, "LAN ProtectBindery" },
  892. { 0x0103, "OracleDataBaseServer" },
  893. { 0x0107, "Netware386/RSPX RemoteConsole" },
  894. { 0x010f, "NovellSNA Gateway" },
  895. { 0x0111, "TestServer" },
  896. { 0x0112, "HP PrintServer" },
  897. { 0x0114, "CSA MUX" },
  898. { 0x0115, "CSA LCA" },
  899. { 0x0116, "CSA CM" },
  900. { 0x0117, "CSA SMA" },
  901. { 0x0118, "CSA DBA" },
  902. { 0x0119, "CSA NMA" },
  903. { 0x011a, "CSA SSA" },
  904. { 0x011b, "CSA STATUS" },
  905. { 0x011e, "CSA APPC" },
  906. { 0x0126, "SNA TEST SSA Profile" },
  907. { 0x012a, "CSA TRACE" },
  908. { 0x012b, "NetwareSAA" },
  909. { 0x012e, "IKARUS VirusScan" },
  910. { 0x0130, "CommunicationsExecutive" },
  911. { 0x0133, "NNS DomainServer/NetwareNamingServicesDomain" },
  912. { 0x0135, "NetwareNamingServicesProfile" },
  913. { 0x0137, "Netware386 PrintQueue/NNS PrintQueue" },
  914. { 0x0141, "LAN SpoolServer" },
  915. { 0x0152, "IRMALAN Gateway" },
  916. { 0x0154, "NamedPipeServer" },
  917. { 0x0166, "NetWareManagement" },
  918. { 0x0168, "Intel PICKIT CommServer/Intel CAS TalkServer" },
  919. { 0x0173, "Compaq" },
  920. { 0x0174, "Compaq SNMP Agent" },
  921. { 0x0175, "Compaq" },
  922. { 0x0180, "XTreeServer/XTreeTools" },
  923. { 0x018A, "NASI ServicesBroadcastServer" },
  924. { 0x01b0, "GARP Gateway" },
  925. { 0x01b1, "Binfview" },
  926. { 0x01bf, "IntelLanDeskManager" },
  927. { 0x01ca, "AXTEC" },
  928. { 0x01cb, "ShivaNetModem/E" },
  929. { 0x01cc, "ShivaLanRover/E" },
  930. { 0x01cd, "ShivaLanRover/T" },
  931. { 0x01ce, "ShivaUniversal" },
  932. { 0x01d8, "CastelleFAXPressServer" },
  933. { 0x01da, "CastelleLANPressPrintServer" },
  934. { 0x01dc, "CastelleFAX/Xerox7033 FaxServer/ExcelLanFax" },
  935. { 0x01f0, "LEGATO" },
  936. { 0x01f5, "LEGATO" },
  937. { 0x0233, "NMS Agent/NetwareManagementAgent" },
  938. { 0x0237, "NMS IPX Discovery/LANternReadWriteChannel" },
  939. { 0x0238, "NMS IP Discovery/LANternTrapAlarmChannel" },
  940. { 0x023a, "LANtern" },
  941. { 0x023c, "MAVERICK" },
  942. { 0x023f, "NovellSMDR" },
  943. { 0x024e, "NetwareConnect" },
  944. { 0x024f, "NASI ServerBroadcast Cisco" },
  945. { 0x026a, "NMS ServiceConsole" },
  946. { 0x026b, "TimeSynchronizationServer Netware 4.x" },
  947. { 0x0278, "DirectoryServer Netware 4.x" },
  948. { 0x027b, "NetwareManagementAgent" },
  949. { 0x0280, "Novell File and Printer Sharing Service for PC" },
  950. { 0x0304, "NovellSAA Gateway" },
  951. { 0x0308, "COM/VERMED" },
  952. { 0x030a, "GalacticommWorldgroupServer" },
  953. { 0x030c, "IntelNetport2/HP JetDirect/HP Quicksilver" },
  954. { 0x0320, "AttachmateGateway" },
  955. { 0x0327, "MicrosoftDiagnostiocs" },
  956. { 0x0328, "WATCOM SQL Server" },
  957. { 0x0335, "MultiTechSystems MultisynchCommServer" },
  958. { 0x0343, "Xylogics RemoteAccessServer/LANModem" },
  959. { 0x0355, "ArcadaBackupExec" },
  960. { 0x0358, "MSLCD1" },
  961. { 0x0361, "NETINELO" },
  962. { 0x037e, "Powerchute UPS Monitoring" },
  963. { 0x037f, "ViruSafeNotify" },
  964. { 0x0386, "HP Bridge" },
  965. { 0x0387, "HP Hub" },
  966. { 0x0394, "NetWare SAA Gateway" },
  967. { 0x039b, "LotusNotes" },
  968. { 0x03b7, "CertusAntiVirus" },
  969. { 0x03c4, "ARCserve4.0" },
  970. { 0x03c7, "LANspool3.5" },
  971. { 0x03d7, "LexmarkPrinterServer" },
  972. { 0x03d8, "LexmarkXLE PrinterServer" },
  973. { 0x03dd, "BanyanENS NetwareClient" },
  974. { 0x03de, "GuptaSequelBaseServer/NetWareSQL" },
  975. { 0x03e1, "UnivelUnixware" },
  976. { 0x03e4, "UnivelUnixware" },
  977. { 0x03fc, "IntelNetport" },
  978. { 0x03fd, "PrintServerQueue" },
  979. { 0x040A, "ipnServer" },
  980. { 0x040D, "LVERRMAN" },
  981. { 0x040E, "LVLIC" },
  982. { 0x0414, "NET Silicon (DPI)/Kyocera" },
  983. { 0x0429, "SiteLockVirus" },
  984. { 0x0432, "UFHELPR???" },
  985. { 0x0433, "Synoptics281xAdvancedSNMPAgent" },
  986. { 0x0444, "MicrosoftNT SNA Server" },
  987. { 0x0448, "Oracle" },
  988. { 0x044c, "ARCserve5.01" },
  989. { 0x0457, "CanonGP55" },
  990. { 0x045a, "QMS Printers" },
  991. { 0x045b, "DellSCSI Array" },
  992. { 0x0491, "NetBlazerModems" },
  993. { 0x04ac, "OnTimeScheduler" },
  994. { 0x04b0, "CD-Net" },
  995. { 0x0513, "EmulexNQA" },
  996. { 0x0520, "SiteLockChecks" },
  997. { 0x0529, "SiteLockChecks" },
  998. { 0x052d, "CitrixOS2 AppServer" },
  999. { 0x0535, "Tektronix" },
  1000. { 0x0536, "Milan" },
  1001. { 0x055d, "Attachmate SNA gateway" },
  1002. { 0x056b, "IBM8235 ModemServer" },
  1003. { 0x056c, "ShivaLanRover/E PLUS" },
  1004. { 0x056d, "ShivaLanRover/T PLUS" },
  1005. { 0x0580, "McAfeeNetShield" },
  1006. { 0x05B8, "NLM to workstation communication (Revelation Software)" },
  1007. { 0x05BA, "CompatibleSystemsRouters" },
  1008. { 0x05BE, "CheyenneHierarchicalStorageManager" },
  1009. { 0x0606, "JCWatermarkImaging" },
  1010. { 0x060c, "AXISNetworkPrinter" },
  1011. { 0x0610, "AdaptecSCSIManagement" },
  1012. { 0x0621, "IBM AntiVirus" },
  1013. { 0x0640, "Windows95 RemoteRegistryService" },
  1014. { 0x064e, "MicrosoftIIS" },
  1015. { 0x067b, "Microsoft Win95/98 File and Print Sharing for NetWare" },
  1016. { 0x067c, "Microsoft Win95/98 File and Print Sharing for NetWare" },
  1017. { 0x076C, "Xerox" },
  1018. { 0x079b, "ShivaLanRover/E 115" },
  1019. { 0x079c, "ShivaLanRover/T 115" },
  1020. { 0x07B4, "CubixWorldDesk" },
  1021. { 0x07c2, "Quarterdeck IWare Connect V2.x NLM" },
  1022. { 0x07c1, "Quarterdeck IWare Connect V3.x NLM" },
  1023. { 0x0810, "ELAN License Server Demo" },
  1024. { 0x0824, "ShivaLanRoverAccessSwitch/E" },
  1025. { 0x086a, "ISSC Collector" },
  1026. { 0x087f, "ISSC DAS AgentAIX" },
  1027. { 0x0880, "Intel Netport PRO" },
  1028. { 0x0881, "Intel Netport PRO" },
  1029. { 0x0b29, "SiteLock" },
  1030. { 0x0c29, "SiteLockApplications" },
  1031. { 0x0c2c, "LicensingServer" },
  1032. { 0x2101, "PerformanceTechnologyInstantInternet" },
  1033. { 0x2380, "LAI SiteLock" },
  1034. { 0x238c, "MeetingMaker" },
  1035. { 0x4808, "SiteLockServer/SiteLockMetering" },
  1036. { 0x5555, "SiteLockUser" },
  1037. { 0x6312, "Tapeware" },
  1038. { 0x6f00, "RabbitGateway" },
  1039. { 0x7703, "MODEM" },
  1040. { 0x8002, "NetPortPrinters" },
  1041. { 0x8008, "WordPerfectNetworkVersion" },
  1042. { 0x85BE, "Cisco EIGRP" },
  1043. { 0x8888, "WordPerfectNetworkVersion/QuickNetworkManagement" },
  1044. { 0x9000, "McAfeeNetShield" },
  1045. { 0x9604, "CSA-NT_MON" },
  1046. { 0xb6a8, "OceanIsleReachoutRemoteControl" },
  1047. { 0xf11f, "SiteLockMetering" },
  1048. { 0xf1ff, "SiteLock" },
  1049. { 0xf503, "Microsoft SQL Server" },
  1050. { 0xF905, "IBM TimeAndPlace" },
  1051. { 0xfbfb, "TopCallIII FaxServer" },
  1052. { 0xffff, "AnyService/Wildcard" },
  1053. { 0, (char *)0 }
  1054. };
  1055. static void
  1056. init_ipxsaparray(netdissect_options *ndo)
  1057. {
  1058. register int i;
  1059. register struct hnamemem *table;
  1060. for (i = 0; ipxsap_db[i].s != NULL; i++) {
  1061. int j = htons(ipxsap_db[i].v) & (HASHNAMESIZE-1);
  1062. table = &ipxsaptable[j];
  1063. while (table->name)
  1064. table = table->nxt;
  1065. table->name = ipxsap_db[i].s;
  1066. table->addr = htons(ipxsap_db[i].v);
  1067. table->nxt = newhnamemem(ndo);
  1068. }
  1069. }
  1070. /*
  1071. * Initialize the address to name translation machinery. We map all
  1072. * non-local IP addresses to numeric addresses if ndo->ndo_fflag is true
  1073. * (i.e., to prevent blocking on the nameserver). localnet is the IP address
  1074. * of the local network. mask is its subnet mask.
  1075. */
  1076. void
  1077. init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
  1078. {
  1079. if (ndo->ndo_fflag) {
  1080. f_localnet = localnet;
  1081. f_netmask = mask;
  1082. }
  1083. if (ndo->ndo_nflag)
  1084. /*
  1085. * Simplest way to suppress names.
  1086. */
  1087. return;
  1088. init_etherarray(ndo);
  1089. init_servarray(ndo);
  1090. init_eprotoarray(ndo);
  1091. init_protoidarray(ndo);
  1092. init_ipxsaparray(ndo);
  1093. }
  1094. const char *
  1095. dnaddr_string(netdissect_options *ndo, u_short dnaddr)
  1096. {
  1097. register struct hnamemem *tp;
  1098. for (tp = &dnaddrtable[dnaddr & (HASHNAMESIZE-1)]; tp->nxt != NULL;
  1099. tp = tp->nxt)
  1100. if (tp->addr == dnaddr)
  1101. return (tp->name);
  1102. tp->addr = dnaddr;
  1103. tp->nxt = newhnamemem(ndo);
  1104. if (ndo->ndo_nflag)
  1105. tp->name = dnnum_string(ndo, dnaddr);
  1106. else
  1107. tp->name = dnname_string(ndo, dnaddr);
  1108. return(tp->name);
  1109. }
  1110. /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */
  1111. struct hnamemem *
  1112. newhnamemem(netdissect_options *ndo)
  1113. {
  1114. register struct hnamemem *p;
  1115. static struct hnamemem *ptr = NULL;
  1116. static u_int num = 0;
  1117. if (num <= 0) {
  1118. num = 64;
  1119. ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
  1120. if (ptr == NULL)
  1121. (*ndo->ndo_error)(ndo, "newhnamemem: calloc");
  1122. }
  1123. --num;
  1124. p = ptr++;
  1125. return (p);
  1126. }
  1127. /* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
  1128. struct h6namemem *
  1129. newh6namemem(netdissect_options *ndo)
  1130. {
  1131. register struct h6namemem *p;
  1132. static struct h6namemem *ptr = NULL;
  1133. static u_int num = 0;
  1134. if (num <= 0) {
  1135. num = 64;
  1136. ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
  1137. if (ptr == NULL)
  1138. (*ndo->ndo_error)(ndo, "newh6namemem: calloc");
  1139. }
  1140. --num;
  1141. p = ptr++;
  1142. return (p);
  1143. }
  1144. /* Represent TCI part of the 802.1Q 4-octet tag as text. */
  1145. const char *
  1146. ieee8021q_tci_string(const uint16_t tci)
  1147. {
  1148. static char buf[128];
  1149. snprintf(buf, sizeof(buf), "vlan %u, p %u%s",
  1150. tci & 0xfff,
  1151. tci >> 13,
  1152. (tci & 0x1000) ? ", DEI" : "");
  1153. return buf;
  1154. }