]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip6.c
OSPF: Use %zu to print sizeof values
[tcpdump] / print-ip6.c
index 2cc4e3090e35ece11633b58a99cf6e8b05cee5cc..525a284ecdb0c4375631c2c123eb16161d9c3030 100644 (file)
@@ -44,7 +44,7 @@
  * calculation.
  */
 static void
-ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
+ip6_finddst(netdissect_options *ndo, nd_ipv6 *dst,
             const struct ip6_hdr *ip6)
 {
        const u_char *cp;
@@ -77,7 +77,6 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
                         * the header, in units of 8 octets, excluding
                         * the first 8 octets.
                         */
-                       ND_TCHECK_2(cp);
                        advance = (GET_U_1(cp + 1) + 1) << 3;
                        nh = GET_U_1(cp);
                        break;
@@ -88,7 +87,6 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
                         * marked as reserved, and the header is always
                         * the same size.
                         */
-                       ND_TCHECK_1(cp);
                        advance = sizeof(struct ip6_frag);
                        nh = GET_U_1(cp);
                        break;
@@ -165,7 +163,7 @@ ip6_finddst(netdissect_options *ndo, struct in6_addr *dst,
 
 done:
 trunc:
-       UNALIGNED_MEMCPY(dst, dst_addr, sizeof(nd_ipv6));
+       GET_CPY_BYTES(dst, dst_addr, sizeof(nd_ipv6));
 }
 
 /*
@@ -177,8 +175,8 @@ nextproto6_cksum(netdissect_options *ndo,
                 u_int len, u_int covlen, uint8_t next_proto)
 {
         struct {
-                struct in6_addr ph_src;
-                struct in6_addr ph_dst;
+                nd_ipv6 ph_src;
+                nd_ipv6 ph_dst;
                 uint32_t       ph_len;
                 uint8_t        ph_zero[3];
                 uint8_t        ph_nxt;
@@ -188,7 +186,7 @@ nextproto6_cksum(netdissect_options *ndo,
 
         /* pseudo-header */
         memset(&ph, 0, sizeof(ph));
-        UNALIGNED_MEMCPY(&ph.ph_src, ip6->ip6_src, sizeof (struct in6_addr));
+        GET_CPY_BYTES(&ph.ph_src, ip6->ip6_src, sizeof(nd_ipv6));
         nh = GET_U_1(ip6->ip6_nxt);
         switch (nh) {
 
@@ -207,8 +205,7 @@ nextproto6_cksum(netdissect_options *ndo,
                 break;
 
         default:
-                UNALIGNED_MEMCPY(&ph.ph_dst, ip6->ip6_dst,
-                                 sizeof (struct in6_addr));
+                GET_CPY_BYTES(&ph.ph_dst, ip6->ip6_dst, sizeof(nd_ipv6));
                 break;
         }
         ph.ph_len = htonl(len);
@@ -334,8 +331,8 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                if (cp == (const u_char *)(ip6 + 1) &&
                    nh != IPPROTO_TCP && nh != IPPROTO_UDP &&
                    nh != IPPROTO_DCCP && nh != IPPROTO_SCTP) {
-                       ND_PRINT("%s > %s: ", ip6addr_string(ndo, ip6->ip6_src),
-                                    ip6addr_string(ndo, ip6->ip6_dst));
+                       ND_PRINT("%s > %s: ", GET_IP6ADDR_STRING(ip6->ip6_src),
+                                    GET_IP6ADDR_STRING(ip6->ip6_dst));
                }
 
                switch (nh) {
@@ -377,7 +374,7 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                         * XXX - we don't use "advance"; RFC 3775 says that
                         * the next header field in a mobility header
                         * should be IPPROTO_NONE, but speaks of
-                        * the possiblity of a future extension in
+                        * the possibility of a future extension in
                         * which payload can be piggybacked atop a
                         * mobility header.
                         */
@@ -413,8 +410,14 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                                 * Set the length to the payload length
                                 * plus the IPv6 header length, and
                                 * change the snapshot length accordingly.
+                                *
+                                * But make sure it's not shorter than
+                                * the total number of bytes we've
+                                * processed so far.
                                 */
                                len = payload_len + sizeof(struct ip6_hdr);
+                               if (len < total_advance)
+                                       goto trunc;
                                if (length < len)
                                        ND_PRINT("truncated-ip6 - %u bytes missing!",
                                                len - length);
@@ -463,8 +466,8 @@ ip6_print(netdissect_options *ndo, const u_char *bp, u_int length)
                                        len -= total_advance;
                                }
                        }
-                       ip_print_demux(ndo, cp, len, 6, fragmented,
-                           GET_U_1(ip6->ip6_hlim), nh, bp);
+                       ip_demux_print(ndo, cp, len, 6, fragmented,
+                                      GET_U_1(ip6->ip6_hlim), nh, bp);
                        nd_pop_packet_info(ndo);
                        return;
                }