]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-hncp.c
Use more the ND_TTEST_1() macro
[tcpdump] / print-hncp.c
index af219c67cb5ad49496b2799e017646df2c1206fc..00ab04d13499cf8536ec355efb6929daaed08f32 100644 (file)
@@ -162,7 +162,8 @@ format_nid(const u_char *data)
     static int i = 0;
     i = (i + 1) % 4;
     snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x",
-             data[0], data[1], data[2], data[3]);
+             EXTRACT_U_1(data), EXTRACT_U_1(data + 1), EXTRACT_U_1(data + 2),
+             EXTRACT_U_1(data + 3));
     return buf[i];
 }
 
@@ -173,10 +174,10 @@ format_256(const u_char *data)
     static int i = 0;
     i = (i + 1) % 4;
     snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
-         EXTRACT_64BITS(data),
-         EXTRACT_64BITS(data + 8),
-         EXTRACT_64BITS(data + 16),
-         EXTRACT_64BITS(data + 24)
+         EXTRACT_BE_U_8(data),
+         EXTRACT_BE_U_8(data + 8),
+         EXTRACT_BE_U_8(data + 16),
+         EXTRACT_BE_U_8(data + 24)
     );
     return buf[i];
 }
@@ -206,12 +207,12 @@ print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
     int plenbytes;
     char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx::/128")];
 
-    if (prefix[0] >= 96 && max_length >= IPV4_MAPPED_HEADING_LEN + 1 &&
-        is_ipv4_mapped_address(&prefix[1])) {
+    if (EXTRACT_U_1(prefix) >= 96 && max_length >= IPV4_MAPPED_HEADING_LEN + 1 &&
+        is_ipv4_mapped_address(prefix + 1)) {
         struct in_addr addr;
         u_int plen;
 
-        plen = prefix[0]-96;
+        plen = EXTRACT_U_1(prefix) - 96;
         if (32 < plen)
             return -1;
         max_length -= 1;
@@ -220,7 +221,7 @@ print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
         plenbytes = (plen + 7) / 8;
         if (max_length < (u_int)plenbytes + IPV4_MAPPED_HEADING_LEN)
             return -3;
-        memcpy(&addr, &prefix[1 + IPV4_MAPPED_HEADING_LEN], plenbytes);
+        memcpy(&addr, prefix + IPV4_MAPPED_HEADING_LEN + 1, plenbytes);
         if (plen % 8) {
                ((u_char *)&addr)[plenbytes - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
@@ -241,7 +242,8 @@ print_dns_label(netdissect_options *ndo,
 {
     u_int length = 0;
     while (length < max_length) {
-        u_int lab_length = cp[length++];
+        u_int lab_length = EXTRACT_U_1(cp + length);
+        length++;
         if (lab_length == 0)
             return (int)length;
         if (length > 1 && print)
@@ -273,8 +275,8 @@ dhcpv4_print(netdissect_options *ndo,
         if (i + 2 > length)
             return -1;
         tlv = cp + i;
-        type = tlv[0];
-        optlen = tlv[1];
+        type = EXTRACT_U_1(tlv);
+        optlen = EXTRACT_U_1(tlv + 1);
         value = tlv + 2;
 
         ND_PRINT((ndo, "\n"));
@@ -325,8 +327,8 @@ dhcpv6_print(netdissect_options *ndo,
         if (i + 4 > length)
             return -1;
         tlv = cp + i;
-        type = EXTRACT_16BITS(tlv);
-        optlen = EXTRACT_16BITS(tlv + 2);
+        type = EXTRACT_BE_U_2(tlv);
+        optlen = EXTRACT_BE_U_2(tlv + 2);
         value = tlv + 4;
 
         ND_PRINT((ndo, "\n"));
@@ -422,14 +424,14 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, "\t"));
         }
 
-        ND_TCHECK2(*tlv, 4);
+        ND_TCHECK_4(tlv);
         if (i + 4 > length)
             goto invalid;
 
-        type = EXTRACT_16BITS(tlv);
-        bodylen = EXTRACT_16BITS(tlv + 2);
+        type = EXTRACT_BE_U_2(tlv);
+        bodylen = EXTRACT_BE_U_2(tlv + 2);
         value = tlv + 4;
-        ND_TCHECK2(*value, bodylen);
+        ND_TCHECK_LEN(value, bodylen);
         if (i + bodylen + 4 > length)
             goto invalid;
 
@@ -499,7 +501,7 @@ hncp_print_rec(netdissect_options *ndo,
                 break;
             }
             node_identifier = format_nid(value);
-            endpoint_identifier = EXTRACT_32BITS(value + 4);
+            endpoint_identifier = EXTRACT_BE_U_4(value + 4);
             ND_PRINT((ndo, " NID: %s EPID: %08x",
                 node_identifier,
                 endpoint_identifier
@@ -513,7 +515,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            hash = EXTRACT_64BITS(value);
+            hash = EXTRACT_BE_U_8(value);
             ND_PRINT((ndo, " hash: %016" PRIx64, hash));
         }
             break;
@@ -527,9 +529,9 @@ hncp_print_rec(netdissect_options *ndo,
                 break;
             }
             node_identifier = format_nid(value);
-            sequence_number = EXTRACT_32BITS(value + 4);
-            interval = format_interval(EXTRACT_32BITS(value + 8));
-            hash = EXTRACT_64BITS(value + 12);
+            sequence_number = EXTRACT_BE_U_4(value + 4);
+            interval = format_interval(EXTRACT_BE_U_4(value + 8));
+            hash = EXTRACT_BE_U_8(value + 12);
             ND_PRINT((ndo, " NID: %s seqno: %u %s hash: %016" PRIx64,
                 node_identifier,
                 sequence_number,
@@ -548,8 +550,8 @@ hncp_print_rec(netdissect_options *ndo,
                 break;
             }
             peer_node_identifier = format_nid(value);
-            peer_endpoint_identifier = EXTRACT_32BITS(value + 4);
-            endpoint_identifier = EXTRACT_32BITS(value + 8);
+            peer_endpoint_identifier = EXTRACT_BE_U_4(value + 4);
+            endpoint_identifier = EXTRACT_BE_U_4(value + 8);
             ND_PRINT((ndo, " Peer-NID: %s Peer-EPID: %08x Local-EPID: %08x",
                 peer_node_identifier,
                 peer_endpoint_identifier,
@@ -565,8 +567,8 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            endpoint_identifier = EXTRACT_32BITS(value);
-            interval = format_interval(EXTRACT_32BITS(value + 4));
+            endpoint_identifier = EXTRACT_BE_U_4(value);
+            interval = format_interval(EXTRACT_BE_U_4(value + 4));
             ND_PRINT((ndo, " EPID: %08x Interval: %s",
                 endpoint_identifier,
                 interval
@@ -580,7 +582,7 @@ hncp_print_rec(netdissect_options *ndo,
                 break;
             }
             ND_PRINT((ndo, " Verdict: %u Fingerprint: %s Common Name: ",
-                *value,
+                EXTRACT_U_1(value),
                 format_256(value + 4)));
             safeputs(ndo, value + 36, bodylen - 36);
         }
@@ -593,7 +595,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            capabilities = EXTRACT_16BITS(value + 2);
+            capabilities = EXTRACT_BE_U_2(value + 2);
             M = (uint8_t)((capabilities >> 12) & 0xf);
             P = (uint8_t)((capabilities >> 8) & 0xf);
             H = (uint8_t)((capabilities >> 4) & 0xf);
@@ -613,13 +615,13 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_DELEGATED_PREFIX: {
             int l;
-            if (bodylen < 9 || bodylen < 9 + (value[8] + 7) / 8) {
+            if (bodylen < 9 || bodylen < 9 + (EXTRACT_U_1(value + 8) + 7) / 8) {
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
             ND_PRINT((ndo, " VLSO: %s PLSO: %s Prefix: ",
-                format_interval(EXTRACT_32BITS(value)),
-                format_interval(EXTRACT_32BITS(value + 4))
+                format_interval(EXTRACT_BE_U_4(value)),
+                format_interval(EXTRACT_BE_U_4(value + 4))
             ));
             l = print_prefix(ndo, value + 8, bodylen - 8);
             if (l == -1) {
@@ -653,7 +655,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            policy = value[0];
+            policy = EXTRACT_U_1(value);
             ND_PRINT((ndo, " type: "));
             if (policy == 0) {
                 if (bodylen != 1) {
@@ -724,13 +726,13 @@ hncp_print_rec(netdissect_options *ndo,
         case HNCP_ASSIGNED_PREFIX: {
             uint8_t prty;
             int l;
-            if (bodylen < 6 || bodylen < 6 + (value[5] + 7) / 8) {
+            if (bodylen < 6 || bodylen < 6 + (EXTRACT_U_1(value + 5) + 7) / 8) {
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            prty = value[4] & 0xf;
+            prty = EXTRACT_U_1(value + 4) & 0xf;
             ND_PRINT((ndo, " EPID: %08x Prty: %u",
-                EXTRACT_32BITS(value),
+                EXTRACT_BE_U_4(value),
                 prty
             ));
             ND_PRINT((ndo, " Prefix: "));
@@ -753,7 +755,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            endpoint_identifier = EXTRACT_32BITS(value);
+            endpoint_identifier = EXTRACT_BE_U_4(value);
             ip_address = format_ip6addr(ndo, value + 4);
             ND_PRINT((ndo, " EPID: %08x IP Address: %s",
                 endpoint_identifier,
@@ -774,9 +776,9 @@ hncp_print_rec(netdissect_options *ndo,
             ip_address = format_ip6addr(ndo, value);
             ND_PRINT((ndo, " IP-Address: %s %c%c%c ",
                 ip_address,
-                (value[16] & 4) ? 'l' : '-',
-                (value[16] & 2) ? 'b' : '-',
-                (value[16] & 1) ? 's' : '-'
+                (EXTRACT_U_1(value + 16) & 4) ? 'l' : '-',
+                (EXTRACT_U_1(value + 16) & 2) ? 'b' : '-',
+                (EXTRACT_U_1(value + 16) & 1) ? 's' : '-'
             ));
             len = print_dns_label(ndo, value+17, bodylen-17, 1);
             if (len < 0) {
@@ -806,7 +808,7 @@ hncp_print_rec(netdissect_options *ndo,
                 ND_PRINT((ndo, " %s", istr));
                 break;
             }
-            l = value[16];
+            l = EXTRACT_U_1(value + 16);
             if (bodylen < 17 + l) {
                 ND_PRINT((ndo, " %s", istr));
                 break;