From: hackbard Date: Tue, 11 May 2004 07:06:19 +0000 (+0000) Subject: only set reuseaddr socket opt if regular bind call fails X-Git-Url: https://hackdaworld.org/gitweb/?a=commitdiff_plain;h=bc3326e4ac44ead72ed2484726ca3b78d4702ec5;p=my-code%2Fivac.git only set reuseaddr socket opt if regular bind call fails --- 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) {