Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 May 2006 22:50:49 -0700
From:      John-Mark Gurney <gurney_j@resnet.uoregon.edu>
To:        David Xu <davidxu@freebsd.org>
Cc:        current@freebsd.org
Subject:   Re: couldn't bind to local address
Message-ID:  <20060521055049.GE770@funkthat.com>
In-Reply-To: <200605211204.10259.davidxu@freebsd.org>
References:  <200605211204.10259.davidxu@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
David Xu wrote this message on Sun, May 21, 2006 at 12:04 +0800:
> It is very weired that on AMD64, bind() can not bind to local address,
> the following code prints out "bind(): Can't assign requested address".

[...]

> 	struct sockaddr_in addr;

[...]

> 	addr.sin_family = AF_INET;
> 	addr.sin_port = htons(9000);
> 	addr.sin_addr.s_addr = inet_addr("127.0.0.1");

You also forgot to initalized sin_len...  I personally have adopted
the policy of using getsockaddr to initalize my addr's...  that way
if sockaddr grows any additional fields, hopefully the kernel's
getsockaddr will properly fill them out for me...

-- 
  John-Mark Gurney				Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."



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