From owner-freebsd-stable@FreeBSD.ORG Wed Jan 7 12:46:37 2004 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 66F5116A4CE for ; Wed, 7 Jan 2004 12:46:37 -0800 (PST) Received: from deepblack.lolitacoders.org (deepblack.lolitacoders.org [213.221.113.38]) by mx1.FreeBSD.org (Postfix) with ESMTP id DCBA543D48 for ; Wed, 7 Jan 2004 12:46:31 -0800 (PST) (envelope-from chris@schwer.bewaff.net) Received: from schwer.bewaff.net (ip129.76.1311A-CUD12K-01.ish.de [62.143.76.129]) (using TLSv1 with cipher DES-CBC3-SHA (168/168 bits)) (No client certificate requested) by deepblack.lolitacoders.org (Postfix) with ESMTP id 5EA528842 for ; Wed, 7 Jan 2004 21:46:30 +0100 (CET) Date: Wed, 7 Jan 2004 21:46:28 +0100 Mime-Version: 1.0 (Apple Message framework v553) Content-Type: text/plain; charset=US-ASCII; format=flowed From: Christian Klein To: freebsd-stable@freebsd.org Content-Transfer-Encoding: 7bit Message-Id: <91136089-4152-11D8-942B-000393076EEC@schwer.bewaff.net> X-Mailer: Apple Mail (2.553) Subject: getsockname() X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jan 2004 20:46:37 -0000 Hi, I have a problem that is similar to the problem described in http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/22868 My program, that opens a tcp socket and binds to INADDR_ANY:0, getsockname() returns either the correct answer or, for some time, a wrong answer, see below (this is of course not my program, just some code that does the same) --- snipp --- #include #include #include #include #include #include #include int main() { int sock, len; struct sockaddr_in addr, foo; if((sock=socket(AF_INET, SOCK_STREAM, 0))<0) { exit(0); } memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(0); if(bind(sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))<0) { perror("bind"); exit(0); } if(listen(sock, 5)<0) { perror("listen"); exit(0); } getsockname(sock, (struct sockaddr *) &foo, &len); fprintf(stderr, "listening on %s:%d\n", inet_ntoa(foo.sin_addr), ntohs(foo.sin_port)); return 0; } --- snap --- $ ./a.out listening on 86.186.4.40:49087 $ ./a.out listening on 0.0.0.0:3810 regards, Chris PS: It is even stranger than I thought, I compiled this program: gcc -o freebsd freebsd.c and ran it serveral times: $ ./freebsd listening on 86.186.4.40:49087 $ mv freebsd a.out $ ./a.out listening on 0.0.0.0:4364 $ mv a.out freebsd $ ./freebsd listening on 86.186.4.40:49087 $ mv freebsd a.out $ ./a.out listening on 0.0.0.0:4604