Date: Sun, 25 Jun 2000 10:28:03 -0700 (PDT) From: jan.grant@bristol.ac.uk To: freebsd-gnats-submit@FreeBSD.org Subject: kern/19505: bind(2) erroneously complains EADDRNOTAVAIL Message-ID: <20000625172803.A7B0937B582@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 19505 >Category: kern >Synopsis: bind(2) erroneously complains EADDRNOTAVAIL >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sun Jun 25 10:30:00 PDT 2000 >Closed-Date: >Last-Modified: >Originator: jan grant >Release: 4.0-stable >Organization: university of bristol >Environment: FreeBSD tribble.ilrt.bris.ac.uk 4.0-STABLE FreeBSD 4.0-STABLE #0: Wed Jun 7 09:34:59 BS T 2000 cmjg@tribble.ilrt.bris.ac.uk:/usr/src/sys/compile/JAN i386 >Description: I've got a trivial little ip4-only program which I want to listen on 127.0.0.1.5999 only, as opposed to *.5999 (tcp socket) It fails at the call to bind: complaining that EADDRNOTAVAIL. The same program (modulo sin_len - missing on that system) works on Solaris, which leads me to believe the problem isn't with my source, but with bind. Running the program using INADDR_ANY works correctly. I've marked this as high-priority since there are some programs (named) that need this functionality. >How-To-Repeat: Trivial little program repeats the bug: compile with gcc -o test test.cc. Email me for source. #include <stdio.h> #include <sys/types.h> #include <netinet/in.h> /* for struct sockaddr_in */ #include <netdb.h> /* For getprotobyname */ #include <sys/param.h> /* For the ntohs, etc. */ #include <arpa/inet.h> /* For inet_ntoa */ #include <netdb.h> // gethostbyname #include <unistd.h> #include <unistd.h> #include <sys/socket.h> #include <errno.h> //errno, EINTR unsigned short sport = 5999; int main(int argc, char *argv[]) { struct protoent * pep = getprotobyname("tcp"); if (!pep) { perror("cannot getprotobyname tcp"); return 1; } int sd = socket(PF_INET, SOCK_STREAM, pep->p_proto); if (sd == -1) { perror("socket"); return 1; } struct hostent *he = gethostbyname("localhost"); if (!he) { perror("gethostbyname localhost"); return 2; } struct sockaddr_in addr; addr.sin_len = sizeof(addr); addr.sin_family = AF_INET; addr.sin_port = htons(sport); memcpy(&addr.sin_addr.s_addr, he->h_addr_list[0], sizeof(addr.sin_addr.s_addr)); //addr.sin_addr.s_addr = htonl(INADDR_ANY); // this works! printf("%lx\n", addr.sin_addr.s_addr); // quick check int one = 1; if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))) { perror("setsockopt"); return 2; } if (bind(sd, (const struct sockaddr *) &addr, sizeof addr)) { perror("bind"); close(sd); return 3; } // ...and listen... if (listen(sd, 5)) { perror("listen"); return 4; } close(sd); return 0; } >Fix: >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20000625172803.A7B0937B582>