X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/ed85e20e4d6a27d5405f37366dd34b64c10a9211..refs/pull/482/head:/print-icmp.c diff --git a/print-icmp.c b/print-icmp.c index a86c7f01..ab3624e2 100644 --- a/print-icmp.c +++ b/print-icmp.c @@ -19,19 +19,18 @@ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#define NETDISSECT_REWORKED #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include #include #include -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" -#include "extract.h" /* must come after interface.h */ +#include "extract.h" #include "ip.h" #include "udp.h" @@ -145,12 +144,10 @@ struct icmp { #define ICMP_MAXTYPE 18 -#define ICMP_INFOTYPE(type) \ - ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ - (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ - (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ - (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ - (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) +#define ICMP_ERRTYPE(type) \ + ((type) == ICMP_UNREACH || (type) == ICMP_SOURCEQUENCH || \ + (type) == ICMP_REDIRECT || (type) == ICMP_TIMXCEED || \ + (type) == ICMP_PARAMPROB) #define ICMP_MPLS_EXT_TYPE(type) \ ((type) == ICMP_UNREACH || \ (type) == ICMP_TIMXCEED || \ @@ -313,7 +310,8 @@ const char *icmp_tstamp_print(u_int); /* print the milliseconds since midnight UTC */ const char * -icmp_tstamp_print(u_int tstamp) { +icmp_tstamp_print(u_int tstamp) +{ u_int msec,sec,min,hrs; static char buf[64]; @@ -345,9 +343,9 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * char buf[MAXHOSTNAMELEN + 100]; struct cksum_vec vec[1]; - dp = (struct icmp *)bp; - ext_dp = (struct icmp_ext_t *)bp; - ip = (struct ip *)bp2; + dp = (const struct icmp *)bp; + ext_dp = (const struct icmp_ext_t *)bp; + ip = (const struct ip *)bp2; str = buf; ND_TCHECK(dp->icmp_code); @@ -379,7 +377,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * ND_TCHECK(dp->icmp_ip.ip_p); oip = &dp->icmp_ip; hlen = IP_HL(oip) * 4; - ouh = (struct udphdr *)(((u_char *)oip) + hlen); + ouh = (const struct udphdr *)(((const u_char *)oip) + hlen); ND_TCHECK(ouh->uh_dport); dport = EXTRACT_16BITS(&ouh->uh_dport); switch (oip->ip_p) { @@ -388,14 +386,14 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * (void)snprintf(buf, sizeof(buf), "%s tcp port %s unreachable", ipaddr_string(ndo, &oip->ip_dst), - tcpport_string(dport)); + tcpport_string(ndo, dport)); break; case IPPROTO_UDP: (void)snprintf(buf, sizeof(buf), "%s udp port %s unreachable", ipaddr_string(ndo, &oip->ip_dst), - udpport_string(dport)); + udpport_string(ndo, dport)); break; default: @@ -410,7 +408,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * case ICMP_UNREACH_NEEDFRAG: { register const struct mtu_discovery *mp; - mp = (struct mtu_discovery *)(u_char *)&dp->icmp_void; + mp = (const struct mtu_discovery *)(const u_char *)&dp->icmp_void; mtu = EXTRACT_16BITS(&mp->nexthopmtu); if (mtu) { (void)snprintf(buf, sizeof(buf), @@ -451,7 +449,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * (void)snprintf(buf, sizeof(buf), "router advertisement"); cp = buf + strlen(buf); - ihp = (struct ih_rdiscovery *)&dp->icmp_void; + ihp = (const struct ih_rdiscovery *)&dp->icmp_void; ND_TCHECK(*ihp); (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf)); cp = buf + strlen(buf); @@ -558,9 +556,9 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * ND_PRINT((ndo, "ICMP %s, length %u", str, plen)); if (ndo->ndo_vflag && !fragmented) { /* don't attempt checksumming if this is a frag */ uint16_t sum, icmp_sum; - struct cksum_vec vec[1]; + if (ND_TTEST2(*bp, plen)) { - vec[0].ptr = (const uint8_t *)(void *)dp; + vec[0].ptr = (const uint8_t *)(const void *)dp; vec[0].len = plen; sum = in_cksum(vec, 1); if (sum != 0) { @@ -576,10 +574,10 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * * print the remnants of the IP packet. * save the snaplength as this may get overidden in the IP printer. */ - if (ndo->ndo_vflag >= 1 && !ICMP_INFOTYPE(dp->icmp_type)) { + if (ndo->ndo_vflag >= 1 && ICMP_ERRTYPE(dp->icmp_type)) { bp += 8; ND_PRINT((ndo, "\n\t")); - ip = (struct ip *)bp; + ip = (const struct ip *)bp; ndo->ndo_snaplen = ndo->ndo_snapend - bp; snapend_save = ndo->ndo_snapend; ip_print(ndo, bp, EXTRACT_16BITS(&ip->ip_len)); @@ -628,11 +626,11 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char * hlen)); hlen -= 4; /* subtract common header size */ - obj_tptr = (uint8_t *)ext_dp->icmp_ext_data; + obj_tptr = (const uint8_t *)ext_dp->icmp_ext_data; while (hlen > sizeof(struct icmp_mpls_ext_object_header_t)) { - icmp_mpls_ext_object_header = (struct icmp_mpls_ext_object_header_t *)obj_tptr; + icmp_mpls_ext_object_header = (const struct icmp_mpls_ext_object_header_t *)obj_tptr; ND_TCHECK(*icmp_mpls_ext_object_header); obj_tlen = EXTRACT_16BITS(icmp_mpls_ext_object_header->length); obj_class_num = icmp_mpls_ext_object_header->class_num;