using bind() call on FreeBSD

Jan Grant Jan.Grant at bristol.ac.uk
Wed Jun 25 05:36:34 PDT 2003


On Mon, 23 Jun 2003, Gagan Grewal wrote:

> Hi Folks :)
>
> I am trying to write a simple a server process which follows this sequence...
>   socket()
>   bind()
>   listen()
>   accept()
>     .
>     .
>     .
>   close( descriptor from accept() )
>   close( descriptor from socket() )
>
> But I am getting error 99 (Cannot assign requested address) from bind().
>
> I am trying to bind the socket on 127.0.0.1:3333
> (This works on Linux though)
>
> Are there any special/extra things I need to do in /etc or elsewhere to make
> this program run on FreeBSD ?
>
> I am running FreeBSD 4.7-RELEASE
>
> Any help/pointers from you folks would be great :)
>
> Thanks in advance :)

You don't offer any source code, but people are often "gotcha"'d by the
fact that FreeBSD really means "must be zero" when it describes spare
entries in a sockstat as MBZ. Linux doesn't care.

If you have a

	struct sockaddr_in a;

try changing it to

	struct sockaddr_in a = {};

- C semantics for structure initialisation mean that unspecified fields
are set to zero.

Cheers,
jan

-- 
jan grant, ILRT, University of Bristol. http://www.ilrt.bris.ac.uk/
Tel +44(0)117 9287088 Fax +44 (0)117 9287112 http://ioctl.org/jan/
Don't annihilate, assimilate: MacDonalds, not missiles.



More information about the freebsd-questions mailing list