]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ip.c
Add changes in 4.2.1.
[tcpdump] / print-ip.c
index 21f83c10eb92c2768bf17ac3d52e7a02a692f94d..1fa7aab0d6cae8830aa92c9f8ac3cf37dfb9d01a 100644 (file)
@@ -87,7 +87,7 @@ ip_printroute(register const u_char *cp, u_int length)
  * This is used for UDP and TCP pseudo-header in the checksum
  * calculation.
  */
-u_int32_t
+static u_int32_t
 ip_finddst(const struct ip *ip)
 {
        int length;
@@ -129,6 +129,39 @@ trunc:
        return retval;
 }
 
+/*
+ * Compute a V4-style checksum by building a pseudoheader.
+ */
+int
+nextproto4_cksum(const struct ip *ip, const u_int8_t *data,
+                u_int len, u_int next_proto)
+{
+       struct phdr {
+               u_int32_t src;
+               u_int32_t dst;
+               u_char mbz;
+               u_char proto;
+               u_int16_t len;
+       } ph;
+       struct cksum_vec vec[2];
+
+       /* pseudo-header.. */
+       ph.len = htons((u_int16_t)len);
+       ph.mbz = 0;
+       ph.proto = next_proto;
+       memcpy(&ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
+       if (IP_HL(ip) == 5)
+               memcpy(&ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
+       else
+               ph.dst = ip_finddst(ip);
+
+       vec[0].ptr = (const u_int8_t *)(void *)&ph;
+       vec[0].len = sizeof(ph);
+       vec[1].ptr = data;
+       vec[1].len = len;
+       return (in_cksum(vec, 2));
+}
+
 static void
 ip_printts(register const u_char *cp, u_int length)
 {
@@ -429,7 +462,19 @@ again:
                break;
 
        case IPPROTO_VRRP:
-               vrrp_print(ipds->cp, ipds->len, ipds->ip->ip_ttl);
+               if (packettype == PT_CARP) {
+                       if (vflag)
+                               (void)printf("carp %s > %s: ",
+                                            ipaddr_string(&ipds->ip->ip_src),
+                                            ipaddr_string(&ipds->ip->ip_dst));
+                       carp_print(ipds->cp, ipds->len, ipds->ip->ip_ttl);
+               } else {
+                       if (vflag)
+                               (void)printf("vrrp %s > %s: ",
+                                            ipaddr_string(&ipds->ip->ip_src),
+                                            ipaddr_string(&ipds->ip->ip_dst));
+                       vrrp_print(ipds->cp, ipds->len, ipds->ip->ip_ttl);
+               }
                break;
 
        case IPPROTO_PGM: