]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-hncp.c
Update .gitignore for other configurations
[tcpdump] / print-hncp.c
index 0433faebc579154ebadf88db2a3ecc035d5d34a0..c195068e418218cadb974155d7f134fde0a52ec4 100644 (file)
@@ -49,6 +49,7 @@ void
 hncp_print(netdissect_options *ndo,
            const u_char *cp, u_int length)
 {
+    ndo->ndo_protocol = "hncp";
     ND_PRINT("hncp (%u)", length);
     hncp_print_rec(ndo, cp, length, 1);
 }
@@ -145,7 +146,7 @@ static const struct tok dh6opt_str[] = {
 /*
  * Is an IPv6 address an IPv4-mapped address?
  */
-static inline int
+static int
 is_ipv4_mapped_address(const u_char *addr)
 {
     /* The value of the prefix */
@@ -161,7 +162,7 @@ format_nid(const u_char *data)
     static char buf[4][sizeof("01:01:01:01")];
     static int i = 0;
     i = (i + 1) % 4;
-    snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x",
+    nd_snprintf(buf[i], sizeof(buf[i]), "%02x:%02x:%02x:%02x",
              EXTRACT_U_1(data), EXTRACT_U_1(data + 1), EXTRACT_U_1(data + 2),
              EXTRACT_U_1(data + 3));
     return buf[i];
@@ -173,7 +174,7 @@ format_256(const u_char *data)
     static char buf[4][sizeof("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")];
     static int i = 0;
     i = (i + 1) % 4;
-    snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
+    nd_snprintf(buf[i], sizeof(buf[i]), "%016" PRIx64 "%016" PRIx64 "%016" PRIx64 "%016" PRIx64,
          EXTRACT_BE_U_8(data),
          EXTRACT_BE_U_8(data + 8),
          EXTRACT_BE_U_8(data + 16),
@@ -188,7 +189,7 @@ format_interval(const uint32_t n)
     static char buf[4][sizeof("0000000.000s")];
     static int i = 0;
     i = (i + 1) % 4;
-    snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000);
+    nd_snprintf(buf[i], sizeof(buf[i]), "%u.%03us", n / 1000, n % 1000);
     return buf[i];
 }
 
@@ -226,7 +227,7 @@ print_prefix(netdissect_options *ndo, const u_char *prefix, u_int max_length)
                ((u_char *)&addr)[plenbytes - 1] &=
                        ((0xff00 >> (plen % 8)) & 0xff);
        }
-       snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, &addr), plen);
+       nd_snprintf(buf, sizeof(buf), "%s/%u", ipaddr_string(ndo, (const u_char *)&addr), plen);
         plenbytes += 1 + IPV4_MAPPED_HEADING_LEN;
     } else {
         plenbytes = decode_prefix6(ndo, prefix, max_length, buf, sizeof(buf));
@@ -247,14 +248,14 @@ print_dns_label(netdissect_options *ndo,
         if (lab_length == 0)
             return (int)length;
         if (length > 1 && print)
-            safeputchar(ndo, '.');
+            ND_PRINT(".");
         if (length+lab_length > max_length) {
             if (print)
-                safeputs(ndo, cp+length, max_length-length);
+                (void)nd_printzp(ndo, cp+length, max_length-length, NULL);
             break;
         }
         if (print)
-            safeputs(ndo, cp+length, lab_length);
+            (void)nd_printzp(ndo, cp+length, lab_length, NULL);
         length += lab_length;
     }
     if (print)
@@ -344,7 +345,7 @@ dhcpv6_print(netdissect_options *ndo,
             case DH6OPT_DNS_SERVERS:
             case DH6OPT_SNTP_SERVERS: {
                 if (optlen % 16 != 0) {
-                    ND_PRINT(" %s", istr);
+                    nd_print_invalid(ndo);
                     return -1;
                 }
                 for (t = 0; t < optlen; t += 16)
@@ -478,14 +479,14 @@ hncp_print_rec(netdissect_options *ndo,
 
         case DNCP_REQUEST_NETWORK_STATE: {
             if (bodylen != 0)
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
         }
             break;
 
         case DNCP_REQUEST_NODE_STATE: {
             const char *node_identifier;
             if (bodylen != 4) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             node_identifier = format_nid(value);
@@ -497,7 +498,7 @@ hncp_print_rec(netdissect_options *ndo,
             const char *node_identifier;
             uint32_t endpoint_identifier;
             if (bodylen != 8) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             node_identifier = format_nid(value);
@@ -512,7 +513,7 @@ hncp_print_rec(netdissect_options *ndo,
         case DNCP_NETWORK_STATE: {
             uint64_t hash;
             if (bodylen != 8) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             hash = EXTRACT_BE_U_8(value);
@@ -525,7 +526,7 @@ hncp_print_rec(netdissect_options *ndo,
             uint32_t sequence_number;
             uint64_t hash;
             if (bodylen < 20) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             node_identifier = format_nid(value);
@@ -546,7 +547,7 @@ hncp_print_rec(netdissect_options *ndo,
             const char *peer_node_identifier;
             uint32_t peer_endpoint_identifier, endpoint_identifier;
             if (bodylen != 12) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             peer_node_identifier = format_nid(value);
@@ -564,7 +565,7 @@ hncp_print_rec(netdissect_options *ndo,
             uint32_t endpoint_identifier;
             const char *interval;
             if (bodylen < 8) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             endpoint_identifier = EXTRACT_BE_U_4(value);
@@ -578,13 +579,13 @@ hncp_print_rec(netdissect_options *ndo,
 
         case DNCP_TRUST_VERDICT: {
             if (bodylen <= 36) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ND_PRINT(" Verdict: %u Fingerprint: %s Common Name: ",
                 EXTRACT_U_1(value),
                 format_256(value + 4));
-            safeputs(ndo, value + 36, bodylen - 36);
+            (void)nd_printzp(ndo, value + 36, bodylen - 36, NULL);
         }
             break;
 
@@ -592,7 +593,7 @@ hncp_print_rec(netdissect_options *ndo,
             uint16_t capabilities;
             uint8_t M, P, H, L;
             if (bodylen < 5) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             capabilities = EXTRACT_BE_U_2(value + 2);
@@ -603,7 +604,7 @@ hncp_print_rec(netdissect_options *ndo,
             ND_PRINT(" M: %u P: %u H: %u L: %u User-agent: ",
                 M, P, H, L
             );
-            safeputs(ndo, value + 4, bodylen - 4);
+            (void)nd_printzp(ndo, value + 4, bodylen - 4, NULL);
         }
             break;
 
@@ -616,7 +617,7 @@ hncp_print_rec(netdissect_options *ndo,
         case HNCP_DELEGATED_PREFIX: {
             int l;
             if (bodylen < 9 || bodylen < 9 + (EXTRACT_U_1(value + 8) + 7) / 8) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ND_PRINT(" VLSO: %s PLSO: %s Prefix: ",
@@ -638,7 +639,7 @@ hncp_print_rec(netdissect_options *ndo,
                  * IPv6", or -3, meaning "the prefix runs past
                  * the end of the TLV".
                  */
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             l += 8 + (-l & 3);
@@ -652,14 +653,14 @@ hncp_print_rec(netdissect_options *ndo,
             uint8_t policy;
             int l;
             if (bodylen < 1) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             policy = EXTRACT_U_1(value);
             ND_PRINT(" type: ");
             if (policy == 0) {
                 if (bodylen != 1) {
-                    ND_PRINT(" %s", istr);
+                    nd_print_invalid(ndo);
                     break;
                 }
                 ND_PRINT("Internet connectivity");
@@ -680,7 +681,7 @@ hncp_print_rec(netdissect_options *ndo,
                      * IPv6", or -3, meaning "the prefix runs past
                      * the end of the TLV".
                      */
-                    ND_PRINT(" %s", istr);
+                    nd_print_invalid(ndo);
                     break;
                 }
             } else if (policy == 129) {
@@ -688,10 +689,10 @@ hncp_print_rec(netdissect_options *ndo,
                 print_dns_label(ndo, value+1, bodylen-1, 1);
             } else if (policy == 130) {
                 ND_PRINT("Opaque UTF-8: ");
-                safeputs(ndo, value + 1, bodylen - 1);
+                (void)nd_printzp(ndo, value + 1, bodylen - 1, NULL);
             } else if (policy == 131) {
                 if (bodylen != 1) {
-                    ND_PRINT(" %s", istr);
+                    nd_print_invalid(ndo);
                     break;
                 }
                 ND_PRINT("Restrictive assignment");
@@ -703,7 +704,7 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_DHCPV4_DATA: {
             if (bodylen == 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             if (dhcpv4_print(ndo, value, bodylen, indent+1) != 0)
@@ -713,11 +714,11 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_DHCPV6_DATA: {
             if (bodylen == 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             if (dhcpv6_print(ndo, value, bodylen, indent+1) != 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
         }
@@ -727,7 +728,7 @@ hncp_print_rec(netdissect_options *ndo,
             uint8_t prty;
             int l;
             if (bodylen < 6 || bodylen < 6 + (EXTRACT_U_1(value + 5) + 7) / 8) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             prty = EXTRACT_U_1(value + 4) & 0xf;
@@ -737,7 +738,7 @@ hncp_print_rec(netdissect_options *ndo,
             );
             ND_PRINT(" Prefix: ");
             if ((l = print_prefix(ndo, value + 5, bodylen - 5)) < 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             l += 5;
@@ -752,7 +753,7 @@ hncp_print_rec(netdissect_options *ndo,
             uint32_t endpoint_identifier;
             const char *ip_address;
             if (bodylen < 20) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             endpoint_identifier = EXTRACT_BE_U_4(value);
@@ -770,7 +771,7 @@ hncp_print_rec(netdissect_options *ndo,
             const char *ip_address;
             int len;
             if (bodylen < 17) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ip_address = format_ip6addr(ndo, value);
@@ -782,7 +783,7 @@ hncp_print_rec(netdissect_options *ndo,
             );
             len = print_dns_label(ndo, value+17, bodylen-17, 1);
             if (len < 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             len += 17;
@@ -794,7 +795,7 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_DOMAIN_NAME: {
             if (bodylen == 0) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ND_PRINT(" Domain: ");
@@ -805,23 +806,23 @@ hncp_print_rec(netdissect_options *ndo,
         case HNCP_NODE_NAME: {
             u_int l;
             if (bodylen < 17) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             l = EXTRACT_U_1(value + 16);
             if (bodylen < 17 + l) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ND_PRINT(" IP-Address: %s Name: ",
                 format_ip6addr(ndo, value)
             );
             if (l < 64) {
-                safeputchar(ndo, '"');
-                safeputs(ndo, value + 17, l);
-                safeputchar(ndo, '"');
+                ND_PRINT("\"");
+                (void)nd_printzp(ndo, value + 17, l, NULL);
+                ND_PRINT("\"");
             } else {
-                ND_PRINT("%s", istr);
+                nd_print_invalid(ndo);
             }
             l += 17;
             l += -l & 3;
@@ -832,7 +833,7 @@ hncp_print_rec(netdissect_options *ndo,
 
         case HNCP_MANAGED_PSK: {
             if (bodylen < 32) {
-                ND_PRINT(" %s", istr);
+                nd_print_invalid(ndo);
                 break;
             }
             ND_PRINT(" PSK: %s", format_256(value));
@@ -856,10 +857,10 @@ hncp_print_rec(netdissect_options *ndo,
     return;
 
  trunc:
-    ND_PRINT("%s", "[|hncp]");
+    nd_print_trunc(ndo);
     return;
 
  invalid:
-    ND_PRINT("%s", istr);
+    nd_print_invalid(ndo);
     return;
 }