]> The Tcpdump Group git mirrors - tcpdump/commitdiff
code cosmetics:
authorhannes <hannes>
Mon, 11 Jul 2005 20:15:31 +0000 (20:15 +0000)
committerhannes <hannes>
Mon, 11 Jul 2005 20:15:31 +0000 (20:15 +0000)
  at places where the entity to print / or increment
  shares the semantics of an IPv4 or IPv6 address
  use sizeof(in_addr) and sizeof(in6_addr),
  rather than a hardcoded 4 or 16

print-icmp6.c
print-isoclns.c
print-ldp.c
print-pim.c
print-rsvp.c

index 4c81fde897acddee531551f3efc8dcb122bbc541..59b5375dada1e0f157e31972b2357a7ca133606b 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.83 2005-05-14 00:42:28 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-icmp6.c,v 1.84 2005-07-11 20:15:31 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -764,13 +764,13 @@ mldv2_report_print(const u_char *bp, u_int len)
                printf(" [invalid number of groups]");
                return;
            }
-            TCHECK2(bp[group + 4], 16);
+            TCHECK2(bp[group + 4], sizeof(struct in6_addr));
             printf(" [gaddr %s", ip6addr_string(&bp[group + 4]));
            printf(" %s", tok2str(mldv2report2str, " [v2-report-#%d]",
                                                                bp[group]));
             nsrcs = (bp[group + 2] << 8) + bp[group + 3];
            /* Check the number of sources and print them */
-           if (len < group + 20 + (nsrcs * 16)) {
+           if (len < group + 20 + (nsrcs * sizeof(struct in6_addr))) {
                printf(" [invalid number of sources %d]", nsrcs);
                return;
            }
@@ -780,13 +780,14 @@ mldv2_report_print(const u_char *bp, u_int len)
                /* Print the sources */
                 (void)printf(" {");
                 for (j = 0; j < nsrcs; j++) {
-                    TCHECK2(bp[group + 20 + j * 16], 16);
-                   printf(" %s", ip6addr_string(&bp[group + 20 + j * 16]));
+                    TCHECK2(bp[group + 20 + j * sizeof(struct in6_addr)],
+                            sizeof(struct in6_addr));
+                   printf(" %s", ip6addr_string(&bp[group + 20 + j * sizeof(struct in6_addr)]));
                }
                 (void)printf(" }");
             }
            /* Next group record */
-            group += 20 + nsrcs * 16;
+            group += 20 + nsrcs * sizeof(struct in6_addr);
            printf("]");
         }
     }
@@ -820,7 +821,7 @@ mldv2_query_print(const u_char *bp, u_int len)
     if (vflag) {
        (void)printf(" [max resp delay=%d]", mrt);
     }
-    TCHECK2(bp[8], 16);
+    TCHECK2(bp[8], sizeof(struct in6_addr));
     printf(" [gaddr %s", ip6addr_string(&bp[8]));
 
     if (vflag) {
@@ -842,13 +843,14 @@ mldv2_query_print(const u_char *bp, u_int len)
     TCHECK2(bp[26], 2);
     nsrcs = ntohs(*(u_short *)&bp[26]);
     if (nsrcs > 0) {
-       if (len < 28 + nsrcs * 16)
+       if (len < 28 + nsrcs * sizeof(struct in6_addr))
            printf(" [invalid number of sources]");
        else if (vflag > 1) {
            printf(" {");
            for (i = 0; i < nsrcs; i++) {
-               TCHECK2(bp[28 + i * 16], 16);
-               printf(" %s", ip6addr_string(&bp[28 + i * 16]));
+               TCHECK2(bp[28 + i * sizeof(struct in6_addr)],
+                        sizeof(struct in6_addr));
+               printf(" %s", ip6addr_string(&bp[28 + i * sizeof(struct in6_addr)]));
            }
            printf(" }");
        } else
index e5471645f4b798019fdee279830c0398bc33c4f1..a75aee7e13fe24ee9552b976a8cee87e5fe0ff37 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.146 2005-07-11 12:58:12 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.147 2005-07-11 20:15:32 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -1399,9 +1399,9 @@ trunctlv:
  */
 
 static int
-isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *ident) {
+isis_print_is_reach_subtlv (const u_int8_t *tptr,u_int subt,u_int subl,const char *ident) {
 
-        int priority_level,bandwidth_constraint;
+        u_int priority_level,bandwidth_constraint;
         union { /* int to float conversion buffer for several subTLVs */
             float f; 
             u_int32_t i;
@@ -1431,7 +1431,7 @@ isis_print_is_reach_subtlv (const u_int8_t *tptr,int subt,int subl,const char *i
            break;
         case ISIS_SUBTLV_EXT_IS_REACH_IPV4_INTF_ADDR:
         case ISIS_SUBTLV_EXT_IS_REACH_IPV4_NEIGHBOR_ADDR:
-            if (subl >= 4)
+            if (subl >= sizeof(struct in_addr))
               printf(", %s", ipaddr_string(tptr));
             break;
         case ISIS_SUBTLV_EXT_IS_REACH_MAX_LINK_BW :
@@ -1605,7 +1605,7 @@ static int
 isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi) {
 
     char ident_buffer[20];
-    u_int8_t prefix[16]; /* shared copy buffer for IPv4 and IPv6 prefixes */
+    u_int8_t prefix[sizeof(struct in6_addr)]; /* shared copy buffer for IPv4 and IPv6 prefixes */
     u_int metric, status_byte, bit_length, byte_length, sublen, processed, subtlvtype, subtlvlen;
 
     if (!TTEST2(*tptr, 4))
@@ -1635,7 +1635,7 @@ isis_print_extd_ip_reach (const u_int8_t *tptr, const char *ident, u_int16_t afi
    
     if (!TTEST2(*tptr, byte_length))
         return (0);
-    memset(prefix, 0, 16);              /* clear the copy buffer */
+    memset(prefix, 0, sizeof(struct in6_addr));              /* clear the copy buffer */
     memcpy(prefix,tptr,byte_length);    /* copy as much as is stored in the TLV */
     tptr+=byte_length;
     processed+=byte_length;
@@ -2263,15 +2263,15 @@ static int isis_print (const u_int8_t *p, u_int length)
            break;
 
        case ISIS_TLV_IP6ADDR:
-           while (tmp>=16) {
-               if (!TTEST2(*tptr, 16))
+           while (tmp>=sizeof(struct in6_addr)) {
+               if (!TTEST2(*tptr, sizeof(struct in6_addr)))
                    goto trunctlv;
 
                 printf("\n\t      IPv6 interface address: %s",
                       ip6addr_string(tptr));
 
-               tptr += 16;
-               tmp -= 16;
+               tptr += sizeof(struct in6_addr);
+               tmp -= sizeof(struct in6_addr);
            }
            break;
 #endif
@@ -2361,18 +2361,18 @@ static int isis_print (const u_int8_t *p, u_int length)
            break;
 
        case ISIS_TLV_TE_ROUTER_ID:
-           if (!TTEST2(*pptr, 4))
+           if (!TTEST2(*pptr, sizeof(struct in_addr)))
                goto trunctlv;
            printf("\n\t      Traffic Engineering Router ID: %s", ipaddr_string(pptr));
            break;
 
        case ISIS_TLV_IPADDR:
-           while (tmp>=4) {
-               if (!TTEST2(*tptr, 4))
+           while (tmp>=sizeof(struct in_addr)) {
+               if (!TTEST2(*tptr, sizeof(struct in_addr)))
                    goto trunctlv;
                printf("\n\t      IPv4 interface address: %s", ipaddr_string(tptr));
-               tptr += 4;
-               tmp -= 4;
+               tptr += sizeof(struct in_addr);
+               tmp -= sizeof(struct in_addr);
            }
            break;
 
@@ -2402,21 +2402,21 @@ static int isis_print (const u_int8_t *p, u_int length)
            printf(", Flags: [%s]", ISIS_MASK_TLV_SHARED_RISK_GROUP(*tptr++) ? "numbered" : "unnumbered");
            tmp--;
 
-           if (tmp < 4)
+           if (tmp < sizeof(struct in_addr))
                break;
-           if (!TTEST2(*tptr,4))
+           if (!TTEST2(*tptr,sizeof(struct in_addr)))
                 goto trunctlv;
            printf("\n\t      IPv4 interface address: %s", ipaddr_string(tptr));
-           tptr+=4;
-           tmp-=4;
+           tptr+=sizeof(struct in_addr);
+           tmp-=sizeof(struct in_addr);
 
-           if (tmp < 4)
+           if (tmp < sizeof(struct in_addr))
                break;
-           if (!TTEST2(*tptr,4))
+           if (!TTEST2(*tptr,sizeof(struct in_addr)))
                 goto trunctlv;
            printf("\n\t      IPv4 neighbor address: %s", ipaddr_string(tptr));
-           tptr+=4;
-           tmp-=4;
+           tptr+=sizeof(struct in_addr);
+           tmp-=sizeof(struct in_addr);
 
            while (tmp>=4) {
                 if (!TTEST2(*tptr, 4))
index a3e7a2dc1f7d5e1b4ce9f03008e6d144c029e4fa..c8bec13564be8bd88bce5d2011ef71c7ec1bb86f 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.14 2005-06-16 01:10:21 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.15 2005-07-11 20:15:32 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -302,7 +302,7 @@ ldp_tlv_print(register const u_char *tptr) {
            printf("IPv4, addresses:");
            for (i=0; i<(tlv_tlen-2)/4; i++) {
                printf(" %s",ipaddr_string(tptr));
-               tptr+=4;
+               tptr+=sizeof(struct in_addr);
            }
        }
 #ifdef INET6
@@ -310,7 +310,7 @@ ldp_tlv_print(register const u_char *tptr) {
            printf("IPv6, addresses:");
            for (i=0; i<(tlv_tlen-2)/16; i++) {
                printf(" %s",ip6addr_string(tptr));
-               tptr+=16;
+               tptr+=sizeof(struct in6_addr);
            }
        }
 #endif
index cc338f119d4f79506cd523aeaf105f75dc9d1a1b..ba7d22ce060514e188377f0e7c4791318330dcad 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.47 2005-04-20 22:08:27 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-pim.c,v 1.48 2005-07-11 20:15:33 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -140,7 +140,7 @@ pimv1_join_prune_print(register const u_char *bp, register u_int len)
                return;
        }
 
-       TCHECK2(bp[0], 4);
+       TCHECK2(bp[0], sizeof(struct in_addr));
        if (vflag > 1)
                (void)printf("\n");
        (void)printf(" Upstream Nbr: %s", ipaddr_string(bp));
@@ -165,9 +165,9 @@ pimv1_join_prune_print(register const u_char *bp, register u_int len)
                 * XXX - does the address have length "addrlen" and the
                 * mask length "maddrlen"?
                 */
-               TCHECK2(bp[0], 4);
+               TCHECK2(bp[0], sizeof(struct in_addr));
                (void)printf("\n\tGroup: %s", ipaddr_string(bp));
-               TCHECK2(bp[4], 4);
+               TCHECK2(bp[4], sizeof(struct in_addr));
                if (EXTRACT_32BITS(&bp[4]) != 0xffffffff)
                        (void)printf("/%s", ipaddr_string(&bp[4]));
                TCHECK2(bp[8], 4);
@@ -247,7 +247,7 @@ pimv1_print(register const u_char *bp, register u_int len)
                break;
        case 2:
                (void)printf(" Register-Stop");
-               TCHECK2(bp[12], 4);
+               TCHECK2(bp[12], sizeof(struct in_addr));
                (void)printf(" for %s > %s", ipaddr_string(&bp[8]),
                    ipaddr_string(&bp[12]));
                break;
@@ -270,7 +270,7 @@ pimv1_print(register const u_char *bp, register u_int len)
                break;
        case 5:
                (void)printf(" Assert");
-               TCHECK2(bp[16], 4);
+               TCHECK2(bp[16], sizeof(struct in_addr));
                (void)printf(" for %s > %s", ipaddr_string(&bp[16]),
                    ipaddr_string(&bp[8]));
                if (EXTRACT_32BITS(&bp[12]) != 0xffffffff)
@@ -520,12 +520,12 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
                switch (bp[0]) {
                case 1:
                        af = AF_INET;
-                       len = 4;
+                       len = sizeof(struct in_addr);
                        break;
 #ifdef INET6
                case 2:
                        af = AF_INET6;
-                       len = 16;
+                       len = sizeof(struct in6_addr);
                        break;
 #endif
                default:
@@ -536,11 +536,11 @@ pimv2_addr_print(const u_char *bp, enum pimv2_addrtype at, int silent)
                hdrlen = 2;
        } else {
                switch (pimv2_addr_len) {
-               case 4:
+               case sizeof(struct in_addr):
                        af = AF_INET;
                        break;
 #ifdef INET6
-               case 16:
+               case sizeof(struct in6_addr):
                        af = AF_INET6;
                        break;
 #endif
index c817ae99f3b456adc1aa2c0c217d2a2b6fddb985..98c9e1087a1fa8d7d95141849e55ad19b15a5ba9 100644 (file)
@@ -15,7 +15,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-rsvp.c,v 1.36 2005-06-16 00:49:55 guy Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-rsvp.c,v 1.37 2005-07-11 20:15:33 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -608,7 +608,7 @@ rsvp_obj_print (const u_char *tptr, const char *ident, u_int tlen) {
                 printf("%s  IPv4 DestAddress: %s, Protocol ID: 0x%02x",
                        ident,
                        ipaddr_string(obj_tptr),
-                       *(obj_tptr+4));
+                       *(obj_tptr+sizeof(struct in_addr)));
                 printf("%s  Flags: [0x%02x], DestPort %u",
                        ident,
                        *(obj_tptr+5),
@@ -623,11 +623,11 @@ rsvp_obj_print (const u_char *tptr, const char *ident, u_int tlen) {
                 printf("%s  IPv6 DestAddress: %s, Protocol ID: 0x%02x",
                        ident,
                        ip6addr_string(obj_tptr),
-                       *(obj_tptr+16));
+                       *(obj_tptr+sizeof(struct in6_addr)));
                 printf("%s  Flags: [0x%02x], DestPort %u",
                        ident,
-                       *(obj_tptr+17),
-                       EXTRACT_16BITS(obj_tptr+18));
+                       *(obj_tptr+sizeof(struct in6_addr)+1),
+                       EXTRACT_16BITS(obj_tptr+sizeof(struct in6_addr)+2));
                 obj_tlen-=20;
                 obj_tptr+=20;                
                 break;
@@ -663,23 +663,23 @@ rsvp_obj_print (const u_char *tptr, const char *ident, u_int tlen) {
         case RSVP_OBJ_CONFIRM:
             switch(rsvp_obj_ctype) {
             case RSVP_CTYPE_IPV4:
-                if (obj_tlen < 4)
+                if (obj_tlen < sizeof(struct in_addr))
                     return -1;
                 printf("%s  IPv4 Receiver Address: %s",
                        ident,
                        ipaddr_string(obj_tptr));
-                obj_tlen-=4;
-                obj_tptr+=4;                
+                obj_tlen-=sizeof(struct in_addr);
+                obj_tptr+=sizeof(struct in_addr);                
                 break;
 #ifdef INET6
             case RSVP_CTYPE_IPV6:
-                if (obj_tlen < 16)
+                if (obj_tlen < sizeof(struct in6_addr))
                     return -1;
                 printf("%s  IPv6 Receiver Address: %s",
                        ident,
                        ip6addr_string(obj_tptr));
-                obj_tlen-=16;
-                obj_tptr+=16;                
+                obj_tlen-=sizeof(struct in6_addr);
+                obj_tptr+=sizeof(struct in6_addr);                
                 break;
 #endif
             default:
@@ -690,23 +690,23 @@ rsvp_obj_print (const u_char *tptr, const char *ident, u_int tlen) {
         case RSVP_OBJ_NOTIFY_REQ:
             switch(rsvp_obj_ctype) {
             case RSVP_CTYPE_IPV4:
-                if (obj_tlen < 4)
+                if (obj_tlen < sizeof(struct in_addr))
                     return -1;
                 printf("%s  IPv4 Notify Node Address: %s",
                        ident,
                        ipaddr_string(obj_tptr));
-                obj_tlen-=4;
-                obj_tptr+=4;                
+                obj_tlen-=sizeof(struct in_addr);
+                obj_tptr+=sizeof(struct in_addr);                
                 break;
 #ifdef INET6
             case RSVP_CTYPE_IPV6:
-                if (obj_tlen < 16)
+                if (obj_tlen < sizeof(struct in6_addr))
                     return-1;
                 printf("%s  IPv6 Notify Node Address: %s",
                        ident,
                        ip6addr_string(obj_tptr));
-                obj_tlen-=16;
-                obj_tptr+=16;                
+                obj_tlen-=sizeof(struct in6_addr);
+                obj_tptr+=sizeof(struct in6_addr);                
                 break;
 #endif
             default: