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:
parent
92ed19164c
commit
2badaef4fc
1 changed files with 5 additions and 11 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue