From 62eb41a8bf4be835265df15f0183a4682a71ba31 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 11 Apr 2012 13:30:30 +0200 Subject: Don't cry and die on a configured server (!) which doesn't resolve (DNS). Just cry some. Part of fixing RADSECPROXY-30. --- common.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 common.c (limited to 'common.c') diff --git a/common.c b/common.c new file mode 100644 index 0000000..6a73a2c --- /dev/null +++ b/common.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2012 NORDUnet A/S + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + */ + +#include +/*#include */ +#include +#include +#include "radsecproxy.h" +#include "debug.h" +#include "hostport.h" +#include "util.h" +#include "common.h" + +int +addserverextra(const struct clsrvconf *conf, + int *socket4, + int *socket6, + struct addrinfo *addrinfo) +{ + struct hostportres *hp = NULL; + + assert(conf != NULL); + assert(socket != NULL); + + if (list_first(conf->hostports) == NULL) + return 0; + hp = (struct hostportres *) list_first(conf->hostports)->data; + if (hp == NULL || hp->addrinfo == NULL) + return 0; + + switch (hp->addrinfo->ai_family) { + case AF_INET: + if (*socket4 < 0) { + /* FIXME: arg 4 is v6only, wtf? */ + *socket4 = bindtoaddr(addrinfo, AF_INET, 0, 1); + if (*socket4 < 0) { + debug(DBG_ERR, + "%s: failed to create client socket for server %s", + __func__, conf->name); + return 0; + } + } + conf->servers->sock = *socket4; + break; + case AF_INET6: + if (*socket6 < 0) { + *socket6 = bindtoaddr(addrinfo, AF_INET6, 0, 1); + if (*socket6 < 0) { + debug(DBG_ERR, + "%s: failed to create client socket for server %s", + __func__, conf->name); + return 0; + } + } + conf->servers->sock = *socket6; + break; + default: + debug(DBG_ERR, "%s: unsupported address family", __func__); + return 0; + } + + return 1; +} + +/* Local Variables: */ +/* c-file-style: "stroustrup" */ +/* End: */ -- cgit v1.1