diff options
-rw-r--r-- | hostport.c | 6 | ||||
-rw-r--r-- | hostport.h | 3 | ||||
-rw-r--r-- | radsecproxy.c | 14 |
3 files changed, 13 insertions, 10 deletions
@@ -14,7 +14,7 @@ #include "list.h" #include "hostport.h" -static void freehostport(struct hostportres *hp) { +void freehostport(struct hostportres *hp) { if (hp) { free(hp->host); free(hp->port); @@ -74,7 +74,7 @@ static int parsehostport(struct hostportres *hp, char *hostport, char *default_p return 1; } -static struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok) { +struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok) { struct hostportres *hp; char *slash, *s; int plen; @@ -126,7 +126,7 @@ static struct hostportres *newhostport(char *hostport, char *default_port, uint8 return NULL; } -static int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) { +int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive) { struct addrinfo hints, *res; memset(&hints, 0, sizeof(hints)); @@ -13,8 +13,11 @@ struct hostportres { struct addrinfo *addrinfo; }; +struct hostportres *newhostport(char *hostport, char *default_port, uint8_t prefixok); int addhostport(struct list **hostports, char *hostport, char *portdefault, uint8_t prefixok); +void freehostport(struct hostportres *hp); void freehostports(struct list *hostports); +int resolvehostport(struct hostportres *hp, int socktype, uint8_t passive); int resolvehostports(struct list *hostports, int socktype); struct addrinfo *resolvepassiveaddrinfo(char *hostport, char *default_port, int socktype); int addressmatches(struct list *hostports, struct sockaddr *addr); diff --git a/radsecproxy.c b/radsecproxy.c index 7266597..8df4e1d 100644 --- a/radsecproxy.c +++ b/radsecproxy.c @@ -1884,14 +1884,14 @@ void *clientwr(void *arg) { void createlistener(uint8_t type, char *arg) { pthread_t th; - struct addrinfo *listenres, *res; + struct addrinfo *res; int s = -1, on = 1, *sp = NULL; - - listenres = resolvepassiveaddrinfo(arg, protodefs[type]->portdefault, protodefs[type]->socktype); - if (!listenres) + struct hostportres *hp = newhostport(arg, protodefs[type]->portdefault, 0); + + if (!hp || !resolvehostport(hp, protodefs[type]->socktype, 1)) debugx(1, DBG_ERR, "createlistener: failed to resolve %s", arg); - for (res = listenres; res; res = res->ai_next) { + for (res = hp->addrinfo; res; res = res->ai_next) { s = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (s < 0) { debug(DBG_WARN, "createlistener: socket failed"); @@ -1920,8 +1920,8 @@ void createlistener(uint8_t type, char *arg) { if (!sp) debugx(1, DBG_ERR, "createlistener: socket/bind failed"); - debug(DBG_WARN, "createlistener: listening for %s on %s", protodefs[type]->name, arg); - freeaddrinfo(listenres); + debug(DBG_WARN, "createlistener: listening for %s on %s:%s", protodefs[type]->name, hp->host ? hp->host : "*", hp->port); + freehostport(hp); } void createlisteners(uint8_t type) { |