From owner-freebsd-stable@FreeBSD.ORG Wed Jan 7 13:41:03 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 9487616A4CE for ; Wed, 7 Jan 2004 13:41:03 -0800 (PST) Received: from shell.webmaster.com (mail.webmaster.com [216.152.64.131]) by mx1.FreeBSD.org (Postfix) with ESMTP id 858D243D1F for ; Wed, 7 Jan 2004 13:41:00 -0800 (PST) (envelope-from davids@webmaster.com) Received: from however ([206.171.168.138]) by shell.webmaster.com (Post.Office MTA v3.5.3 release 223 ID# 0-12345L500S10000V35) with SMTP id com; Wed, 7 Jan 2004 13:40:57 -0800 From: "David Schwartz" To: "Christian Klein" , Date: Wed, 7 Jan 2004 13:40:54 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <91136089-4152-11D8-942B-000393076EEC@schwer.bewaff.net> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2055 Importance: Normal Subject: RE: 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 21:41:03 -0000 > (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; Okay, you haven't set the value of '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); Hmm, you still haven't set the value of 'len'. And you ignore the return value of 'getsockname'. > fprintf(stderr, "listening on %s:%d\n", inet_ntoa(foo.sin_addr), > ntohs(foo.sin_port)); > > return 0; > } > $ ./a.out > listening on 86.186.4.40:49087 > $ ./a.out > listening on 0.0.0.0:3810 Fix those two bugs and see if you still have a problem. DS