From e153afc401ccb9256385a0a3da10bf412d87fe1f Mon Sep 17 00:00:00 2001 From: venaas Date: Thu, 18 Sep 2008 11:10:44 +0000 Subject: fixed some bugs, improved duplicate detection git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@391 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- udp.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) (limited to 'udp.c') diff --git a/udp.c b/udp.c index 6b49e49..05e7a6b 100644 --- a/udp.c +++ b/udp.c @@ -47,6 +47,7 @@ unsigned char *radudpget(int s, struct client **client, struct server **server, struct clsrvconf *p; struct list_node *node; fd_set readfds; + struct client *c = NULL; for (;;) { if (rad) { @@ -103,26 +104,27 @@ unsigned char *radudpget(int s, struct client **client, struct server **server, if (client) { pthread_mutex_lock(p->lock); - for (node = list_first(p->clients); node; node = list_next(node)) - if (addr_equal((struct sockaddr *)&from, ((struct client *)node->data)->addr)) + for (node = list_first(p->clients); node; node = list_next(node)) { + c = (struct client *)node->data; + if (s == c->sock && addr_equal((struct sockaddr *)&from, c->addr)) break; - if (node) { - *client = (struct client *)node->data; - pthread_mutex_unlock(p->lock); - break; } - fromcopy = addr_copy((struct sockaddr *)&from); - if (!fromcopy) { - pthread_mutex_unlock(p->lock); - continue; + if (!node) { + fromcopy = addr_copy((struct sockaddr *)&from); + if (!fromcopy) { + pthread_mutex_unlock(p->lock); + continue; + } + c = addclient(p, 0); + if (!c) { + free(fromcopy); + pthread_mutex_unlock(p->lock); + continue; + } + c->sock = s; + c->addr = fromcopy; } - *client = addclient(p, 0); - if (!*client) { - free(fromcopy); - pthread_mutex_unlock(p->lock); - continue; - } - (*client)->addr = fromcopy; + *client = c; pthread_mutex_unlock(p->lock); } else if (server) *server = p->servers; -- cgit v1.1