along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- $Id: net.c,v 1.35.4.24 2000/08/08 17:07:47 guus Exp $
+ $Id: net.c,v 1.35.4.27 2000/09/06 11:49:03 guus Exp $
*/
#include "config.h"
rp->from = ntohl(rp->from);
total_socket_in += rp->len;
-
+
if(rp->len >= 0)
{
f = lookup_conn(rp->from);
}
else
{
- /* Can we add to queue? */
+ add_queue(&(cl->sq), rp, rp->len + 2);
if(!cl->status.waitingforkey)
send_key_request(rp->from);
}
int nfd, flags;
struct sockaddr_in a;
const int one = 1;
+ config_t const *cfg;
cp
if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
{
return -1;
}
+ if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &one, sizeof(one)))
+ {
+ syslog(LOG_ERR, _("setsockopt: %m"));
+ return -1;
+ }
+
flags = fcntl(nfd, F_GETFL);
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0)
{
return -1;
}
+ if((cfg = get_config_val(interface)))
+ {
+ if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, cfg->data.ptr, strlen(cfg->data.ptr)))
+ {
+ syslog(LOG_ERR, _("Unable to bind listen socket to interface %s: %m"), cfg->data.ptr);
+ return -1;
+ }
+ }
+
memset(&a, 0, sizeof(a));
a.sin_family = AF_INET;
a.sin_port = htons(port);
- a.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ if((cfg = get_config_val(interfaceip)))
+ a.sin_addr.s_addr = htonl(cfg->data.ip->ip);
+ else
+ a.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
{
}
flags = fcntl(cl->meta_socket, F_GETFL);
-/* if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0)
+ if(fcntl(cl->meta_socket, F_SETFL, flags | O_NONBLOCK) < 0)
{
syslog(LOG_ERR, _("fcntl for %s port %d: %m"),
cl->real_hostname, cl->port);
return -1;
}
-*/
+
if(debug_lvl > 0)
syslog(LOG_INFO, _("Connected to %s port %hd"),
cl->real_hostname, cl->port);
if(x)
{
syslog(LOG_ERR, _("Incoming data socket error for %s (%s): %s"),
- cl->vpn_hostname, cl->real_hostname, sys_errlist[x]);
+ cl->vpn_hostname, cl->real_hostname, strerror(x));
return -1;
}
if(x)
{
syslog(LOG_ERR, _("Metadata socket error for %s (%s): %s"),
- cl->vpn_hostname, cl->real_hostname, sys_errlist[x]);
+ cl->vpn_hostname, cl->real_hostname, strerror(x));
return -1;
}
- if(cl->buflen >= MAXBUFSIZE)
- {
- syslog(LOG_ERR, _("Metadata read buffer overflow!"));
- return -1;
- }
-
- lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE-cl->buflen);
+ lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE - cl->buflen);
if(lenin<=0)
{
}
}
+ if(cl->buflen >= MAXBUFSIZE)
+ {
+ syslog(LOG_ERR, _("Metadata read buffer overflow!"));
+ return -1;
+ }
+
cl->last_ping_time = time(NULL);
cl->want_ping = 0;
cp
*/
getsockopt(p->socket, SOL_SOCKET, SO_ERROR, &x, &l);
syslog(LOG_ERR, _("Outgoing data socket error for %s (%s): %s"),
- p->vpn_hostname, p->real_hostname, sys_errlist[x]);
+ p->vpn_hostname, p->real_hostname, strerror(x));
terminate_connection(p);
return;
}