Skip to content

Commit

Permalink
Add sa_is_wildcard() helper to socket-utils.h
Browse files Browse the repository at this point in the history
  • Loading branch information
greghudson committed Jan 9, 2017
1 parent d005bea commit 715b397
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/include/socket-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ sa_is_inet(struct sockaddr *sa)
return sa->sa_family == AF_INET || sa->sa_family == AF_INET6;
}

/* Return true if sa is an IPv4 or IPv6 wildcard address. */
static inline int
sa_is_wildcard(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET6)
return IN6_IS_ADDR_UNSPECIFIED(&sa2sin6(sa)->sin6_addr);
else if (sa->sa_family == AF_INET)
return sa2sin(sa)->sin_addr.s_addr == INADDR_ANY;
return 0;
}

/* Return the length of an IPv4 or IPv6 socket structure; abort if it is
* neither. */
static inline socklen_t
Expand Down

0 comments on commit 715b397

Please sign in to comment.