diff --git a/src/libckpool.c b/src/libckpool.c index 7f3f350f..f4a28271 100644 --- a/src/libckpool.c +++ b/src/libckpool.c @@ -434,6 +434,23 @@ bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port) return true; } +bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addrinfo) +{ + struct addrinfo *servinfo, hints; + + memset(&hints, 0, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + servinfo = addrinfo; + if (getaddrinfo(url, port, &hints, &servinfo) != 0) + return false; + if (!servinfo) + return false; + memcpy(addrinfo, servinfo->ai_addr, sizeof(struct addrinfo)); + freeaddrinfo(servinfo); + return true; +} + void keep_sockalive(int fd) { const int tcp_one = 1; diff --git a/src/libckpool.h b/src/libckpool.h index ecd9465d..26994aa7 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -423,6 +424,7 @@ static inline bool sock_timeout(void) bool extract_sockaddr(char *url, char **sockaddr_url, char **sockaddr_port); bool url_from_sockaddr(const struct sockaddr *addr, char *url, char *port); +bool addrinfo_from_url(const char *url, const char *port, struct addrinfo *addrinfo); void keep_sockalive(int fd); void nolinger_socket(int fd); void noblock_socket(int fd);