Re: couldn't bind to local address

From: John-Mark Gurney <gurney_j_at_resnet.uoregon.edu>
Date: Sat, 20 May 2006 22:50:49 -0700
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."
Received on Sun May 21 2006 - 03:50:59 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:56 UTC