*BSD News Article 72496


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.anu.edu.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!qns3.qns.net!imci4!newsfeed.internetmci.com!howland.reston.ans.net!surfnet.nl!tuegate.tue.nl!news.win.tue.nl!il.ft.hse.nl!not-for-mail
From: robert@il.ft.hse.nl (robert)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: can't bind local address
Date: 1 Jul 1996 12:01:55 +0200
Organization: LSD...melts in your mind, not in your hand
Lines: 25
Message-ID: <4r87mj$kgv@charm.il.ft.hse.nl>
References: <31D3D501.2D1C@job-link.com>
NNTP-Posting-Host: charm.il.ft.hse.nl

Charles Boesel <webguy@job-link.com>:
 >I'm trying to run a server daemon on FreeBSD2.1
 >and whenever I try to run it I get this message:
 >"can't bind local address"
 >What would cause this and how do I fix it?

Something's already on the port you try to bind() your socket to, _or_ the
socket is in SOCK_WAIT state..which means there's nothing connected to it,
but the kernel hasn't freed its resources yet.

To fix it, either wait, kill the process which is on the port (hmmm, might
be a tough thing to find out who's on it...try lsof if you have it, or get
charm.il.ft.hse.nl:/pub/perl/nstat.pl, a perl script which you can use to
find out things like that), or add the following code to the server's code
(providing you have it):

/* 'sock' is the socket descriptor */
int	opt = 1, sock;
...
(void) setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int));
...

(add this _before_ you bind()).

                                                                robert