]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-decnet.c
Use more the EXTRACT_8BITS() macro to fetch a one-byte value (17/n)
[tcpdump] / print-decnet.c
index 41d022fc42b2bc267ccc026d45b1a78cd8d246ed..ad0b478f27884b05da3ac1cf2d33c94eab0a36c1 100644 (file)
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
+/* \summary: DECnet printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
 struct mbuf;
 struct rtentry;
@@ -324,7 +326,6 @@ union controlmsg
 #define COS_NONE 0                     /* no flow control */
 #define COS_SEGMENT 04                 /* segment flow control */
 #define COS_MESSAGE 010                        /* message flow control */
-#define COS_CRYPTSER 020               /* cryptographic services requested */
 #define COS_DEFAULT 1                  /* default value for field */
 
 #define COI_MASK 3                     /* mask for version field */
@@ -490,9 +491,6 @@ static void print_i_info(netdissect_options *, int);
 static int print_elist(const char *, u_int);
 static int print_nsp(netdissect_options *, const u_char *, u_int);
 static void print_reason(netdissect_options *, int);
-#ifdef PRINT_NSPDATA
-static void pdata(netdissect_options *, u_char *, u_int);
-#endif
 
 #ifndef HAVE_NETDNET_DNETDB_H_DNET_HTOA
 extern char *dnet_htoa(struct dn_naddr *);
@@ -528,7 +526,7 @@ decnet_print(netdissect_options *ndo,
 
        rhp = (const union routehdr *)&(ap[sizeof(short)]);
        ND_TCHECK(rhp->rh_short.sh_flags);
-       mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
+       mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
 
        if (mflags & RMF_PAD) {
            /* pad bytes of some sort in front of message */
@@ -544,7 +542,8 @@ decnet_print(netdissect_options *ndo,
            length -= padlen;
            caplen -= padlen;
            rhp = (const union routehdr *)&(ap[sizeof(short)]);
-           mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
+           ND_TCHECK(rhp->rh_short.sh_flags);
+           mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
        }
 
        if (mflags & RMF_FVER) {
@@ -571,7 +570,7 @@ decnet_print(netdissect_options *ndo,
                EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
            src =
                EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
-           hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits);
+           hops = EXTRACT_8BITS(rhp->rh_long.lg_visits);
            nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
            nsplen = length - sizeof(struct longhdr);
            break;
@@ -579,7 +578,7 @@ decnet_print(netdissect_options *ndo,
            ND_TCHECK(rhp->rh_short);
            dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
            src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
-           hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
+           hops = (EXTRACT_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
            nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
            nsplen = length - sizeof(struct shorthdr);
            break;
@@ -615,7 +614,8 @@ print_decnet_ctlmsg(netdissect_options *ndo,
                     register const union routehdr *rhp, u_int length,
                     u_int caplen)
 {
-       int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
+       /* Our caller has already checked for mflags */
+       int mflags = EXTRACT_8BITS(rhp->rh_short.sh_flags);
        register const union controlmsg *cmp = (const union controlmsg *)rhp;
        int src, dst, info, blksize, eco, ueco, hello, other, vers;
        etheraddr srcea, rtea;
@@ -630,11 +630,11 @@ print_decnet_ctlmsg(netdissect_options *ndo,
                goto trunc;
            ND_TCHECK(cmp->cm_init);
            src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
-           info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
+           info = EXTRACT_8BITS(cmp->cm_init.in_info);
            blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
-           vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers);
-           eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
-           ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
+           vers = EXTRACT_8BITS(cmp->cm_init.in_vers);
+           eco = EXTRACT_8BITS(cmp->cm_init.in_eco);
+           ueco = EXTRACT_8BITS(cmp->cm_init.in_ueco);
            hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
            print_t_info(ndo, info);
            ND_PRINT((ndo,
@@ -649,7 +649,7 @@ print_decnet_ctlmsg(netdissect_options *ndo,
                goto trunc;
            ND_TCHECK(cmp->cm_ver);
            src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
-           other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
+           other = EXTRACT_8BITS(cmp->cm_ver.ve_fcnval);
            ND_PRINT((ndo, "src %s fcnval %o", dnaddr_string(ndo, src), other));
            ret = 1;
            break;
@@ -659,7 +659,7 @@ print_decnet_ctlmsg(netdissect_options *ndo,
                goto trunc;
            ND_TCHECK(cmp->cm_test);
            src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
-           other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
+           other = EXTRACT_8BITS(cmp->cm_test.te_data);
            ND_PRINT((ndo, "src %s data %o", dnaddr_string(ndo, src), other));
            ret = 1;
            break;
@@ -688,15 +688,15 @@ print_decnet_ctlmsg(netdissect_options *ndo,
            if (length < sizeof(struct rhellomsg))
                goto trunc;
            ND_TCHECK(cmp->cm_rhello);
-           vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
-           eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
-           ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
+           vers = EXTRACT_8BITS(cmp->cm_rhello.rh_vers);
+           eco = EXTRACT_8BITS(cmp->cm_rhello.rh_eco);
+           ueco = EXTRACT_8BITS(cmp->cm_rhello.rh_ueco);
            memcpy((char *)&srcea, (const char *)&(cmp->cm_rhello.rh_src),
                sizeof(srcea));
            src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
-           info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info);
+           info = EXTRACT_8BITS(cmp->cm_rhello.rh_info);
            blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
-           priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
+           priority = EXTRACT_8BITS(cmp->cm_rhello.rh_priority);
            hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
            print_i_info(ndo, info);
            ND_PRINT((ndo,
@@ -711,20 +711,20 @@ print_decnet_ctlmsg(netdissect_options *ndo,
            if (length < sizeof(struct ehellomsg))
                goto trunc;
            ND_TCHECK(cmp->cm_ehello);
-           vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
-           eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
-           ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
+           vers = EXTRACT_8BITS(cmp->cm_ehello.eh_vers);
+           eco = EXTRACT_8BITS(cmp->cm_ehello.eh_eco);
+           ueco = EXTRACT_8BITS(cmp->cm_ehello.eh_ueco);
            memcpy((char *)&srcea, (const char *)&(cmp->cm_ehello.eh_src),
                sizeof(srcea));
            src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
-           info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info);
+           info = EXTRACT_8BITS(cmp->cm_ehello.eh_info);
            blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize);
            /*seed*/
            memcpy((char *)&rtea, (const char *)&(cmp->cm_ehello.eh_router),
                sizeof(rtea));
            dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
            hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
-           other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
+           other = EXTRACT_8BITS(cmp->cm_ehello.eh_data);
            print_i_info(ndo, info);
            ND_PRINT((ndo,
        "vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
@@ -860,7 +860,7 @@ print_nsp(netdissect_options *ndo,
        if (nsplen < sizeof(struct nsphdr))
                goto trunc;
        ND_TCHECK(*nsphp);
-       flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
+       flags = EXTRACT_8BITS(nsphp->nh_flags);
        dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
        src = EXTRACT_LE_16BITS(nsphp->nh_src);
 
@@ -875,9 +875,6 @@ print_nsp(netdissect_options *ndo,
                {
                    const struct seghdr *shp = (const struct seghdr *)nspp;
                    int ack;
-#ifdef PRINT_NSPDATA
-                   const u_char *dp;
-#endif
                    u_int data_off = sizeof(struct minseghdr);
 
                    if (nsplen < data_off)
@@ -907,13 +904,6 @@ print_nsp(netdissect_options *ndo,
                        }
                    }
                    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
-#ifdef PRINT_NSPDATA
-                   if (nsplen > data_off) {
-                       dp = &(nspp[data_off]);
-                       ND_TCHECK2(*dp, nsplen - data_off);
-                       pdata(ndo, dp, nsplen - data_off);
-                   }
-#endif
                }
                break;
            case MFS_ILS+MFS_INT:
@@ -921,9 +911,6 @@ print_nsp(netdissect_options *ndo,
                {
                    const struct seghdr *shp = (const struct seghdr *)nspp;
                    int ack;
-#ifdef PRINT_NSPDATA
-                   const u_char *dp;
-#endif
                    u_int data_off = sizeof(struct minseghdr);
 
                    if (nsplen < data_off)
@@ -953,13 +940,6 @@ print_nsp(netdissect_options *ndo,
                        }
                    }
                    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
-#ifdef PRINT_NSPDATA
-                   if (nsplen > data_off) {
-                       dp = &(nspp[data_off]);
-                       ND_TCHECK2(*dp, nsplen - data_off);
-                       pdata(ndo, dp, nsplen - data_off);
-                   }
-#endif
                }
                break;
            case MFS_ILS:
@@ -993,8 +973,8 @@ print_nsp(netdissect_options *ndo,
                    }
                    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
                    ND_TCHECK(*lsmp);
-                   lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
-                   fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
+                   lsflags = EXTRACT_8BITS(lsmp->ls_lsflags);
+                   fcval = EXTRACT_8BITS(lsmp->ls_fcval);
                    switch (lsflags & LSI_MASK) {
                    case LSI_DATA:
                        ND_PRINT((ndo, "dat seg count %d ", fcval));
@@ -1099,15 +1079,12 @@ print_nsp(netdissect_options *ndo,
                {
                    const struct cimsg *cimp = (const struct cimsg *)nspp;
                    int services, info, segsize;
-#ifdef PRINT_NSPDATA
-                   const u_char *dp;
-#endif
 
                    if (nsplen < sizeof(struct cimsg))
                        goto trunc;
                    ND_TCHECK(*cimp);
-                   services = EXTRACT_LE_8BITS(cimp->ci_services);
-                   info = EXTRACT_LE_8BITS(cimp->ci_info);
+                   services = EXTRACT_8BITS(cimp->ci_services);
+                   info = EXTRACT_8BITS(cimp->ci_info);
                    segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
 
                    switch (services & COS_MASK) {
@@ -1119,9 +1096,6 @@ print_nsp(netdissect_options *ndo,
                    case COS_MESSAGE:
                        ND_PRINT((ndo, "msg "));
                        break;
-                   case COS_CRYPTSER:
-                       ND_PRINT((ndo, "crypt "));
-                       break;
                    }
                    switch (info & COI_MASK) {
                    case COI_32:
@@ -1138,13 +1112,6 @@ print_nsp(netdissect_options *ndo,
                        break;
                    }
                    ND_PRINT((ndo, "segsize %d ", segsize));
-#ifdef PRINT_NSPDATA
-                   if (nsplen > sizeof(struct cimsg)) {
-                       dp = &(nspp[sizeof(struct cimsg)]);
-                       ND_TCHECK2(*dp, nsplen - sizeof(struct cimsg));
-                       pdata(ndo, dp, nsplen - sizeof(struct cimsg));
-                   }
-#endif
                }
                break;
            case MFS_CC:
@@ -1153,17 +1120,14 @@ print_nsp(netdissect_options *ndo,
                    const struct ccmsg *ccmp = (const struct ccmsg *)nspp;
                    int services, info;
                    u_int segsize, optlen;
-#ifdef PRINT_NSPDATA
-                   const u_char *dp;
-#endif
 
                    if (nsplen < sizeof(struct ccmsg))
                        goto trunc;
                    ND_TCHECK(*ccmp);
-                   services = EXTRACT_LE_8BITS(ccmp->cc_services);
-                   info = EXTRACT_LE_8BITS(ccmp->cc_info);
+                   services = EXTRACT_8BITS(ccmp->cc_services);
+                   info = EXTRACT_8BITS(ccmp->cc_info);
                    segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
-                   optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen);
+                   optlen = EXTRACT_8BITS(ccmp->cc_optlen);
 
                    switch (services & COS_MASK) {
                    case COS_NONE:
@@ -1174,9 +1138,6 @@ print_nsp(netdissect_options *ndo,
                    case COS_MESSAGE:
                        ND_PRINT((ndo, "msg "));
                        break;
-                   case COS_CRYPTSER:
-                       ND_PRINT((ndo, "crypt "));
-                       break;
                    }
                    switch (info & COI_MASK) {
                    case COI_32:
@@ -1195,13 +1156,6 @@ print_nsp(netdissect_options *ndo,
                    ND_PRINT((ndo, "segsize %d ", segsize));
                    if (optlen) {
                        ND_PRINT((ndo, "optlen %d ", optlen));
-#ifdef PRINT_NSPDATA
-                       if (optlen > nsplen - sizeof(struct ccmsg))
-                           goto trunc;
-                       dp = &(nspp[sizeof(struct ccmsg)]);
-                       ND_TCHECK2(*dp, optlen);
-                       pdata(ndo, dp, optlen);
-#endif
                    }
                }
                break;
@@ -1211,26 +1165,16 @@ print_nsp(netdissect_options *ndo,
                    const struct dimsg *dimp = (const struct dimsg *)nspp;
                    int reason;
                    u_int optlen;
-#ifdef PRINT_NSPDATA
-                   const u_char *dp;
-#endif
 
                    if (nsplen < sizeof(struct dimsg))
                        goto trunc;
                    ND_TCHECK(*dimp);
                    reason = EXTRACT_LE_16BITS(dimp->di_reason);
-                   optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
+                   optlen = EXTRACT_8BITS(dimp->di_optlen);
 
                    print_reason(ndo, reason);
                    if (optlen) {
                        ND_PRINT((ndo, "optlen %d ", optlen));
-#ifdef PRINT_NSPDATA
-                       if (optlen > nsplen - sizeof(struct dimsg))
-                           goto trunc;
-                       dp = &(nspp[sizeof(struct dimsg)]);
-                       ND_TCHECK2(*dp, optlen);
-                       pdata(ndo, dp, optlen);
-#endif
                    }
                }
                break;
@@ -1327,18 +1271,3 @@ dnname_string(netdissect_options *ndo, u_short dnaddr)
        return(dnnum_string(ndo, dnaddr));      /* punt */
 #endif
 }
-
-#ifdef PRINT_NSPDATA
-static void
-pdata(netdissect_options *ndo,
-      u_char *dp, u_int maxlen)
-{
-       char c;
-       u_int x = maxlen;
-
-       while (x-- > 0) {
-           c = *dp++;
-           safeputchar(ndo, c);
-       }
-}
-#endif