From bc3326e4ac44ead72ed2484726ca3b78d4702ec5 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 11 May 2004 07:06:19 +0000 Subject: [PATCH] only set reuseaddr socket opt if regular bind call fails --- src/network.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/network.c b/src/network.c index 449dacf..3579f5a 100644 --- a/src/network.c +++ b/src/network.c @@ -27,17 +27,15 @@ int network_init(t_net *net) { addr.sin_port=htons(net->l_port); addr.sin_addr.s_addr=INADDR_ANY; - /* prevent addres in use error message */ - true=1; - if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) { - perror("[network] setsockopt call"); - return N_ERROR; - } - if(bind(net->l_fd,(struct sockaddr *)&addr, sizeof(struct sockaddr))==-1) { - perror("[network] bind call"); - return N_ERROR; + /* try harder ... */ + true=1; + if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) { + perror("[network] setsockopt call"); + return N_ERROR; + } + puts("[network] reused address"); } if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) { -- 2.39.2