From owner-freebsd-net Fri Jan 11 16:55:41 2002 Delivered-To: freebsd-net@freebsd.org Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by hub.freebsd.org (Postfix) with ESMTP id 6410B37B405 for ; Fri, 11 Jan 2002 16:55:35 -0800 (PST) Received: by elvis.mu.org (Postfix, from userid 1192) id 4496110DDF8; Fri, 11 Jan 2002 16:55:35 -0800 (PST) Date: Fri, 11 Jan 2002 16:55:35 -0800 From: Alfred Perlstein To: Abel Alejandro Cc: freebsd-net@freebsd.org, elec@chatpr.org Subject: Re: Problems with inet_ntop Message-ID: <20020111165535.U7984@elvis.mu.org> References: <20020111204406.N98793-100000@www.chatpr.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <20020111204406.N98793-100000@www.chatpr.org>; from elec@www.chatpr.org on Fri, Jan 11, 2002 at 08:49:35PM -0400 Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org * Abel Alejandro [020111 16:49] wrote: > Hello, a while ago I come with a kqueue example for FreeBSD. > The source is at: http://www.monkeys.com/freeware/kqueue-echo.c > > The problem is after getting used to the code, i wanted to know the IP of > the incoming connections, so I used inet_ntop for this. > > My problem is that on the very first connection kqueue-echo receives, > inet_ntop prints a bad address, however after this first connection it > starts printing the ip address correctly. > > The source for the tweaked kqueue-echo.c is at: > http://core.friendspr.com/~elec/kqueue-echo.c static void do_accept (register struct kevent const *const kep) { auto sockaddr_in sin; auto socklen_t sinsiz; register int s; register ecb *ecbp; char ok[200]; if ((s = accept (kep->ident, (struct sockaddr *)&sin, &sinsiz)) == -1) fatal ("Error in accept(): %s", strerror (errno)); OOPS! You're missing: sinsiz = sizeof(sin); before the call to accept. -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' Tax deductable donations for FreeBSD: http://www.freebsdfoundation.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message