]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-atalk.c
Handle rpcaps:// URLs as well, for rpcap-over-TLS.
[tcpdump] / print-atalk.c
index 0d6b87d83faa7f6aee91d10b5c47443697b25306..8faa29f0ce9cefeeb43985f43e970fcdd7f86362 100644 (file)
@@ -36,7 +36,6 @@
 #include "extract.h"
 #include "appletalk.h"
 
-static const char tstr[] = "[|atalk]";
 
 static const struct tok type2str[] = {
        { ddpRTMP,              "rtmp" },
@@ -79,6 +78,7 @@ ltalk_if_print(netdissect_options *ndo,
 {
        u_int hdrlen;
 
+       ndo->ndo_protocol = "ltalk_if";
        hdrlen = llap_print(ndo, p, h->len);
        if (hdrlen == 0) {
                /* Cut short by the snapshot length. */
@@ -100,12 +100,13 @@ llap_print(netdissect_options *ndo,
        u_short snet;
        u_int hdrlen;
 
+       ndo->ndo_protocol = "llap";
        if (length < sizeof(*lp)) {
                ND_PRINT(" [|llap %u]", length);
                return (length);
        }
        if (!ND_TTEST_LEN(bp, sizeof(*lp))) {
-               ND_PRINT(" [|llap]");
+               nd_print_trunc(ndo);
                return (0);     /* cut short by the snapshot length */
        }
        lp = (const struct LAP *)bp;
@@ -182,6 +183,7 @@ atalk_print(netdissect_options *ndo,
        const struct atDDP *dp;
        u_short snet;
 
+       ndo->ndo_protocol = "atalk";
         if(!ndo->ndo_eflag)
             ND_PRINT("AT ");
 
@@ -214,11 +216,12 @@ aarp_print(netdissect_options *ndo,
 
 #define AT(member) ataddr_string(ndo, (ap->member[1]<<8)|ap->member[2],ap->member[3])
 
+       ndo->ndo_protocol = "aarp";
        ND_PRINT("aarp ");
        ap = (const struct aarp *)bp;
        if (!ND_TTEST_SIZE(ap)) {
                /* Just bail if we don't have the whole chunk. */
-               ND_PRINT(" [|aarp]");
+               nd_print_trunc(ndo);
                return;
        }
        if (length < sizeof(*ap)) {
@@ -285,7 +288,7 @@ atp_print(netdissect_options *ndo,
 
        if ((const u_char *)(ap + 1) > ndo->ndo_snapend) {
                /* Just bail if we don't have the whole chunk. */
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                return;
        }
        if (length < sizeof(*ap)) {
@@ -429,7 +432,7 @@ nbp_print(netdissect_options *ndo,
        /* ep points to end of available data */
        ep = ndo->ndo_snapend;
        if ((const u_char *)tp > ep) {
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                return;
        }
        control = EXTRACT_U_1(np->control);
@@ -439,7 +442,7 @@ nbp_print(netdissect_options *ndo,
        case nbpLkUp:
                ND_PRINT(i == nbpLkUp? " nbp-lkup %u:":" nbp-brRq %u:", EXTRACT_U_1(np->id));
                if ((const u_char *)(tp + 1) > ep) {
-                       ND_PRINT("%s", tstr);
+                       nd_print_trunc(ndo);
                        return;
                }
                (void)nbp_name_print(ndo, tp, ep);
@@ -476,14 +479,14 @@ nbp_print(netdissect_options *ndo,
 }
 
 /* print a counted string */
-static const char *
+static const u_char *
 print_cstring(netdissect_options *ndo,
-              const char *cp, const u_char *ep)
+              const u_char *cp, const u_char *ep)
 {
        u_int length;
 
-       if (cp >= (const char *)ep) {
-               ND_PRINT("%s", tstr);
+       if (cp >= ep) {
+               nd_print_trunc(ndo);
                return (0);
        }
        length = EXTRACT_U_1(cp);
@@ -495,11 +498,11 @@ print_cstring(netdissect_options *ndo,
                return (0);
        }
        while (length != 0) {
-               if (cp >= (const char *)ep) {
-                       ND_PRINT("%s", tstr);
+               if (cp >= ep) {
+                       nd_print_trunc(ndo);
                        return (0);
                }
-               ND_PRINT("%c", EXTRACT_U_1(cp));
+               fn_print_char(ndo, EXTRACT_U_1(cp));
                cp++;
                length--;
        }
@@ -514,7 +517,7 @@ nbp_tuple_print(netdissect_options *ndo,
        const struct atNBPtuple *tpn;
 
        if ((const u_char *)(tp + 1) > ep) {
-               ND_PRINT("%s", tstr);
+               nd_print_trunc(ndo);
                return 0;
        }
        tpn = nbp_name_print(ndo, tp, ep);
@@ -540,7 +543,7 @@ static const struct atNBPtuple *
 nbp_name_print(netdissect_options *ndo,
                const struct atNBPtuple *tp, const u_char *ep)
 {
-       const char *cp = (const char *)tp + nbpTupleSize;
+       const u_char *cp = (const u_char *)tp + nbpTupleSize;
 
        ND_PRINT(" ");
 
@@ -581,39 +584,57 @@ ataddr_string(netdissect_options *ndo,
        FILE *fp;
 
        /*
-        * if this is the first call, see if there's an AppleTalk
-        * number to name map file.
+        * Are we doing address to name resolution?
         */
-       if (first && (first = 0, !ndo->ndo_nflag)
-           && (fp = fopen("/etc/atalk.names", "r"))) {
-               char line[256];
-               u_int i1, i2;
-
-               while (fgets(line, sizeof(line), fp)) {
-                       if (line[0] == '\n' || line[0] == 0 || line[0] == '#')
-                               continue;
-                       if (sscanf(line, "%u.%u %256s", &i1, &i2, nambuf) == 3)
-                               /* got a hostname. */
-                               i2 |= (i1 << 8);
-                       else if (sscanf(line, "%u %256s", &i1, nambuf) == 2)
-                               /* got a net name */
-                               i2 = (i1 << 8) | 255;
-                       else
-                               continue;
-
-                       for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
-                            tp->nxt; tp = tp->nxt)
-                               ;
-                       tp->addr = i2;
-                       tp->nxt = newhnamemem(ndo);
-                       tp->name = strdup(nambuf);
-                       if (tp->name == NULL)
-                               (*ndo->ndo_error)(ndo,
-                                                 "ataddr_string: strdup(nambuf)");
+       if (!ndo->ndo_nflag) {
+               /*
+                * Yes.  Have we tried to open and read an AppleTalk
+                * number to name map file?
+                */
+               if (!first) {
+                       /*
+                        * No; try to do so.
+                        */
+                       first = 0;
+                       fp = fopen("/etc/atalk.names", "r");
+                       if (fp != NULL) {
+                               char line[256];
+                               u_int i1, i2;
+
+                               while (fgets(line, sizeof(line), fp)) {
+                                       if (line[0] == '\n' || line[0] == 0 ||
+                                           line[0] == '#')
+                                               continue;
+                                       if (sscanf(line, "%u.%u %256s", &i1,
+                                           &i2, nambuf) == 3)
+                                               /* got a hostname. */
+                                               i2 |= (i1 << 8);
+                                       else if (sscanf(line, "%u %256s", &i1,
+                                           nambuf) == 2)
+                                               /* got a net name */
+                                               i2 = (i1 << 8) | 255;
+                                       else
+                                               continue;
+
+                                       for (tp = &hnametable[i2 & (HASHNAMESIZE-1)];
+                                            tp->nxt; tp = tp->nxt)
+                                               ;
+                                       tp->addr = i2;
+                                       tp->nxt = newhnamemem(ndo);
+                                       tp->name = strdup(nambuf);
+                                       if (tp->name == NULL)
+                                               (*ndo->ndo_error)(ndo,
+                                                   S_ERR_ND_MEM_ALLOC,
+                                                   "ataddr_string: strdup(nambuf)");
+                               }
+                               fclose(fp);
+                       }
                }
-               fclose(fp);
        }
 
+       /*
+        * Now try to look up the address in the table.
+        */
        for (tp = &hnametable[i & (HASHNAMESIZE-1)]; tp->nxt; tp = tp->nxt)
                if (tp->addr == i)
                        return (tp->name);
@@ -624,24 +645,25 @@ ataddr_string(netdissect_options *ndo,
                if (tp2->addr == i) {
                        tp->addr = (atnet << 8) | athost;
                        tp->nxt = newhnamemem(ndo);
-                       (void)snprintf(nambuf, sizeof(nambuf), "%s.%u",
+                       (void)nd_snprintf(nambuf, sizeof(nambuf), "%s.%u",
                            tp2->name, athost);
                        tp->name = strdup(nambuf);
                        if (tp->name == NULL)
-                               (*ndo->ndo_error)(ndo,
-                                                 "ataddr_string: strdup(nambuf)");
+                               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                                       "ataddr_string: strdup(nambuf)");
                        return (tp->name);
                }
 
        tp->addr = (atnet << 8) | athost;
        tp->nxt = newhnamemem(ndo);
        if (athost != 255)
-               (void)snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost);
+               (void)nd_snprintf(nambuf, sizeof(nambuf), "%u.%u", atnet, athost);
        else
-               (void)snprintf(nambuf, sizeof(nambuf), "%u", atnet);
+               (void)nd_snprintf(nambuf, sizeof(nambuf), "%u", atnet);
        tp->name = strdup(nambuf);
        if (tp->name == NULL)
-               (*ndo->ndo_error)(ndo, "ataddr_string: strdup(nambuf)");
+               (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC,
+                                 "ataddr_string: strdup(nambuf)");
 
        return (tp->name);
 }
@@ -661,7 +683,7 @@ ddpskt_string(netdissect_options *ndo,
        static char buf[8];
 
        if (ndo->ndo_nflag) {
-               (void)snprintf(buf, sizeof(buf), "%u", skt);
+               (void)nd_snprintf(buf, sizeof(buf), "%u", skt);
                return (buf);
        }
        return (tok2str(skt2str, "%u", skt));