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
nd_uint8_t icmp_code; /* type sub code */
nd_uint16_t icmp_cksum; /* ones complement cksum of struct */
union {
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;
struct ih_idseq {
nd_uint16_t icd_id;
nd_uint16_t icd_seq;
ND_TCHECK_1(dp->icmp_ip.ip_p);
(void)nd_snprintf(buf, sizeof(buf),
"%s protocol %u unreachable",
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;
EXTRACT_U_1(dp->icmp_ip.ip_p));
break;
case IPPROTO_TCP:
(void)nd_snprintf(buf, sizeof(buf),
"%s tcp port %s unreachable",
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",
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",
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;
}
ip_proto, dport);
break;
}
if (mtu) {
(void)nd_snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %u)",
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",
} 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));
fmt = tok2str(unreach2str, "#%u %%s unreachable",
icmp_code);
(void)nd_snprintf(buf, sizeof(buf), fmt,
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));
fmt = tok2str(type2str, "redirect-#%u %%s to net %%s",
icmp_code);
(void)nd_snprintf(buf, sizeof(buf), fmt,
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:
break;
case ICMP_ROUTERADVERT:
while (num-- > 0) {
ND_TCHECK_SIZE(idp);
(void)nd_snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
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;
EXTRACT_BE_U_4(idp->ird_pref));
cp = buf + strlen(buf);
++idp;