Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Dec 2001 23:47:21 +1100
From:      Edwin Groothuis <edwin@mavetju.org>
To:        Lance Bland <lbland@vvi.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: bind() error on stale port ...
Message-ID:  <20011203234721.B546@k7.mavetju.org>
In-Reply-To: <5DF8B77C-E7EB-11D5-A5E1-0030659A531A@vvi.com>; from lbland@vvi.com on Mon, Dec 03, 2001 at 07:43:35AM -0500
References:  <5DF8B77C-E7EB-11D5-A5E1-0030659A531A@vvi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Dec 03, 2001 at 07:43:35AM -0500, Lance Bland wrote:
> hi-
> 
> I get an error on bind() this way:
> 
> Start process that calls bind()
> Kill process
> Start same process up right away.
> -> bind() error
> 
> The reason is because the port is settling down from the last process 
> run before it is put back in the pool of available pool of ports.
> 
> I fixed this before with a call to some function (I think that was 
> sysctl()??) that said "dereference port immediately when process is no 
> longer around".
> 
> The problem is: I can't remember the function I called, and the flag it 
> needed. It was simple and worked, I just can't remember it.

You do it with setsockopt and SO_REUSEADDR:

    int x=1;
    if (setsockopt(fd6,SOL_SOCKET,SO_REUSEADDR,(char *)&x,sizeof(x))<0) {
	bugf("init_socket6(): SO_REUSEADDR: %s",ERROR);
	exit(1);
    }

Edwin

-- 
Edwin Groothuis   |              Personal website: http://www.MavEtJu.org
edwin@mavetju.org |           Interested in MUDs? Visit Fatal Dimensions:
------------------+                       http://www.FatalDimensions.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011203234721.B546>