From owner-freebsd-questions Sun May 6 10: 4:30 2001 Delivered-To: freebsd-questions@freebsd.org Received: from brainlink.com (mail.brainlink.com [149.2.32.129]) by hub.freebsd.org (Postfix) with ESMTP id 9AA5537B422 for ; Sun, 6 May 2001 10:04:26 -0700 (PDT) (envelope-from spork@gronim.com) Received: from [208.41.77.198] (HELO gronim.com) by brainlink.com (CommuniGate Pro SMTP 3.3.2) with ESMTP id 6257410 for freebsd-questions@freebsd.org; Sun, 06 May 2001 13:04:00 -0400 Received: (from spork@localhost) by gronim.com (8.11.3/8.11.0) id f46H12i65147 for freebsd-questions@freebsd.org; Sun, 6 May 2001 13:01:02 -0400 (EDT) (envelope-from spork) Date: Sun, 6 May 2001 13:01:02 -0400 From: Spike Gronim To: freebsd-questions@freebsd.org Subject: bind() on FreeBSD Message-ID: <20010506130102.A65011@spike.gronim.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Hey. The attached code snippet works correctly on Linux but not FreeBSD. On a FreeBSD system with a configured lo0, it says 'Can't assign requested address'. 'man errno' says that EADDRNOTAVAIL "Normally results from an attempt to create a socket with an address on on this machine." Can anybody help me diagnose this? Please CC directly to me, as I am not subscribed to the list. Thank you. FreeBSD/i386: 12:56 spike:~ > ifconfig lo0 lo0: flags=8049 mtu 16384 inet 127.0.0.1 netmask 0xff000000 12:56 spike:~ > ./test Binding to: 127.0.0.1 (7697) Bind error: 'Can't assign requested address' 12:56 spike:~ > uname -a FreeBSD spike.gronim.com 4.3-STABLE FreeBSD 4.3-STABLE #1: Mon Apr 23 06:51:11 EDT 2001 root@spike.gronim.com:/2/obj/3/src/sys/ZALEM4 i386 12:56 spike:~ > Linux/i386: 12:59 ernie > ifconfig lo lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:3924 Metric:1 RX packets:1126102 errors:0 dropped:0 overruns:0 frame:0 TX packets:1126102 errors:0 dropped:0 overruns:0 carrier:0 Collisions:0 12:59 ernie > ./test Binding to: 127.0.0.1 (7697) 12:59 ernie > uname -a Linux ernie 2.2.16 #1 SMP Fri Jun 9 13:16:05 EST 2000 i686 unknown 12:59 ernie > -- --Spike Gronim gronimw@stuy.edu "Oh yes? An obscene triangle which, has more courage than the word." test.c: #include #include #include #include #include #include #include #include extern int errno; int main() { int ret, listenfd; struct sockaddr_in sai; sai.sin_family = AF_INET; inet_aton("127.0.0.1",&sai.sin_addr); sai.sin_port = htons(7697); printf("Binding to: %s (%d)\n", inet_ntoa(sai.sin_addr), ntohs(sai.sin_port)); listenfd = socket(PF_INET, SOCK_STREAM, 0); ret = bind(listenfd, (struct sockaddr *)&sai, sizeof(struct sockaddr_in)); if(ret == -1) { printf("Bind error: '%s'\n",strerror(errno)); exit(1); } ret = listen(listenfd, 5); return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message