couldn't bind to local address
David Xu
davidxu at freebsd.org
Sat May 20 21:04:21 PDT 2006
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);
}
More information about the freebsd-current
mailing list