Date: Sun, 6 May 2001 13:01:02 -0400 From: Spike Gronim <william@brainlink.com> To: freebsd-questions@freebsd.org Subject: bind() on FreeBSD Message-ID: <20010506130102.A65011@spike.gronim.com>
next in thread | raw e-mail | index | archive | help
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<UP,LOOPBACK,RUNNING,MULTICAST> 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010506130102.A65011>
