diff --git a/lib/socket.c b/lib/socket.c index 4a339a8a2..41250571c 100644 --- a/lib/socket.c +++ b/lib/socket.c @@ -21,8 +21,8 @@ static unsigned int __ip4_hash(const sockaddr_t *a); static unsigned int __ip6_hash(const sockaddr_t *a); static int __ip4_eq(const sockaddr_t *a, const sockaddr_t *b); static int __ip6_eq(const sockaddr_t *a, const sockaddr_t *b); -static int __ip4_is_specified(const sockaddr_t *a); -static int __ip6_is_specified(const sockaddr_t *a); +static bool __ip4_is_specified(const sockaddr_t *a); +static bool __ip6_is_specified(const sockaddr_t *a); static int __ip_bind(socket_t *s, unsigned int, const sockaddr_t *); static int __ip_connect(socket_t *s, const endpoint_t *); static int __ip_listen(socket_t *s, int backlog); @@ -203,10 +203,10 @@ static int __ip4_eq(const sockaddr_t *a, const sockaddr_t *b) { static int __ip6_eq(const sockaddr_t *a, const sockaddr_t *b) { return !memcmp(&a->ipv6, &b->ipv6, sizeof(a->ipv6)); } -static int __ip4_is_specified(const sockaddr_t *a) { +static bool __ip4_is_specified(const sockaddr_t *a) { return a->ipv4.s_addr != 0; } -static int __ip6_is_specified(const sockaddr_t *a) { +static bool __ip6_is_specified(const sockaddr_t *a) { return a->ipv6.s6_addr32[0] != 0 || a->ipv6.s6_addr32[1] != 0 || a->ipv6.s6_addr32[2] != 0 diff --git a/lib/socket.h b/lib/socket.h index 4b8daae3f..aed52957e 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -65,7 +65,7 @@ struct socket_family { int (*addr_parse)(sockaddr_t *, const char *); bool (*addr_print)(const sockaddr_t *, char *, size_t); bool (*addr_print_p)(const sockaddr_t *, char *, size_t); - int (*is_specified)(const sockaddr_t *); + bool (*is_specified)(const sockaddr_t *); int (*sockaddr2endpoint)(endpoint_t *, const void *); int (*endpoint2sockaddr)(void *, const endpoint_t *); int (*addrport2sockaddr)(void *, const sockaddr_t *, unsigned int); @@ -175,9 +175,9 @@ INLINE bool endpoint_print(const endpoint_t *ep, char *buf, size_t len) { INLINE char *endpoint_print_buf(const endpoint_t *ep) { return sockaddr_print_port_buf(&ep->address, ep->port); } -INLINE int is_addr_unspecified(const sockaddr_t *a) { +INLINE bool is_addr_unspecified(const sockaddr_t *a) { if (!a || !a->family) - return 1; + return true; return !a->family->is_specified(a); } #define socket_recvfrom(s,a...) (s)->family->recvfrom((s), a)