1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

unix plat: avoid strict aliasing complaint from a toolchain

The type of the fields in rtentry is sockaddr, and it is
casted to sockaddr_in. Size-wise it is ok, they should both
be the same size. But casting a pointer breaks build with
optimizations with the following error:

unix-sockets.c:434: error: dereferencing pointer 'addr' does break strict-aliasing rules

Amends commit 3c95483518.
This commit is contained in:
Orgad Shaneh 2020-09-14 17:40:54 +03:00 committed by Andy Green
parent 92ed19164c
commit 2badaef4fc

View file

@ -409,7 +409,6 @@ lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip,
uint8_t *gateway_ip)
{
#if defined(__linux__)
struct sockaddr_in *addr;
struct sockaddr_in sin;
struct rtentry route;
struct ifreq ifr;
@ -440,17 +439,12 @@ lws_plat_ifconfig_ip(const char *ifname, int fd, uint8_t *ip, uint8_t *mask_ip,
lws_plat_if_up(ifname, fd, 1);
addr = (struct sockaddr_in *)&route.rt_gateway;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = htonl(*(uint32_t *)gateway_ip);
sin.sin_addr.s_addr = htonl(*(uint32_t *)gateway_ip);
memcpy(&route.rt_gateway, &sin, sizeof(struct sockaddr));
addr = (struct sockaddr_in *)&route.rt_dst;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = 0;
addr = (struct sockaddr_in *)&route.rt_genmask;
addr->sin_family = AF_INET;
addr->sin_addr.s_addr = 0;
sin.sin_addr.s_addr = 0;
memcpy(&route.rt_dst, &sin, sizeof(struct sockaddr));
memcpy(&route.rt_genmask, &sin, sizeof(struct sockaddr));
route.rt_flags = RTF_UP | RTF_GATEWAY;
route.rt_metric = 100;