diff options
author | Linus Nordberg <linus@nordu.net> | 2012-04-11 13:30:30 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2012-04-11 13:30:30 +0200 |
commit | 62eb41a8bf4be835265df15f0183a4682a71ba31 (patch) | |
tree | 16c06fc992aa2dd07e9898d8051f3a4c3ba74bd4 /common.c | |
parent | d40144aec7a0bf59a05f236102bf094363caa32e (diff) |
Don't cry and die on a configured server (!) which doesn't resolve (DNS). Just cry some.postpone-resolving
Part of fixing RADSECPROXY-30.
Diffstat (limited to 'common.c')
-rw-r--r-- | common.c | 72 |
1 files changed, 72 insertions, 0 deletions
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 <sys/socket.h> +/*#include <netinet/in.h>*/ +#include <netdb.h> +#include <assert.h> +#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: */ |