]> The Tcpdump Group git mirrors - tcpdump/commitdiff
courtesy rick cheng (rcheng AT juniper dot net):
authorhannes <hannes>
Fri, 3 Feb 2006 08:32:39 +0000 (08:32 +0000)
committerhannes <hannes>
Fri, 3 Feb 2006 08:32:39 +0000 (08:32 +0000)
improve code readability:
  - LDP_TLV_ADDRESS_LIST printer
  - BFD_DISCRIMINATOR printer

CREDITS
print-ldp.c
print-lspping.c

diff --git a/CREDITS b/CREDITS
index bc71340a9049e29a9adbfb6bd9cef925d67e9256..252b9bab26755eef900179c54daa2db07b1e8329 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -115,6 +115,7 @@ Additional people who have contributed patches:
        Phil Wood                       <[email protected]>
        Rafal Maszkowski                <[email protected]>
        Raphael Raimbault               <[email protected]>
+       Rick Cheng                      <[email protected]>
        Rick Jones                      <[email protected]>
        Rick Watson                     <[email protected]>
        Rob Braun                       <[email protected]>
index 39079cb141e8e997c880cd9e268faa9ee1346bfa..f499133a06949132c886f9943b6e7a10c1061f0f 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.16 2006-02-01 14:56:25 hannes Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ldp.c,v 1.17 2006-02-03 08:32:39 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -215,8 +215,10 @@ static const struct tok ldp_fec_martini_ifparm_vccv_cv_values[] = {
 };
 
 /* RFC1700 address family numbers, same definition in print-bgp.c */
+/* FIXME: move all AF stuff into dedicated files */
 #define AFNUM_INET     1
 #define AFNUM_INET6    2
+#define AFNUM_LEN       2 
 
 #define FALSE 0
 #define TRUE  1
@@ -296,21 +298,24 @@ ldp_tlv_print(register const u_char *tptr) {
 
     case LDP_TLV_ADDRESS_LIST:
        af = EXTRACT_16BITS(tptr);
-       tptr+=2;
+       tptr+=AFNUM_LEN;
+        tlv_tlen -= AFNUM_LEN;
        printf("\n\t      Address Family: ");
        if (af == AFNUM_INET) {
            printf("IPv4, addresses:");
-           for (i=0; i<(tlv_tlen-2)/4; i++) {
+           while(tlv_tlen >= sizeof(struct in_addr)) {
                printf(" %s",ipaddr_string(tptr));
-               tptr+=sizeof(struct in_addr);
+               tlv_tlen-=sizeof(struct in_addr);
+               tptr+=sizeof(struct in_addr);                
            }
        }
 #ifdef INET6
        else if (af == AFNUM_INET6) {
            printf("IPv6, addresses:");
-           for (i=0; i<(tlv_tlen-2)/16; i++) {
+           while(tlv_tlen >= sizeof(struct in6_addr)) {
                printf(" %s",ip6addr_string(tptr));
-               tptr+=sizeof(struct in6_addr);
+               tlv_tlen-=sizeof(struct in6_addr);
+               tptr+=sizeof(struct in6_addr);                
            }
        }
 #endif
index 24e6997163b0cade731220147cbde5f2eb37d37e..e92fd058351b7dd4e3eeccd74c8b992897d07e3f 100644 (file)
@@ -15,7 +15,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-lspping.c,v 1.16 2006-02-01 14:37:26 hannes Exp $";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-lspping.c,v 1.17 2006-02-03 08:33:12 hannes Exp $";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -138,6 +138,7 @@ struct lspping_tlv_header {
 #define        LSPPING_TLV_PAD                   3
 #define        LSPPING_TLV_ERROR_CODE            4
 #define        LSPPING_TLV_BFD_DISCRIMINATOR     15 /* draft-ietf-bfd-mpls-02 */
+#define LSPPING_TLV_BFD_DISCRIMINATOR_LEN 4
 #define        LSPPING_TLV_VENDOR_PRIVATE        0xfc00
 
 static const struct tok lspping_tlv_values[] = {
@@ -836,7 +837,7 @@ lspping_print(register const u_char *pptr, register u_int len) {
 
         case LSPPING_TLV_BFD_DISCRIMINATOR:
             tptr += sizeof(struct lspping_tlv_header);
-            if (!TTEST2(*tptr, 4))
+            if (!TTEST2(*tptr, LSPPING_TLV_BFD_DISCRIMINATOR_LEN))
                 goto trunc;
             printf("\n\t    BFD Discriminator 0x%08x", EXTRACT_32BITS(tptr));
             break;