]> The Tcpdump Group git mirrors - tcpdump/commitdiff
NDOize IP mobile, MSDP and NULL decoders
authorDenis Ovsienko <[email protected]>
Thu, 6 Mar 2014 16:41:44 +0000 (20:41 +0400)
committerDenis Ovsienko <[email protected]>
Thu, 6 Mar 2014 17:08:17 +0000 (21:08 +0400)
interface.h
netdissect.h
print-ip.c
print-mobile.c
print-msdp.c
print-null.c
print-tcp.c
tcpdump.c

index 5613777ed961175e812dd364f585040a81005420..49372ac8f9bc6992bfa32c0c2cacc5026157a10b 100644 (file)
@@ -223,7 +223,6 @@ extern void isoclns_print(const u_char *, u_int, u_int);
 extern void krb_print(const u_char *);
 extern u_int llap_print(const u_char *, u_int);
 extern u_int ltalk_if_print(const struct pcap_pkthdr *, const u_char *);
-extern void msdp_print(const unsigned char *, u_int);
 extern void nfsreply_print(const u_char *, u_int, const u_char *);
 extern void nfsreply_print_noaddr(const u_char *, u_int, const u_char *);
 extern void nfsreq_print(const u_char *, u_int, const u_char *);
@@ -231,7 +230,6 @@ extern void nfsreq_print_noaddr(const u_char *, u_int, const u_char *);
 extern void ns_print(const u_char *, u_int, int);
 extern const u_char * ns_nprint (register const u_char *, register const u_char *);
 extern void ntp_print(const u_char *, u_int);
-extern u_int null_if_print(const struct pcap_pkthdr *, const u_char *);
 extern void openflow_print(const u_char *, const u_int);
 extern void ospf_print(const u_char *, u_int, const u_char *);
 extern void olsr_print (const u_char *, u_int, int);
@@ -246,7 +244,6 @@ extern void lspping_print(const u_char *, u_int);
 extern void lwapp_control_print(const u_char *, u_int, int);
 extern void lwapp_data_print(const u_char *, u_int);
 extern void eigrp_print(const u_char *, u_int);
-extern void mobile_print(const u_char *, u_int);
 extern void pim_print(const u_char *, u_int, u_int);
 extern u_int pppoe_print(const u_char *, u_int);
 extern u_int ppp_print(register const u_char *, u_int);
index adf8c2e4fa831e46dd035f49a2041e0d3145930a..e55502983ad6dbf81952c4f3ce860b7d44288a7c 100644 (file)
@@ -377,6 +377,9 @@ extern u_int ipfc_if_print(netdissect_options *, const struct pcap_pkthdr *, con
 extern void udld_print(netdissect_options *, const u_char *, u_int);
 extern void hsrp_print(netdissect_options *, const u_char *, u_int);
 extern void igrp_print(netdissect_options *, const u_char *, u_int);
+extern void msdp_print(netdissect_options *, const u_char *, u_int);
+extern u_int null_if_print(netdissect_options *, const struct pcap_pkthdr *, const u_char *);
+extern void mobile_print(netdissect_options *, const u_char *, u_int);
 
 /* stuff that has not yet been rototiled */
 extern const u_char * ns_nprint (register const u_char *, register const u_char *);
index 9639be43509e7a74c53bab16e731baab32a92bf7..6e76ecf39fb72c54d6de0bcbaa5c3bcdd4106277 100644 (file)
@@ -449,7 +449,7 @@ again:
                break;
 
        case IPPROTO_MOBILE:
-               mobile_print(ipds->cp, ipds->len);
+               mobile_print(ndo, ipds->cp, ipds->len);
                break;
 
        case IPPROTO_PIM:
index e8e0acce1f65c1e01d5a83db71b8a40c22c54d88..cebbea045cfd40ad391b780f6272f90ec071af56 100644 (file)
@@ -42,8 +42,6 @@
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-
 #include "interface.h"
 #include "addrtoname.h"
 #include "extract.h"           /* must come after interface.h */
@@ -63,7 +61,7 @@ struct mobile_ip {
  * Deencapsulate and print a mobile-tunneled IP datagram
  */
 void
-mobile_print(const u_char *bp, u_int length)
+mobile_print(netdissect_options *ndo, const u_char *bp, u_int length)
 {
        const struct mobile_ip *mob;
        struct cksum_vec vec[1];
@@ -72,11 +70,11 @@ mobile_print(const u_char *bp, u_int length)
 
        mob = (const struct mobile_ip *)bp;
 
-       if (length < MOBILE_SIZE || !TTEST(*mob)) {
-               fputs("[|mobile]", stdout);
+       if (length < MOBILE_SIZE || !ND_TTEST(*mob)) {
+               ND_PRINT((ndo, "[|mobile]"));
                return;
        }
-       fputs("mobile: ", stdout);
+       ND_PRINT((ndo, "mobile: "));
 
        proto = EXTRACT_16BITS(&mob->proto);
        crc =  EXTRACT_16BITS(&mob->hcheck);
@@ -85,21 +83,19 @@ mobile_print(const u_char *bp, u_int length)
        }
 
        if (osp)  {
-               fputs("[S] ",stdout);
-               if (vflag)
-                       (void)printf("%s ",ipaddr_string(&mob->osrc));
+               ND_PRINT((ndo, "[S] "));
+               if (ndo->ndo_vflag)
+                       ND_PRINT((ndo, "%s ", ipaddr_string(&mob->osrc)));
        } else {
-               fputs("[] ",stdout);
+               ND_PRINT((ndo, "[] "));
        }
-       if (vflag) {
-               (void)printf("> %s ",ipaddr_string(&mob->odst));
-               (void)printf("(oproto=%d)",proto>>8);
+       if (ndo->ndo_vflag) {
+               ND_PRINT((ndo, "> %s ", ipaddr_string(&mob->odst)));
+               ND_PRINT((ndo, "(oproto=%d)", proto>>8));
        }
        vec[0].ptr = (const u_int8_t *)(void *)mob;
        vec[0].len = osp ? 12 : 8;
        if (in_cksum(vec, 1)!=0) {
-               (void)printf(" (bad checksum %d)",crc);
+               ND_PRINT((ndo, " (bad checksum %d)", crc));
        }
-
-       return;
 }
index e1ec2b42d6007c105a98bef42fc0063572913fa3..ce466da9661dc2a90bd692a3ec016099cf4dbcd8 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "interface.h"
+#include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
 
 #define MSDP_TYPE_MAX  7
 
 void
-msdp_print(const unsigned char *sp, u_int length)
+msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
 {
        unsigned int type, len;
 
-       TCHECK2(*sp, 3);
+       ND_TCHECK2(*sp, 3);
        /* See if we think we're at the beginning of a compound packet */
        type = *sp;
        len = EXTRACT_16BITS(sp + 1);
        if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
                goto trunc;     /* not really truncated, but still not decodable */
-       (void)printf(" msdp:");
+       ND_PRINT((ndo, " msdp:"));
        while (length > 0) {
-               TCHECK2(*sp, 3);
+               ND_TCHECK2(*sp, 3);
                type = *sp;
                len = EXTRACT_16BITS(sp + 1);
-               if (len > 1400 || vflag)
-                       printf(" [len %u]", len);
+               if (len > 1400 || ndo->ndo_vflag)
+                       ND_PRINT((ndo, " [len %u]", len));
                if (len < 3)
                        goto trunc;
                sp += 3;
@@ -57,35 +54,35 @@ msdp_print(const unsigned char *sp, u_int length)
                case 1: /* IPv4 Source-Active */
                case 3: /* IPv4 Source-Active Response */
                        if (type == 1)
-                               (void)printf(" SA");
+                               ND_PRINT((ndo, " SA"));
                        else
-                               (void)printf(" SA-Response");
-                       TCHECK(*sp);
-                       (void)printf(" %u entries", *sp);
+                               ND_PRINT((ndo, " SA-Response"));
+                       ND_TCHECK(*sp);
+                       ND_PRINT((ndo, " %u entries", *sp));
                        if ((u_int)((*sp * 12) + 8) < len) {
-                               (void)printf(" [w/data]");
-                               if (vflag > 1) {
-                                       (void)printf(" ");
-                                       ip_print(gndo, sp + *sp * 12 + 8 - 3,
+                               ND_PRINT((ndo, " [w/data]"));
+                               if (ndo->ndo_vflag > 1) {
+                                       ND_PRINT((ndo, " "));
+                                       ip_print(ndo, sp + *sp * 12 + 8 - 3,
                                                 len - (*sp * 12 + 8));
                                }
                        }
                        break;
                case 2:
-                       (void)printf(" SA-Request");
-                       TCHECK2(*sp, 5);
-                       (void)printf(" for %s", ipaddr_string(sp + 1));
+                       ND_PRINT((ndo, " SA-Request"));
+                       ND_TCHECK2(*sp, 5);
+                       ND_PRINT((ndo, " for %s", ipaddr_string(sp + 1)));
                        break;
                case 4:
-                       (void)printf(" Keepalive");
+                       ND_PRINT((ndo, " Keepalive"));
                        if (len != 3)
-                               (void)printf("[len=%d] ", len);
+                               ND_PRINT((ndo, "[len=%d] ", len));
                        break;
                case 5:
-                       (void)printf(" Notification");
+                       ND_PRINT((ndo, " Notification"));
                        break;
                default:
-                       (void)printf(" [type=%d len=%d]", type, len);
+                       ND_PRINT((ndo, " [type=%d len=%d]", type, len));
                        break;
                }
                sp += (len - 3);
@@ -93,7 +90,7 @@ msdp_print(const unsigned char *sp, u_int length)
        }
        return;
 trunc:
-       (void)printf(" [|msdp]");
+       ND_PRINT((ndo, " [|msdp]"));
 }
 
 /*
index a4011c1439e0e3ebf3158e3d4f6deb06a4a46f1a..be9d65f9e737559c1bb3a1e9203f1c49d0c52a35 100644 (file)
 
 #include <tcpdump-stdinc.h>
 
-#include <stdio.h>
 #include <string.h>
 
 #include "interface.h"
-
-#include "ip.h"
-#ifdef INET6
-#include "ip6.h"
-#endif
 #include "af.h"
 
 /*
 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
 
 static inline void
-null_hdr_print(u_int family, u_int length)
+null_hdr_print(netdissect_options *ndo, u_int family, u_int length)
 {
-       if (!qflag) {
-               (void)printf("AF %s (%u)",
-                       tok2str(bsd_af_values,"Unknown",family),family);
+       if (!ndo->ndo_qflag) {
+               ND_PRINT((ndo, "AF %s (%u)",
+                       tok2str(bsd_af_values,"Unknown",family),family));
        } else {
-               (void)printf("%s",
-                       tok2str(bsd_af_values,"Unknown AF %u",family));
+               ND_PRINT((ndo, "%s",
+                       tok2str(bsd_af_values,"Unknown AF %u",family)));
        }
 
-       (void)printf(", length %u: ", length);
+       ND_PRINT((ndo, ", length %u: ", length));
 }
 
 /*
@@ -77,14 +71,14 @@ null_hdr_print(u_int family, u_int length)
  * is the number of bytes actually captured.
  */
 u_int
-null_if_print(const struct pcap_pkthdr *h, const u_char *p)
+null_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
 {
        u_int length = h->len;
        u_int caplen = h->caplen;
        u_int family;
 
        if (caplen < NULL_HDRLEN) {
-               printf("[|null]");
+               ND_PRINT((ndo, "[|null]"));
                return (NULL_HDRLEN);
        }
 
@@ -101,8 +95,8 @@ null_if_print(const struct pcap_pkthdr *h, const u_char *p)
        if ((family & 0xFFFF0000) != 0)
                family = SWAPLONG(family);
 
-       if (eflag)
-               null_hdr_print(family, length);
+       if (ndo->ndo_eflag)
+               null_hdr_print(ndo, family, length);
 
        length -= NULL_HDRLEN;
        caplen -= NULL_HDRLEN;
@@ -111,14 +105,14 @@ null_if_print(const struct pcap_pkthdr *h, const u_char *p)
        switch (family) {
 
        case BSD_AFNUM_INET:
-               ip_print(gndo, p, length);
+               ip_print(ndo, p, length);
                break;
 
 #ifdef INET6
        case BSD_AFNUM_INET6_BSD:
        case BSD_AFNUM_INET6_FREEBSD:
        case BSD_AFNUM_INET6_DARWIN:
-               ip6_print(gndo, p, length);
+               ip6_print(ndo, p, length);
                break;
 #endif
 
@@ -136,10 +130,10 @@ null_if_print(const struct pcap_pkthdr *h, const u_char *p)
 
        default:
                /* unknown AF_ value */
-               if (!eflag)
-                       null_hdr_print(family, length + NULL_HDRLEN);
-               if (!suppress_default_print)
-                       default_print(p, caplen);
+               if (!ndo->ndo_eflag)
+                       null_hdr_print(ndo, family, length + NULL_HDRLEN);
+               if (!ndo->ndo_suppress_default_print)
+                       ndo->ndo_default_print(ndo, p, caplen);
        }
 
        return (NULL_HDRLEN);
index 2b470f5929c58df18052897d525a35089d2a626f..7eb13b376ba3c4fb8d5e57a3eca5d8a2ac54a739 100644 (file)
@@ -695,7 +695,7 @@ tcp_print(register const u_char *bp, register u_int length,
                  */
                 ns_print(bp + 2, length - 2, 0);
         } else if (sport == MSDP_PORT || dport == MSDP_PORT) {
-                msdp_print(bp, length);
+                msdp_print(gndo, bp, length);
         } else if (sport == RPKI_RTR_PORT || dport == RPKI_RTR_PORT) {
                 rpki_rtr_print(bp, length);
         }
index daee688ee65653fa4aa359faefa84a7f14ad3660..aeb43cc4f55050bcd41193326bc76fe10148d09e 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -187,10 +187,6 @@ static const struct printer printers[] = {
        { ppp_bsdos_if_print,   DLT_PPP_BSDOS },
 #endif
        { fddi_if_print,        DLT_FDDI },
-       { null_if_print,        DLT_NULL },
-#ifdef DLT_LOOP
-       { null_if_print,        DLT_LOOP },
-#endif
        { raw_if_print,         DLT_RAW },
        { atm_if_print,         DLT_ATM_RFC1483 },
 #ifdef DLT_C_HDLC
@@ -343,6 +339,10 @@ static const struct ndo_printer ndo_printers[] = {
 #endif
 #ifdef DLT_IP_OVER_FC
        { ipfc_if_print,        DLT_IP_OVER_FC },
+#endif
+       { null_if_print,        DLT_NULL },
+#ifdef DLT_LOOP
+       { null_if_print,        DLT_LOOP },
 #endif
        { NULL,                 0 },
 };