From 2e4e8b5fd240d7f3647ba662b43d4e28f62260d7 Mon Sep 17 00:00:00 2001 From: venaas Date: Tue, 27 Jan 2009 14:02:35 +0000 Subject: rewriting code for hosts,ports,resolving,builds but needs testing git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@462 e88ac4ed-0b26-0410-9574-a7f39faa03bf --- tcp.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tcp.c') diff --git a/tcp.c b/tcp.c index 00c796d..43a0489 100644 --- a/tcp.c +++ b/tcp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Stig Venaas + * Copyright (C) 2008-2009 Stig Venaas * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -25,6 +25,7 @@ #include #include #include "list.h" +#include "hostport.h" #include "radsecproxy.h" #ifdef RADPROT_TCP @@ -78,9 +79,9 @@ static char **getlistenerargs() { void tcpsetsrcres() { if (!srcres) - srcres = resolve_hostport_addrinfo(handle, protoopts ? protoopts->sourcearg : NULL); + srcres = resolvepassiveaddrinfo(protoopts ? protoopts->sourcearg : NULL, NULL, protodefs.socktype); } - + int tcpconnect(struct server *server, struct timeval *when, int timeout, char *text) { struct timeval now; time_t elapsed; @@ -117,14 +118,12 @@ int tcpconnect(struct server *server, struct timeval *when, int timeout, char *t sleep(60); } else server->lastconnecttry.tv_sec = now.tv_sec; /* no sleep at startup */ - debug(DBG_WARN, "tcpconnect: trying to open TCP connection to %s port %s", server->conf->host, server->conf->port); + if (server->sock >= 0) close(server->sock); - if ((server->sock = connecttcp(server->conf->addrinfo, srcres)) >= 0) + if ((server->sock = connecttcphostlist(server->conf->hostports, srcres)) >= 0) break; - debug(DBG_ERR, "tcpconnect: connecttcp failed"); } - debug(DBG_WARN, "tcpconnect: TCP connection to %s port %s up", server->conf->host, server->conf->port); server->connectionok = 1; gettimeofday(&server->lastconnecttry, NULL); pthread_mutex_unlock(&server->lock); @@ -210,7 +209,7 @@ int clientradputtcp(struct server *server, unsigned char *rad) { debug(DBG_ERR, "clientradputtcp: write error"); return 0; } - debug(DBG_DBG, "clientradputtcp: Sent %d bytes, Radius packet of length %d to TCP peer %s", cnt, len, conf->host); + debug(DBG_DBG, "clientradputtcp: Sent %d bytes, Radius packet of length %d to TCP peer %s", cnt, len, conf->name); return 1; } -- cgit v1.1