X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/94a4b4608009a96bf791ff24b2d019f40a120085..02da8c74d958d59f41bfd8c5cf7ffc31289d5725:/print-ip.c?ds=sidebyside diff --git a/print-ip.c b/print-ip.c index 21f83c10..c0c91888 100644 --- a/print-ip.c +++ b/print-ip.c @@ -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: @@ -616,7 +661,7 @@ ip_print(netdissect_options *ndo, if (ipds->off & 0x1fff) { (void)printf("%s > %s:", ipaddr_string(&ipds->ip->ip_src), ipaddr_string(&ipds->ip->ip_dst)); - if ((proto = getprotobynumber(ipds->ip->ip_p)) != NULL) + if (!ndo->ndo_nflag && (proto = getprotobynumber(ipds->ip->ip_p)) != NULL) (void)printf(" %s", proto->p_name); else (void)printf(" ip-proto-%d", ipds->ip->ip_p);