]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Functions in libnetdissect must use ndo_error() function
authorFrancois-Xavier Le Bail <[email protected]>
Sat, 5 Sep 2015 20:28:04 +0000 (22:28 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Sat, 5 Sep 2015 20:52:11 +0000 (22:52 +0200)
13 files changed:
addrtoname.c
addrtoname.h
print-802_15_4.c
print-atalk.c
print-bgp.c
print-icmp.c
print-icmp6.c
print-ipx.c
print-isoclns.c
print-pgm.c
print-tcp.c
print-udp.c
print.c

index 96af9e112236abcc4a8f3c2970f57f0918c421ce..3449912768d52ef60fa5a8fdefb132fe128e9ff9 100644 (file)
@@ -71,7 +71,7 @@ extern int ether_ntohost(char *, const struct ether_addr *);
 /*
  * hash tables for whatever-to-name translations
  *
- * error() called on strdup(3) failure
+ * ndo_error() called on strdup(3) failure
  */
 
 #define HASHNAMESIZE 4096
@@ -231,7 +231,7 @@ getname(netdissect_options *ndo, const u_char *ap)
                        return (p->name);
        }
        p->addr = addr;
-       p->nxt = newhnamemem();
+       p->nxt = newhnamemem(ndo);
 
        /*
         * Print names unless:
@@ -248,7 +248,8 @@ getname(netdissect_options *ndo, const u_char *ap)
 
                        p->name = strdup(hp->h_name);
                        if (p->name == NULL)
-                               error("getname: strdup(hp->h_name)");
+                               (*ndo->ndo_error)(ndo,
+                                                 "getname: strdup(hp->h_name)");
                        if (ndo->ndo_Nflag) {
                                /* Remove domain qualifications */
                                dotp = strchr(p->name, '.');
@@ -260,7 +261,7 @@ getname(netdissect_options *ndo, const u_char *ap)
        }
        p->name = strdup(intoa(addr));
        if (p->name == NULL)
-               error("getname: strdup(intoa(addr))");
+               (*ndo->ndo_error)(ndo, "getname: strdup(intoa(addr))");
        return (p->name);
 }
 
@@ -291,7 +292,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
                        return (p->name);
        }
        p->addr = addr.addr;
-       p->nxt = newh6namemem();
+       p->nxt = newh6namemem(ndo);
 
        /*
         * Do not print names if -n was given.
@@ -303,7 +304,8 @@ getname6(netdissect_options *ndo, const u_char *ap)
 
                        p->name = strdup(hp->h_name);
                        if (p->name == NULL)
-                               error("getname6: strdup(hp->h_name)");
+                               (*ndo->ndo_error)(ndo,
+                                                 "getname6: strdup(hp->h_name)");
                        if (ndo->ndo_Nflag) {
                                /* Remove domain qualifications */
                                dotp = strchr(p->name, '.');
@@ -316,7 +318,7 @@ getname6(netdissect_options *ndo, const u_char *ap)
        cp = inet_ntop(AF_INET6, &addr, ntop_buf, sizeof(ntop_buf));
        p->name = strdup(cp);
        if (p->name == NULL)
-               error("getname6: strdup(cp)");
+               (*ndo->ndo_error)(ndo, "getname6: strdup(cp)");
        return (p->name);
 }
 #endif /* INET6 */
@@ -327,7 +329,7 @@ static const char hex[] = "0123456789abcdef";
 /* Find the hash node that corresponds the ether address 'ep' */
 
 static inline struct enamemem *
-lookup_emem(const u_char *ep)
+lookup_emem(netdissect_options *ndo, const u_char *ep)
 {
        register u_int i, j, k;
        struct enamemem *tp;
@@ -349,7 +351,7 @@ lookup_emem(const u_char *ep)
        tp->e_addr2 = k;
        tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
        if (tp->e_nxt == NULL)
-               error("lookup_emem: calloc");
+               (*ndo->ndo_error)(ndo, "lookup_emem: calloc");
 
        return tp;
 }
@@ -360,7 +362,8 @@ lookup_emem(const u_char *ep)
  */
 
 static inline struct enamemem *
-lookup_bytestring(register const u_char *bs, const unsigned int nlen)
+lookup_bytestring(netdissect_options *ndo, register const u_char *bs,
+                 const unsigned int nlen)
 {
        struct enamemem *tp;
        register u_int i, j, k;
@@ -392,12 +395,12 @@ lookup_bytestring(register const u_char *bs, const unsigned int nlen)
 
        tp->e_bs = (u_char *) calloc(1, nlen + 1);
        if (tp->e_bs == NULL)
-               error("lookup_bytestring: calloc");
+               (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
 
        memcpy(tp->e_bs, bs, nlen);
        tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
        if (tp->e_nxt == NULL)
-               error("lookup_bytestring: calloc");
+               (*ndo->ndo_error)(ndo, "lookup_bytestring: calloc");
 
        return tp;
 }
@@ -405,7 +408,7 @@ lookup_bytestring(register const u_char *bs, const unsigned int nlen)
 /* Find the hash node that corresponds the NSAP 'nsap' */
 
 static inline struct enamemem *
-lookup_nsap(register const u_char *nsap)
+lookup_nsap(netdissect_options *ndo, register const u_char *nsap)
 {
        register u_int i, j, k;
        unsigned int nlen = *nsap;
@@ -436,11 +439,11 @@ lookup_nsap(register const u_char *nsap)
        tp->e_addr2 = k;
        tp->e_nsap = (u_char *)malloc(nlen + 1);
        if (tp->e_nsap == NULL)
-               error("lookup_nsap: malloc");
+               (*ndo->ndo_error)(ndo, "lookup_nsap: malloc");
        memcpy((char *)tp->e_nsap, (const char *)nsap, nlen + 1);
        tp->e_nxt = (struct enamemem *)calloc(1, sizeof(*tp));
        if (tp->e_nxt == NULL)
-               error("lookup_nsap: calloc");
+               (*ndo->ndo_error)(ndo, "lookup_nsap: calloc");
 
        return tp;
 }
@@ -448,7 +451,7 @@ lookup_nsap(register const u_char *nsap)
 /* Find the hash node that corresponds the protoid 'pi'. */
 
 static inline struct protoidmem *
-lookup_protoid(const u_char *pi)
+lookup_protoid(netdissect_options *ndo, const u_char *pi)
 {
        register u_int i, j;
        struct protoidmem *tp;
@@ -468,7 +471,7 @@ lookup_protoid(const u_char *pi)
        tp->p_proto = j;
        tp->p_nxt = (struct protoidmem *)calloc(1, sizeof(*tp));
        if (tp->p_nxt == NULL)
-               error("lookup_protoid: calloc");
+               (*ndo->ndo_error)(ndo, "lookup_protoid: calloc");
 
        return tp;
 }
@@ -482,7 +485,7 @@ etheraddr_string(netdissect_options *ndo, register const u_char *ep)
        int oui;
        char buf[BUFSIZE];
 
-       tp = lookup_emem(ep);
+       tp = lookup_emem(ndo, ep);
        if (tp->e_name)
                return (tp->e_name);
 #ifdef USE_ETHER_NTOHOST
@@ -492,7 +495,8 @@ etheraddr_string(netdissect_options *ndo, register const u_char *ep)
                if (ether_ntohost(buf2, (const struct ether_addr *)ep) == 0) {
                        tp->e_name = strdup(buf2);
                        if (tp->e_name == NULL)
-                               error("etheraddr_string: strdup(buf2)");
+                               (*ndo->ndo_error)(ndo,
+                                                 "etheraddr_string: strdup(buf2)");
                        return (tp->e_name);
                }
        }
@@ -514,12 +518,12 @@ etheraddr_string(netdissect_options *ndo, register const u_char *ep)
                *cp = '\0';
        tp->e_name = strdup(buf);
        if (tp->e_name == NULL)
-               error("etheraddr_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "etheraddr_string: strdup(buf)");
        return (tp->e_name);
 }
 
 const char *
-le64addr_string(const u_char *ep)
+le64addr_string(netdissect_options *ndo, const u_char *ep)
 {
        const unsigned int len = 8;
        register u_int i;
@@ -527,7 +531,7 @@ le64addr_string(const u_char *ep)
        register struct enamemem *tp;
        char buf[BUFSIZE];
 
-       tp = lookup_bytestring(ep, len);
+       tp = lookup_bytestring(ndo, ep, len);
        if (tp->e_name)
                return (tp->e_name);
 
@@ -543,13 +547,14 @@ le64addr_string(const u_char *ep)
 
        tp->e_name = strdup(buf);
        if (tp->e_name == NULL)
-               error("le64addr_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "le64addr_string: strdup(buf)");
 
        return (tp->e_name);
 }
 
 const char *
-linkaddr_string(netdissect_options *ndo, const u_char *ep, const unsigned int type, const unsigned int len)
+linkaddr_string(netdissect_options *ndo, const u_char *ep,
+               const unsigned int type, const unsigned int len)
 {
        register u_int i;
        register char *cp;
@@ -564,13 +569,13 @@ linkaddr_string(netdissect_options *ndo, const u_char *ep, const unsigned int ty
        if (type == LINKADDR_FRELAY)
                return (q922_string(ndo, ep, len));
 
-       tp = lookup_bytestring(ep, len);
+       tp = lookup_bytestring(ndo, ep, len);
        if (tp->e_name)
                return (tp->e_name);
 
        tp->e_name = cp = (char *)malloc(len*3);
        if (tp->e_name == NULL)
-               error("linkaddr_string: malloc");
+               (*ndo->ndo_error)(ndo, "linkaddr_string: malloc");
        *cp++ = hex[*ep >> 4];
        *cp++ = hex[*ep++ & 0xf];
        for (i = len-1; i > 0 ; --i) {
@@ -583,7 +588,7 @@ linkaddr_string(netdissect_options *ndo, const u_char *ep, const unsigned int ty
 }
 
 const char *
-etherproto_string(u_short port)
+etherproto_string(netdissect_options *ndo, u_short port)
 {
        register char *cp;
        register struct hnamemem *tp;
@@ -595,7 +600,7 @@ etherproto_string(u_short port)
                        return (tp->name);
 
        tp->addr = i;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
 
        cp = buf;
        NTOHS(port);
@@ -606,19 +611,19 @@ etherproto_string(u_short port)
        *cp++ = '\0';
        tp->name = strdup(buf);
        if (tp->name == NULL)
-               error("etherproto_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "etherproto_string: strdup(buf)");
        return (tp->name);
 }
 
 const char *
-protoid_string(register const u_char *pi)
+protoid_string(netdissect_options *ndo, register const u_char *pi)
 {
        register u_int i, j;
        register char *cp;
        register struct protoidmem *tp;
        char buf[sizeof("00:00:00:00:00")];
 
-       tp = lookup_protoid(pi);
+       tp = lookup_protoid(ndo, pi);
        if (tp->p_name)
                return tp->p_name;
 
@@ -635,13 +640,14 @@ protoid_string(register const u_char *pi)
        *cp = '\0';
        tp->p_name = strdup(buf);
        if (tp->p_name == NULL)
-               error("protoid_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "protoid_string: strdup(buf)");
        return (tp->p_name);
 }
 
 #define ISONSAP_MAX_LENGTH 20
 const char *
-isonsap_string(const u_char *nsap, register u_int nsap_length)
+isonsap_string(netdissect_options *ndo, const u_char *nsap,
+              register u_int nsap_length)
 {
        register u_int nsap_idx;
        register char *cp;
@@ -650,13 +656,13 @@ isonsap_string(const u_char *nsap, register u_int nsap_length)
        if (nsap_length < 1 || nsap_length > ISONSAP_MAX_LENGTH)
                return ("isonsap_string: illegal length");
 
-       tp = lookup_nsap(nsap);
+       tp = lookup_nsap(ndo, nsap);
        if (tp->e_name)
                return tp->e_name;
 
        tp->e_name = cp = (char *)malloc(sizeof("xx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xxxx.xx"));
        if (cp == NULL)
-               error("isonsap_string: malloc");
+               (*ndo->ndo_error)(ndo, "isonsap_string: malloc");
 
        for (nsap_idx = 0; nsap_idx < nsap_length; nsap_idx++) {
                *cp++ = hex[*nsap >> 4];
@@ -671,7 +677,7 @@ isonsap_string(const u_char *nsap, register u_int nsap_length)
 }
 
 const char *
-tcpport_string(u_short port)
+tcpport_string(netdissect_options *ndo, u_short port)
 {
        register struct hnamemem *tp;
        register uint32_t i = port;
@@ -682,17 +688,17 @@ tcpport_string(u_short port)
                        return (tp->name);
 
        tp->addr = i;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
        tp->name = strdup(buf);
        if (tp->name == NULL)
-               error("tcpport_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "tcpport_string: strdup(buf)");
        return (tp->name);
 }
 
 const char *
-udpport_string(register u_short port)
+udpport_string(netdissect_options *ndo, register u_short port)
 {
        register struct hnamemem *tp;
        register uint32_t i = port;
@@ -703,17 +709,17 @@ udpport_string(register u_short port)
                        return (tp->name);
 
        tp->addr = i;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
 
        (void)snprintf(buf, sizeof(buf), "%u", i);
        tp->name = strdup(buf);
        if (tp->name == NULL)
-               error("udpport_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "udpport_string: strdup(buf)");
        return (tp->name);
 }
 
 const char *
-ipxsap_string(u_short port)
+ipxsap_string(netdissect_options *ndo, u_short port)
 {
        register char *cp;
        register struct hnamemem *tp;
@@ -725,7 +731,7 @@ ipxsap_string(u_short port)
                        return (tp->name);
 
        tp->addr = i;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
 
        cp = buf;
        NTOHS(port);
@@ -736,7 +742,7 @@ ipxsap_string(u_short port)
        *cp++ = '\0';
        tp->name = strdup(buf);
        if (tp->name == NULL)
-               error("ipxsap_string: strdup(buf)");
+               (*ndo->ndo_error)(ndo, "ipxsap_string: strdup(buf)");
        return (tp->name);
 }
 
@@ -766,10 +772,10 @@ init_servarray(netdissect_options *ndo)
                } else
                        table->name = strdup(sv->s_name);
                if (table->name == NULL)
-                       error("init_servarray: strdup");
+                       (*ndo->ndo_error)(ndo, "init_servarray: strdup");
 
                table->addr = port;
-               table->nxt = newhnamemem();
+               table->nxt = newhnamemem(ndo);
        }
        endservent();
 }
@@ -786,7 +792,7 @@ const struct eproto {
 } eproto_db[];
 
 static void
-init_eprotoarray(void)
+init_eprotoarray(netdissect_options *ndo)
 {
        register int i;
        register struct hnamemem *table;
@@ -798,7 +804,7 @@ init_eprotoarray(void)
                        table = table->nxt;
                table->name = eproto_db[i].s;
                table->addr = htons(eproto_db[i].p);
-               table->nxt = newhnamemem();
+               table->nxt = newhnamemem(ndo);
        }
 }
 
@@ -819,7 +825,7 @@ static const struct protoidlist {
  * types.
  */
 static void
-init_protoidarray(void)
+init_protoidarray(netdissect_options *ndo)
 {
        register int i;
        register struct protoidmem *tp;
@@ -833,14 +839,15 @@ init_protoidarray(void)
                u_short etype = htons(eproto_db[i].p);
 
                memcpy((char *)&protoid[3], (char *)&etype, 2);
-               tp = lookup_protoid(protoid);
+               tp = lookup_protoid(ndo, protoid);
                tp->p_name = strdup(eproto_db[i].s);
                if (tp->p_name == NULL)
-                       error("init_protoidarray: strdup(eproto_db[i].s)");
+                       (*ndo->ndo_error)(ndo,
+                                         "init_protoidarray: strdup(eproto_db[i].s)");
        }
        /* Hardwire some SNAP proto ID names */
        for (pl = protoidlist; pl->name != NULL; ++pl) {
-               tp = lookup_protoid(pl->protoid);
+               tp = lookup_protoid(ndo, pl->protoid);
                /* Don't override existing name */
                if (tp->p_name != NULL)
                        continue;
@@ -872,7 +879,7 @@ static const struct etherlist {
  * translation, so we just pcap_next_etherent as a convenience.
  */
 static void
-init_etherarray(void)
+init_etherarray(netdissect_options *ndo)
 {
        register const struct etherlist *el;
        register struct enamemem *tp;
@@ -886,10 +893,11 @@ init_etherarray(void)
        fp = fopen(PCAP_ETHERS_FILE, "r");
        if (fp != NULL) {
                while ((ep = pcap_next_etherent(fp)) != NULL) {
-                       tp = lookup_emem(ep->addr);
+                       tp = lookup_emem(ndo, ep->addr);
                        tp->e_name = strdup(ep->name);
                        if (tp->e_name == NULL)
-                               error("init_etherarray: strdup(ep->addr)");
+                               (*ndo->ndo_error)(ndo,
+                                                 "init_etherarray: strdup(ep->addr)");
                }
                (void)fclose(fp);
        }
@@ -897,7 +905,7 @@ init_etherarray(void)
 
        /* Hardwire some ethernet names */
        for (el = etherlist; el->name != NULL; ++el) {
-               tp = lookup_emem(el->addr);
+               tp = lookup_emem(ndo, el->addr);
                /* Don't override existing name */
                if (tp->e_name != NULL)
                        continue;
@@ -909,7 +917,8 @@ init_etherarray(void)
                if (ether_ntohost(name, (const struct ether_addr *)el->addr) == 0) {
                        tp->e_name = strdup(name);
                        if (tp->e_name == NULL)
-                               error("init_etherarray: strdup(name)");
+                               (*ndo->ndo_error)(ndo,
+                                                 "init_etherarray: strdup(name)");
                        continue;
                }
 #endif
@@ -1135,7 +1144,7 @@ static const struct tok ipxsap_db[] = {
 };
 
 static void
-init_ipxsaparray(void)
+init_ipxsaparray(netdissect_options *ndo)
 {
        register int i;
        register struct hnamemem *table;
@@ -1147,7 +1156,7 @@ init_ipxsaparray(void)
                        table = table->nxt;
                table->name = ipxsap_db[i].s;
                table->addr = htons(ipxsap_db[i].v);
-               table->nxt = newhnamemem();
+               table->nxt = newhnamemem(ndo);
        }
 }
 
@@ -1170,11 +1179,11 @@ init_addrtoname(netdissect_options *ndo, uint32_t localnet, uint32_t mask)
                 */
                return;
 
-       init_etherarray();
+       init_etherarray(ndo);
        init_servarray(ndo);
-       init_eprotoarray();
-       init_protoidarray();
-       init_ipxsaparray();
+       init_eprotoarray(ndo);
+       init_protoidarray(ndo);
+       init_ipxsaparray(ndo);
 }
 
 const char *
@@ -1188,7 +1197,7 @@ dnaddr_string(netdissect_options *ndo, u_short dnaddr)
                        return (tp->name);
 
        tp->addr = dnaddr;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
        if (ndo->ndo_nflag)
                tp->name = dnnum_string(ndo, dnaddr);
        else
@@ -1199,7 +1208,7 @@ dnaddr_string(netdissect_options *ndo, u_short dnaddr)
 
 /* Return a zero'ed hnamemem struct and cuts down on calloc() overhead */
 struct hnamemem *
-newhnamemem(void)
+newhnamemem(netdissect_options *ndo)
 {
        register struct hnamemem *p;
        static struct hnamemem *ptr = NULL;
@@ -1209,7 +1218,7 @@ newhnamemem(void)
                num = 64;
                ptr = (struct hnamemem *)calloc(num, sizeof (*ptr));
                if (ptr == NULL)
-                       error("newhnamemem: calloc");
+                       (*ndo->ndo_error)(ndo, "newhnamemem: calloc");
        }
        --num;
        p = ptr++;
@@ -1219,7 +1228,7 @@ newhnamemem(void)
 #ifdef INET6
 /* Return a zero'ed h6namemem struct and cuts down on calloc() overhead */
 struct h6namemem *
-newh6namemem(void)
+newh6namemem(netdissect_options *ndo)
 {
        register struct h6namemem *p;
        static struct h6namemem *ptr = NULL;
@@ -1229,7 +1238,7 @@ newh6namemem(void)
                num = 64;
                ptr = (struct h6namemem *)calloc(num, sizeof (*ptr));
                if (ptr == NULL)
-                       error("newh6namemem: calloc");
+                       (*ndo->ndo_error)(ndo, "newh6namemem: calloc");
        }
        --num;
        p = ptr++;
index b07d8b29e4cf6ff04e83574c6b3f1bf8323bd49f..03fb918733e8930c8813434e14851ba55e39a9a3 100644 (file)
@@ -32,14 +32,14 @@ enum {
 
 extern const char *linkaddr_string(netdissect_options *, const u_char *, const unsigned int, const unsigned int);
 extern const char *etheraddr_string(netdissect_options *, const u_char *);
-extern const char *le64addr_string(const u_char *);
-extern const char *etherproto_string(u_short);
-extern const char *tcpport_string(u_short);
-extern const char *udpport_string(u_short);
-extern const char *isonsap_string(const u_char *, register u_int);
+extern const char *le64addr_string(netdissect_options *, const u_char *);
+extern const char *etherproto_string(netdissect_options *, u_short);
+extern const char *tcpport_string(netdissect_options *, u_short);
+extern const char *udpport_string(netdissect_options *, u_short);
+extern const char *isonsap_string(netdissect_options *, const u_char *, register u_int);
 extern const char *dnaddr_string(netdissect_options *, u_short);
-extern const char *protoid_string(const u_char *);
-extern const char *ipxsap_string(u_short);
+extern const char *protoid_string(netdissect_options *, const u_char *);
+extern const char *ipxsap_string(netdissect_options *, u_short);
 extern const char *getname(netdissect_options *, const u_char *);
 #ifdef INET6
 extern const char *getname6(netdissect_options *, const u_char *);
@@ -47,9 +47,9 @@ extern const char *getname6(netdissect_options *, const u_char *);
 extern const char *intoa(uint32_t);
 
 extern void init_addrtoname(netdissect_options *, uint32_t, uint32_t);
-extern struct hnamemem *newhnamemem(void);
+extern struct hnamemem *newhnamemem(netdissect_options *);
 #ifdef INET6
-extern struct h6namemem *newh6namemem(void);
+extern struct h6namemem *newh6namemem(netdissect_options *);
 #endif
 extern const char * ieee8021q_tci_string(const uint16_t);
 
index b41e15ac56168bd045922670a2b41bef9b663326..ba8e396c98989ec9ab32c9b384eeef2467caaecf 100644 (file)
@@ -138,7 +138,7 @@ ieee802_15_4_if_print(netdissect_options *ndo,
                case 0x03:
                        panid = EXTRACT_LE_16BITS(p);
                        p += 2;
-                       ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p)));
+                       ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p)));
                        p += 8;
                        break;
                }
@@ -164,7 +164,7 @@ ieee802_15_4_if_print(netdissect_options *ndo,
                                panid = EXTRACT_LE_16BITS(p);
                                p += 2;
                        }
-                        ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(p)));
+                        ND_PRINT((ndo,"%04x:%s ", panid, le64addr_string(ndo, p)));
                        p += 8;
                        break;
                }
index 6940d39353940e89b8c44e2ea07bdf5de1bdbf76..f3618d79951e1d71ba5eaff998f7a69437552f9f 100644 (file)
@@ -566,7 +566,7 @@ ataddr_string(netdissect_options *ndo,
                             tp->nxt; tp = tp->nxt)
                                ;
                        tp->addr = i2;
-                       tp->nxt = newhnamemem();
+                       tp->nxt = newhnamemem(ndo);
                        tp->name = strdup(nambuf);
                        if (tp->name == NULL)
                                (*ndo->ndo_error)(ndo,
@@ -584,7 +584,7 @@ ataddr_string(netdissect_options *ndo,
        for (tp2 = &hnametable[i & (HASHNAMESIZE-1)]; tp2->nxt; tp2 = tp2->nxt)
                if (tp2->addr == i) {
                        tp->addr = (atnet << 8) | athost;
-                       tp->nxt = newhnamemem();
+                       tp->nxt = newhnamemem(ndo);
                        (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
                            tp2->name, athost);
                        tp->name = strdup(nambuf);
@@ -595,7 +595,7 @@ ataddr_string(netdissect_options *ndo,
                }
 
        tp->addr = (atnet << 8) | athost;
-       tp->nxt = newhnamemem();
+       tp->nxt = newhnamemem(ndo);
        if (athost != 255)
                (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet, athost);
        else
index fa0d3701787b592f361eb555ac82c5183270a255..84241415a82c92fc655a627f332782a3d7e14d2f 100644 (file)
@@ -1211,7 +1211,7 @@ decode_clnp_prefix(netdissect_options *ndo,
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
        snprintf(buf, buflen, "%s/%d",
-                 isonsap_string(addr,(plen + 7) / 8),
+                 isonsap_string(ndo, addr,(plen + 7) / 8),
                  plen);
 
        return 1 + (plen + 7) / 8;
@@ -1248,7 +1248,7 @@ decode_labeled_vpn_clnp_prefix(netdissect_options *ndo,
         /* the label may get offsetted by 4 bits so lets shift it right */
        snprintf(buf, buflen, "RD: %s, %s/%d, label:%u %s",
                  bgp_vpn_rd_print(ndo, pptr+4),
-                 isonsap_string(addr,(plen + 7) / 8),
+                 isonsap_string(ndo, addr,(plen + 7) / 8),
                  plen,
                  EXTRACT_24BITS(pptr+1)>>4,
                  ((pptr[3]&1)==0) ? "(BOGUS: Bottom of Stack NOT set!)" : "(bottom)" );
@@ -1645,7 +1645,7 @@ bgp_attr_print(netdissect_options *ndo,
                         case (AFNUM_NSAP<<8 | SAFNUM_MULTICAST):
                         case (AFNUM_NSAP<<8 | SAFNUM_UNIMULTICAST):
                             ND_TCHECK2(tptr[0], tlen);
-                            ND_PRINT((ndo, "%s", isonsap_string(tptr, tlen)));
+                            ND_PRINT((ndo, "%s", isonsap_string(ndo, tptr, tlen)));
                             tptr += tlen;
                             tlen = 0;
                             break;
@@ -1660,7 +1660,7 @@ bgp_attr_print(netdissect_options *ndo,
                                 ND_TCHECK2(tptr[0], tlen);
                                 ND_PRINT((ndo, "RD: %s, %s",
                                        bgp_vpn_rd_print(ndo, tptr),
-                                       isonsap_string(tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
+                                       isonsap_string(ndo, tptr+BGP_VPN_RD_LEN,tlen-BGP_VPN_RD_LEN)));
                                 /* rfc986 mapped IPv4 address ? */
                                 if (EXTRACT_32BITS(tptr+BGP_VPN_RD_LEN) ==  0x47000601)
                                     ND_PRINT((ndo, " = %s", getname(ndo, tptr+BGP_VPN_RD_LEN+4)));
index a29115611e04a93e01a8c7f2f7365839db14c06b..e270cde17b63b121ca62bc116ed07b657ac867b0 100644 (file)
@@ -386,14 +386,14 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
                                (void)snprintf(buf, sizeof(buf),
                                        "%s tcp port %s unreachable",
                                        ipaddr_string(ndo, &oip->ip_dst),
-                                       tcpport_string(dport));
+                                       tcpport_string(ndo, dport));
                                break;
 
                        case IPPROTO_UDP:
                                (void)snprintf(buf, sizeof(buf),
                                        "%s udp port %s unreachable",
                                        ipaddr_string(ndo, &oip->ip_dst),
-                                       udpport_string(dport));
+                                       udpport_string(ndo, dport));
                                break;
 
                        default:
@@ -556,7 +556,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
        ND_PRINT((ndo, "ICMP %s, length %u", str, plen));
        if (ndo->ndo_vflag && !fragmented) { /* don't attempt checksumming if this is a frag */
                uint16_t sum, icmp_sum;
-               
+
                if (ND_TTEST2(*bp, plen)) {
                        vec[0].ptr = (const uint8_t *)(const void *)dp;
                        vec[0].len = plen;
index 19bf206dead85ba32a9a8b34485876deb9579f88..fbc77ec2c140447a7aa46a9d5851efa58dbd5f47 100644 (file)
@@ -957,12 +957,12 @@ icmp6_print(netdissect_options *ndo,
                        case IPPROTO_TCP:
                                ND_PRINT((ndo,", %s tcp port %s",
                                        ip6addr_string(ndo, &oip->ip6_dst),
-                                          tcpport_string(dport)));
+                                          tcpport_string(ndo, dport)));
                                break;
                        case IPPROTO_UDP:
                                ND_PRINT((ndo,", %s udp port %s",
                                        ip6addr_string(ndo, &oip->ip6_dst),
-                                          udpport_string(dport)));
+                                          udpport_string(ndo, dport)));
                                break;
                        default:
                                ND_PRINT((ndo,", %s protocol %d port %d unreachable",
index b24bbd2be1f9d6796037d38befdac9540b29cea1..b06ff613d7c049b278f6427aba655816e3b0f858 100644 (file)
@@ -164,7 +164,7 @@ ipx_sap_print(netdissect_options *ndo, const u_short *ipx, u_int length)
            ND_PRINT((ndo, "ipx-sap-nearest-req"));
 
        ND_TCHECK(ipx[0]);
-       ND_PRINT((ndo, " %s", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0])))));
+       ND_PRINT((ndo, " %s", ipxsap_string(ndo, htons(EXTRACT_16BITS(&ipx[0])))));
        break;
 
       case 2:
@@ -176,7 +176,7 @@ ipx_sap_print(netdissect_options *ndo, const u_short *ipx, u_int length)
 
        for (i = 0; i < 8 && length > 0; i++) {
            ND_TCHECK(ipx[0]);
-           ND_PRINT((ndo, " %s '", ipxsap_string(htons(EXTRACT_16BITS(&ipx[0])))));
+           ND_PRINT((ndo, " %s '", ipxsap_string(ndo, htons(EXTRACT_16BITS(&ipx[0])))));
            if (fn_printzp(ndo, (const u_char *)&ipx[1], 48, ndo->ndo_snapend)) {
                ND_PRINT((ndo, "'"));
                goto trunc;
index 5944286a63db8c76dcaa6eb8071d62641332ac1e..fb4c0b2606b3858bff0ceeb11ae62bd8aa2016b7 100644 (file)
@@ -807,8 +807,8 @@ clnp_print(netdissect_options *ndo,
         if (ndo->ndo_vflag < 1) {
             ND_PRINT((ndo, "%s%s > %s, %s, length %u",
                    ndo->ndo_eflag ? "" : ", ",
-                   isonsap_string(source_address, source_address_length),
-                   isonsap_string(dest_address, dest_address_length),
+                   isonsap_string(ndo, source_address, source_address_length),
+                   isonsap_string(ndo, dest_address, dest_address_length),
                    tok2str(clnp_pdu_values,"unknown (%u)",clnp_pdu_type),
                    length));
             return (1);
@@ -832,9 +832,9 @@ clnp_print(netdissect_options *ndo,
 
         ND_PRINT((ndo, "\n\tsource address (length %u): %s\n\tdest   address (length %u): %s",
                source_address_length,
-               isonsap_string(source_address, source_address_length),
+               isonsap_string(ndo, source_address, source_address_length),
                dest_address_length,
-               isonsap_string(dest_address, dest_address_length)));
+               isonsap_string(ndo, dest_address, dest_address_length)));
 
         if (clnp_flags & CLNP_SEGMENT_PART) {
                clnp_segment_header = (const struct clnp_segment_header_t *) pptr;
@@ -905,7 +905,7 @@ clnp_print(netdissect_options *ndo,
                                     ND_TCHECK2(*source_address, source_address_length);
                                     ND_PRINT((ndo, "\n\t    NSAP address (length %u): %s",
                                            source_address_length,
-                                           isonsap_string(source_address, source_address_length)));
+                                           isonsap_string(ndo, source_address, source_address_length)));
                             }
                             tlen-=source_address_length+1;
                     }
@@ -1111,7 +1111,7 @@ esis_print(netdissect_options *ndo,
                dst = pptr;
                pptr += dstl;
                 li -= dstl;
-               ND_PRINT((ndo, "\n\t  %s", isonsap_string(dst, dstl)));
+               ND_PRINT((ndo, "\n\t  %s", isonsap_string(ndo, dst, dstl)));
 
                ND_TCHECK(*pptr);
                if (li < 1) {
@@ -1148,7 +1148,7 @@ esis_print(netdissect_options *ndo,
                if (netal == 0)
                        ND_PRINT((ndo, "\n\t  %s", etheraddr_string(ndo, snpa)));
                else
-                       ND_PRINT((ndo, "\n\t  %s", isonsap_string(neta, netal)));
+                       ND_PRINT((ndo, "\n\t  %s", isonsap_string(ndo, neta, netal)));
                break;
        }
 
@@ -1181,7 +1181,7 @@ esis_print(netdissect_options *ndo,
                }
                 ND_PRINT((ndo, "\n\t  NET (length: %u): %s",
                        source_address_length,
-                       isonsap_string(pptr, source_address_length)));
+                       isonsap_string(ndo, pptr, source_address_length)));
                 pptr += source_address_length;
                 li -= source_address_length;
                 source_address_number--;
@@ -1203,7 +1203,7 @@ esis_print(netdissect_options *ndo,
                 ND_PRINT((ndo, ", bad ish/li"));
                 return;
             }
-            ND_PRINT((ndo, "\n\t  NET (length: %u): %s", source_address_length, isonsap_string(pptr, source_address_length)));
+            ND_PRINT((ndo, "\n\t  NET (length: %u): %s", source_address_length, isonsap_string(ndo, pptr, source_address_length)));
             pptr += source_address_length;
             li -= source_address_length;
             break;
@@ -2462,7 +2462,7 @@ isis_print(netdissect_options *ndo,
            while (tmp && alen < tmp) {
                ND_PRINT((ndo, "\n\t      Area address (length: %u): %s",
                        alen,
-                       isonsap_string(tptr, alen)));
+                       isonsap_string(ndo, tptr, alen)));
                tptr += alen;
                tmp -= alen + 1;
                if (tmp==0) /* if this is the last area address do not attemt a boundary check */
@@ -3020,7 +3020,7 @@ isis_print(netdissect_options *ndo,
                 if (!ND_TTEST2(*tptr, prefix_len / 2))
                     goto trunctlv;
                 ND_PRINT((ndo, "\n\t\tAddress: %s/%u",
-                       isonsap_string(tptr, prefix_len / 2), prefix_len * 4));
+                       isonsap_string(ndo, tptr, prefix_len / 2), prefix_len * 4));
                 tptr+=prefix_len/2;
                 tmp-=prefix_len/2;
             }
index fc2b0cccd5536494d01abc1a9fade0fd285b4ece..1821c2bad64777741c734fe650f57c006cbce838 100644 (file)
@@ -201,12 +201,12 @@ pgm_print(netdissect_options *ndo,
                if (ip6->ip6_nxt == IPPROTO_PGM) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                ip6addr_string(ndo, &ip6->ip6_src),
-                               tcpport_string(sport),
+                               tcpport_string(ndo, sport),
                                ip6addr_string(ndo, &ip6->ip6_dst),
-                               tcpport_string(dport)));
+                               tcpport_string(ndo, dport)));
                } else {
                        ND_PRINT((ndo, "%s > %s: ",
-                               tcpport_string(sport), tcpport_string(dport)));
+                               tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                }
        } else
 #endif /*INET6*/
@@ -214,12 +214,12 @@ pgm_print(netdissect_options *ndo,
                if (ip->ip_p == IPPROTO_PGM) {
                        ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                ipaddr_string(ndo, &ip->ip_src),
-                               tcpport_string(sport),
+                               tcpport_string(ndo, sport),
                                ipaddr_string(ndo, &ip->ip_dst),
-                               tcpport_string(dport)));
+                               tcpport_string(ndo, dport)));
                } else {
                        ND_PRINT((ndo, "%s > %s: ",
-                               tcpport_string(sport), tcpport_string(dport)));
+                               tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                }
        }
 
index 5374e8a45f1a1e3b93182abe4ad94783ee4711e7..a1d68a8adddaa0269a2f42007d0bb9581a076e1e 100644 (file)
@@ -194,12 +194,12 @@ tcp_print(netdissect_options *ndo,
                 if (ip6->ip6_nxt == IPPROTO_TCP) {
                         ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                      ip6addr_string(ndo, &ip6->ip6_src),
-                                     tcpport_string(sport),
+                                     tcpport_string(ndo, sport),
                                      ip6addr_string(ndo, &ip6->ip6_dst),
-                                     tcpport_string(dport)));
+                                     tcpport_string(ndo, dport)));
                 } else {
                         ND_PRINT((ndo, "%s > %s: ",
-                                     tcpport_string(sport), tcpport_string(dport)));
+                                     tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                 }
         } else
 #endif /*INET6*/
@@ -207,12 +207,12 @@ tcp_print(netdissect_options *ndo,
                 if (ip->ip_p == IPPROTO_TCP) {
                         ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                      ipaddr_string(ndo, &ip->ip_src),
-                                     tcpport_string(sport),
+                                     tcpport_string(ndo, sport),
                                      ipaddr_string(ndo, &ip->ip_dst),
-                                     tcpport_string(dport)));
+                                     tcpport_string(ndo, dport)));
                 } else {
                         ND_PRINT((ndo, "%s > %s: ",
-                                     tcpport_string(sport), tcpport_string(dport)));
+                                     tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
                 }
         }
 
index 1e02f2ea6104dc509017e443cca8bec262888867..d718f8565c23b90e8f78d5d17502e08f6426ba40 100644 (file)
@@ -306,15 +306,15 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
                        } else {
                                ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                        ip6addr_string(ndo, &ip6->ip6_src),
-                                       udpport_string(sport),
+                                       udpport_string(ndo, sport),
                                        ip6addr_string(ndo, &ip6->ip6_dst),
-                                       udpport_string(dport)));
+                                       udpport_string(ndo, dport)));
                        }
                } else {
                        if (sport != -1) {
                                ND_PRINT((ndo, "%s > %s: ",
-                                       udpport_string(sport),
-                                       udpport_string(dport)));
+                                       udpport_string(ndo, sport),
+                                       udpport_string(ndo, dport)));
                        }
                }
        } else
@@ -328,15 +328,15 @@ udpipaddr_print(netdissect_options *ndo, const struct ip *ip, int sport, int dpo
                        } else {
                                ND_PRINT((ndo, "%s.%s > %s.%s: ",
                                        ipaddr_string(ndo, &ip->ip_src),
-                                       udpport_string(sport),
+                                       udpport_string(ndo, sport),
                                        ipaddr_string(ndo, &ip->ip_dst),
-                                       udpport_string(dport)));
+                                       udpport_string(ndo, dport)));
                        }
                } else {
                        if (sport != -1) {
                                ND_PRINT((ndo, "%s > %s: ",
-                                       udpport_string(sport),
-                                       udpport_string(dport)));
+                                       udpport_string(ndo, sport),
+                                       udpport_string(ndo, dport)));
                        }
                }
        }
diff --git a/print.c b/print.c
index c7381c0a2528cb4ff8099d4ba8695c1db00c30c0..66a07ee1b7bcb74ad381337707df20af2b807027 100644 (file)
--- a/print.c
+++ b/print.c
@@ -311,10 +311,12 @@ get_print_info(netdissect_options *ndo, int type)
        if (printinfo.printer == NULL) {
                dltname = pcap_datalink_val_to_name(type);
                if (dltname != NULL)
-                       error("packet printing is not supported for link type %s: use -w",
-                             dltname);
+                       (*ndo->ndo_error)(ndo,
+                                         "packet printing is not supported for link type %s: use -w",
+                                         dltname);
                else
-                       error("packet printing is not supported for link type %d: use -w", type);
+                       (*ndo->ndo_error)(ndo,
+                                         "packet printing is not supported for link type %d: use -w", type);
        }
        return (printinfo);
 }