@@ -1104,18 +1104,21 @@ int build_niquery(__u8 *_nih)
{
struct ni_hdr *nih;
int cc;
+ __u16 this_nonce;
nih = (struct ni_hdr *)_nih;
nih->ni_cksum = 0;
- CLR(ntohs((*(__u16*)(nih->ni_nonce))) % mx_dup_ck);
+ memcpy(&this_nonce, &nih->ni_nonce, sizeof(this_nonce));
+ CLR(ntohs(this_nonce) % mx_dup_ck);
nih->ni_type = ICMPV6_NI_QUERY;
cc = sizeof(*nih);
datalen = 0;
memcpy(nih->ni_nonce, ni_nonce, sizeof(nih->ni_nonce));
- *(__u16*)(nih->ni_nonce) = htons(ntransmitted + 1);
+ this_nonce = htons(ntransmitted + 1);
+ memcpy(&nih->ni_nonce, &this_nonce, sizeof(this_nonce));
nih->ni_code = ni_subject_type;
nih->ni_qtype = htons(ni_query);
@@ -1331,7 +1334,7 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv)
#endif
if (c->cmsg_len < CMSG_LEN(sizeof(int)))
continue;
- hops = *(int*)CMSG_DATA(c);
+ memcpy(&hops, CMSG_DATA(c), sizeof(int));
}
}
@@ -1355,7 +1358,9 @@ parse_reply(struct msghdr *msg, int cc, void *addr, struct timeval *tv)
return 0;
} else if (icmph->icmp6_type == ICMPV6_NI_REPLY) {
struct ni_hdr *nih = (struct ni_hdr *)icmph;
- __u16 seq = ntohs(*(__u16 *)nih->ni_nonce);
+ __u16 seq;
+ memcpy(&seq, &nih->ni_nonce, sizeof(seq));
+ seq = ntohs(seq);
if (memcmp(&nih->ni_nonce[2], &ni_nonce[2], sizeof(ni_nonce) - sizeof(__u16)))
return 1;
if (gather_statistics((__u8*)icmph, sizeof(*icmph), cc,
@@ -142,7 +142,7 @@ restart:
if (cmsg->cmsg_type == IP_RECVERR) {
e = (struct sock_extended_err *) CMSG_DATA(cmsg);
} else if (cmsg->cmsg_type == IP_TTL) {
- rethops = *(int*)CMSG_DATA(cmsg);
+ memcpy(&rethops, CMSG_DATA(cmsg), sizeof(int));
} else {
printf("cmsg:%d\n ", cmsg->cmsg_type);
}
@@ -170,7 +170,7 @@ restart:
#ifdef IPV6_2292HOPLIMIT
case IPV6_2292HOPLIMIT:
#endif
- rethops = *(int*)CMSG_DATA(cmsg);
+ memcpy(&rethops, CMSG_DATA(cmsg), sizeof(int));
break;
default:
printf("cmsg6:%d\n ", cmsg->cmsg_type);
Current build of some tools results in gcc warning about strict-aliasing violations. So change those freaky casts to memcpy's. When the pointer types work out, gcc will optimize this away anyways. Signed-off-by: Mike Frysinger <vapier@gentoo.org> --- ping6.c | 13 +++++++++---- tracepath.c | 2 +- tracepath6.c | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-)