From owner-freebsd-hackers Fri Dec 6 11:55:35 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E9C5337B401 for ; Fri, 6 Dec 2002 11:55:33 -0800 (PST) Received: from ack.Berkeley.EDU (ack.Berkeley.EDU [128.32.206.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8120C43EA9 for ; Fri, 6 Dec 2002 11:55:33 -0800 (PST) (envelope-from mhunter@ack.Berkeley.EDU) Received: (from mhunter@localhost) by ack.Berkeley.EDU (8.9.3+Sun/8.9.3) id LAA16710; Fri, 6 Dec 2002 11:55:30 -0800 (PST) Date: Fri, 6 Dec 2002 11:55:30 -0800 From: Mike Hunter To: dslb@tiscali.dk Cc: hackers@FreeBSD.ORG Subject: Re: accept() Message-ID: <20021206115530.A16665@ack.Berkeley.EDU> References: <3D9FE7F600009214@cpfe5.be.tisc.dk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3D9FE7F600009214@cpfe5.be.tisc.dk>; from dslb@tiscali.dk on Fri, Dec 06, 2002 at 08:50:46PM +0100 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Dec 06, "dslb@tiscali.dk" wrote: > Hi all > > When using accept() with: > int sd_client = accept(socket_descriptor, (sockaddr *)&client, > (socklen_t *) sizeof(client)); > > Accept return -1 and 14 in errno, but when I use: > > socklen_t alen; > int sd_client = accept(socket_descriptor, (sockaddr *)&client, &alen); > > It works fine. Why can't you use the first method? There must be a way > to avoid creating a variable just to hold the address?!?!? You have to use a variable because accept may write to it (?). From the man page: The addrlen is a value-result parameter; it should initially contain the amount of space pointed to by addr; on return it will contain the actual length (in bytes) of the address returned. It doesn't make sense to cast the results of sizeof to a pointer. Mike -- Hi William. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message