From owner-freebsd-bugs Sun Jun 25 10:30: 5 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 45E2137BAEE for ; Sun, 25 Jun 2000 10:30:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id KAA89577; Sun, 25 Jun 2000 10:30:00 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: by hub.freebsd.org (Postfix, from userid 32767) id A7B0937B582; Sun, 25 Jun 2000 10:28:03 -0700 (PDT) Message-Id: <20000625172803.A7B0937B582@hub.freebsd.org> Date: Sun, 25 Jun 2000 10:28:03 -0700 (PDT) From: jan.grant@bristol.ac.uk To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: kern/19505: bind(2) erroneously complains EADDRNOTAVAIL Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >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 #include #include /* for struct sockaddr_in */ #include /* For getprotobyname */ #include /* For the ntohs, etc. */ #include /* For inet_ntoa */ #include // gethostbyname #include #include #include #include //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