couldn't bind to local address

Kostik Belousov kostikbel at gmail.com
Sat May 20 21:32:58 PDT 2006


On Sun, May 21, 2006 at 12:04:10PM +0800, David Xu wrote:
> 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".
> 
> David Xu
> ---
> 
> 
> include <netinet/in.h>
> #include <sys/socket.h>
> #include <stdio.h>
> 
> int main()
> {
> 	struct sockaddr_in addr;
> 	int s;
> 
> 	s = socket(AF_INET, SOCK_STREAM, 0);
> 	if (s == -1) {
> 		perror("socket()");
> 		return (1);
> 	}
> 
> 	addr.sin_family = AF_INET;
> 	addr.sin_port = htons(9000);
> 	addr.sin_addr.s_addr = inet_addr("127.0.0.1");
> 
> 	if (bind(s, (struct sockaddr *)&addr, sizeof(addr))) {
> 		perror("bind()");
> 		return (2);
> 	}
> 
> 	close(s);
> 	return (0);
> }

I tried your code on the

amd64% uname -a
FreeBSD amd64.kiev.zoral.com.ua 6.1-RELEASE FreeBSD 6.1-RELEASE #1: Fri May 12 12:05:38 UTC 2006     root@:/mnt/bsd/obj/amd64/usr/bsd/src/sys/GENERIC  amd64

and did not receive any errors. Could it be that you have lo0 misconfigured ?
What ifconfig -a show ?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20060521/765d0982/attachment.pgp


More information about the freebsd-current mailing list