summaryrefslogtreecommitdiff
path: root/lib/radsec.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2011-03-09 10:18:06 +0100
committerLinus Nordberg <linus@nordu.net>2011-03-09 10:18:06 +0100
commitce4d6dfe1728e5633a8f49fc4b16c36df0d23521 (patch)
tree679a007b7897e03e9105a0902a84a8df1356e8c7 /lib/radsec.c
parentc4e2bd206bb9248843a8a4d9a945c5e49a188474 (diff)
Add retransmission timer support (UDP).
Diffstat (limited to 'lib/radsec.c')
-rw-r--r--lib/radsec.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/radsec.c b/lib/radsec.c
index ddd4edd..ec43b2f 100644
--- a/lib/radsec.c
+++ b/lib/radsec.c
@@ -20,6 +20,7 @@
#if defined (RS_ENABLE_TLS)
#include <regex.h>
#include "debug.h"
+#include "err.h"
#include "rsp_list.h"
#include "../radsecproxy.h"
#endif
@@ -91,24 +92,44 @@ rs_context_create (struct rs_context **ctx, const char *dict)
return err;
}
-struct rs_peer *
-_rs_peer_create (struct rs_context *ctx, struct rs_peer **rootp)
+struct rs_error * /* FIXME: Return int as all the others? */
+rs_resolv (struct evutil_addrinfo **addr,
+ rs_conn_type_t type,
+ const char *hostname,
+ const char *service)
{
- struct rs_peer *p;
+ int err;
+ struct evutil_addrinfo hints, *res = NULL;
- p = (struct rs_peer *) rs_malloc (ctx, sizeof(*p));
- if (p)
+ memset (&hints, 0, sizeof(struct evutil_addrinfo));
+ hints.ai_family = AF_INET; /* IPv4 only. TODO: Set AF_UNSPEC. */
+ hints.ai_flags = AI_ADDRCONFIG;
+ switch (type)
{
- memset (p, 0, sizeof(struct rs_peer));
- if (*rootp)
- {
- p->next = (*rootp)->next;
- (*rootp)->next = p;
- }
- else
- *rootp = p;
+ case RS_CONN_TYPE_NONE:
+ return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
+ case RS_CONN_TYPE_TCP:
+ /* Fall through. */
+ case RS_CONN_TYPE_TLS:
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_protocol = IPPROTO_TCP;
+ break;
+ case RS_CONN_TYPE_UDP:
+ /* Fall through. */
+ case RS_CONN_TYPE_DTLS:
+ hints.ai_socktype = SOCK_DGRAM;
+ hints.ai_protocol = IPPROTO_UDP;
+ break;
+ default:
+ return err_create (RSE_INVALID_CONN, __FILE__, __LINE__, NULL, NULL);
}
- return p;
+ err = evutil_getaddrinfo (hostname, service, &hints, &res);
+ if (err)
+ return err_create (RSE_BADADDR, __FILE__, __LINE__,
+ "%s:%s: bad host name or service name (%s)",
+ hostname, service, evutil_gai_strerror(err));
+ *addr = res; /* Simply use first result. */
+ return NULL;
}
static void