The ``<sys/socket.h>`` header should be included in ``src/netutils.h``
before the usage of ``struct sockaddr_storage``, otherwise build failed
with errors such as:
```
In file included from udprelay.c:53:0:
netutils.h:68:22: error: 'struct sockaddr_storage' declared inside parameter list [-Werror]
int ipv6first);
^
netutils.h:68:22: error: its scope is only this definition or declaration, which is probably not what you want [-Werror]
```
Tested on DragonFly BSD 4.9-development and Debian Linux testing.
This may fix#565
It is not recommended to compare two structs via memcmp although they have been
memset to 0.
Added two helper functions to compare sockaddr_storage, one for address only and
the other one takes port into account.
These two functions are based on Unbound version in util/net_help.c, and
comform needs of shadowsocks-libev.
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
code issues found by Clang with
CFLAGS="-Os -Wall -Wextra -Werror=unused-const-variable -Wno-error=unused-parameter"
enabled
The details as follows:
- variable initialization issue, modified them as Clang suggested
- data type mismatch when comparing, fix them either by casting or changing
the data type of index of iterator
- get_sockaddr() in netutils may return -1 thus changed returning type from
size_t to ssize_t, which makes Clang happier
- recvfrom() in udprelay is identical, fix this by creating local variable
for comparison and assign back to buf->len when returning value is acceptable
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>