Date: Sat, 20 May 2006 22:47:39 -0700 From: Maxim Sobolev <sobomax@FreeBSD.ORG> To: David Xu <davidxu@FreeBSD.ORG> Cc: current@FreeBSD.ORG Subject: Re: couldn't bind to local address Message-ID: <20060521054739.GA82826@gk.360sip.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
You forgot to bzero(3) addr. This is a common mistake - obviously it has nothing to do with AMD64. -Maxim 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); > } > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org" >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060521054739.GA82826>