diff --git a/src/netutl.c b/src/netutl.c index fab3fc78..43409197 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -54,6 +54,25 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock return ai; } +/* + Turn a configuration Address string into addrinfo. +*/ +struct addrinfo *config_address2addrinfo(char *address, int socktype) { + struct addrinfo *ai; + char *space, *port; + space = strchr(address, ' '); + if(space) { + port = xstrdup(space + 1); + *space = 0; + } else + port = xstrdup("655"); + + ai = str2addrinfo(address, port, socktype); + free(port); + + return ai; +} + sockaddr_t str2sockaddr(const char *address, const char *port) { struct addrinfo *ai, hint; sockaddr_t result; diff --git a/src/netutl.h b/src/netutl.h index 471cae7f..5b0166a8 100644 --- a/src/netutl.h +++ b/src/netutl.h @@ -26,6 +26,7 @@ extern bool hostnames; extern struct addrinfo *str2addrinfo(const char *, const char *, int) __attribute__ ((__malloc__)); +extern struct addrinfo *config_address2addrinfo(char *, int); extern sockaddr_t str2sockaddr(const char *, const char *); extern void sockaddr2str(const sockaddr_t *, char **, char **); extern char *sockaddr2hostname(const sockaddr_t *) __attribute__ ((__malloc__));