summaryrefslogtreecommitdiff
path: root/print-icmp.c
diff options
context:
space:
mode:
authorFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-01-30 15:51:20 +0100
committerFrancois-Xavier Le Bail <devel.fx.lebail@orange.fr>2018-01-30 16:38:48 +0100
commitaa9960a2c3d98c38d385c10e54d9160cb89feba0 (patch)
treec30a1db530c9d83ddfce03cfcac9b0da1afe8a2c /print-icmp.c
parentfbe65c7e385eb914cc86ea3e1cf278f4179203b2 (diff)
downloadtcpdump-aa9960a2c3d98c38d385c10e54d9160cb89feba0.tar.gz
ICMP: Replace a 'struct in_addr' member type with a 'nd_ipv4' one
In 'struct icmp'. This avoid some 'undefined-behavior' warnings with clang and option -fsanitize=undefined enabled. Moreover: Remove unneeded '&' when getting a pointer to a nd_ipv4 type. Fix indentation. The warnings were like: print-icmp.c:355:2: runtime error: member access within misaligned address 0x61d00001eabe for type 'const struct icmp', which requires 4 byte alignment 0x61d00001eabe: note: pointer points here ef 01 02 03 08 00 90 e1 00 03 00 00 00 00 00 00 00 05 ed 60 ab cd ab cd ab cd ab cd ab cd ab cd ^ SUMMARY: AddressSanitizer: undefined-behavior print-icmp.c:355:2 in
Diffstat (limited to 'print-icmp.c')
-rw-r--r--print-icmp.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/print-icmp.c b/print-icmp.c
index 269b14fb..a5b94d63 100644
--- a/print-icmp.c
+++ b/print-icmp.c
@@ -52,8 +52,8 @@ struct icmp {
nd_uint8_t icmp_code; /* type sub code */
nd_uint16_t icmp_cksum; /* ones complement cksum of struct */
union {
- nd_uint8_t ih_pptr; /* ICMP_PARAMPROB */
- struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
+ nd_uint8_t ih_pptr; /* ICMP_PARAMPROB */
+ nd_ipv4 ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
nd_uint16_t icd_id;
nd_uint16_t icd_seq;
@@ -375,7 +375,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
ND_TCHECK_1(dp->icmp_ip.ip_p);
(void)nd_snprintf(buf, sizeof(buf),
"%s protocol %u unreachable",
- ipaddr_string(ndo, &dp->icmp_ip.ip_dst),
+ ipaddr_string(ndo, dp->icmp_ip.ip_dst),
EXTRACT_U_1(dp->icmp_ip.ip_p));
break;
@@ -392,21 +392,21 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
case IPPROTO_TCP:
(void)nd_snprintf(buf, sizeof(buf),
"%s tcp port %s unreachable",
- ipaddr_string(ndo, &oip->ip_dst),
+ ipaddr_string(ndo, oip->ip_dst),
tcpport_string(ndo, dport));
break;
case IPPROTO_UDP:
(void)nd_snprintf(buf, sizeof(buf),
"%s udp port %s unreachable",
- ipaddr_string(ndo, &oip->ip_dst),
+ ipaddr_string(ndo, oip->ip_dst),
udpport_string(ndo, dport));
break;
default:
(void)nd_snprintf(buf, sizeof(buf),
"%s protocol %u port %u unreachable",
- ipaddr_string(ndo, &oip->ip_dst),
+ ipaddr_string(ndo, oip->ip_dst),
ip_proto, dport);
break;
}
@@ -420,11 +420,11 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
if (mtu) {
(void)nd_snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %u)",
- ipaddr_string(ndo, &dp->icmp_ip.ip_dst), mtu);
+ ipaddr_string(ndo, dp->icmp_ip.ip_dst), mtu);
} else {
(void)nd_snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
- ipaddr_string(ndo, &dp->icmp_ip.ip_dst));
+ ipaddr_string(ndo, dp->icmp_ip.ip_dst));
}
}
break;
@@ -433,7 +433,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
fmt = tok2str(unreach2str, "#%u %%s unreachable",
icmp_code);
(void)nd_snprintf(buf, sizeof(buf), fmt,
- ipaddr_string(ndo, &dp->icmp_ip.ip_dst));
+ ipaddr_string(ndo, dp->icmp_ip.ip_dst));
break;
}
break;
@@ -443,8 +443,8 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
fmt = tok2str(type2str, "redirect-#%u %%s to net %%s",
icmp_code);
(void)nd_snprintf(buf, sizeof(buf), fmt,
- ipaddr_string(ndo, &dp->icmp_ip.ip_dst),
- ipaddr_string(ndo, &dp->icmp_gwaddr));
+ ipaddr_string(ndo, dp->icmp_ip.ip_dst),
+ ipaddr_string(ndo, dp->icmp_gwaddr));
break;
case ICMP_ROUTERADVERT:
@@ -490,7 +490,7 @@ icmp_print(netdissect_options *ndo, const u_char *bp, u_int plen, const u_char *
while (num-- > 0) {
ND_TCHECK_SIZE(idp);
(void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
- ipaddr_string(ndo, &idp->ird_addr),
+ ipaddr_string(ndo, idp->ird_addr),
EXTRACT_BE_U_4(idp->ird_pref));
cp = buf + strlen(buf);
++idp;