diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/util_net.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/util/util_net.c b/lib/util/util_net.c index eb5e2255c9..228393a2bb 100644 --- a/lib/util/util_net.c +++ b/lib/util/util_net.c @@ -408,3 +408,17 @@ bool is_address_any(const struct sockaddr *psa) } return false; } + +void set_sockaddr_port(struct sockaddr *psa, uint16_t port) +{ +#if defined(HAVE_IPV6) + if (psa->sa_family == AF_INET6) { + ((struct sockaddr_in6 *)psa)->sin6_port = htons(port); + } +#endif + if (psa->sa_family == AF_INET) { + ((struct sockaddr_in *)psa)->sin_port = htons(port); + } +} + + |