From owner-freebsd-net Wed Nov 28 11:50:11 2001 Delivered-To: freebsd-net@freebsd.org Received: from tp.databus.com (p101-46.acedsl.com [160.79.101.46]) by hub.freebsd.org (Postfix) with ESMTP id F067437B405 for ; Wed, 28 Nov 2001 11:50:02 -0800 (PST) Received: (from barney@localhost) by tp.databus.com (8.11.6/8.11.4) id fASJnoc16044; Wed, 28 Nov 2001 14:49:50 -0500 (EST) (envelope-from barney) Date: Wed, 28 Nov 2001 14:49:49 -0500 From: Barney Wolff To: "Sergey V. Artjushkin" Cc: freebsd-net@FreeBSD.ORG Subject: Re: get client ip from accept(2) ? Message-ID: <20011128144949.A16005@tp.databus.com> References: <3C0520DB.6090009@caravan.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <3C0520DB.6090009@caravan.ru>; from skiv@caravan.ru on Wed, Nov 28, 2001 at 08:37:31PM +0300 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 You probably forgot to initialize l_addrlen to sizeof(sockaddr_in). (As well as needing the & before l_cliaddr, but that's probably a typo as it wouldn't compile without it.) On Wed, Nov 28, 2001 at 08:37:31PM +0300, Sergey V. Artjushkin wrote: > Hello > > Colleagues, I have some question about accept(2) functions. > I have wrote the following programm: > > ------------------------------- > /* set up the listening tcp socket*/ > if ( (l_fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) > { log_error("socket (tcp) error"); exit(0); } > memset(&l_servaddr,0,sizeof(l_servaddr)); > l_servaddr.sin_family = AF_INET; > l_servaddr.sin_addr.s_addr = htonl(INADDR_ANY); > l_servaddr.sin_port = htons(c_tcpport); > > if ( bind(l_fd,(struct sockaddr *) &l_servaddr, sizeof(l_servaddr)) < 0) > { log_error ("bind TCP error"); exit(0); } > > if ( listen(l_fd, 32) < 0) > { log_error("listen error"); exit(0); } > > if ( (l_connfd = accept(l_fd,(struct sockaddr *) l_cliaddr, &l_addrlen)) > < 0) > { log_error("accept error"); exit(0); } > ---------------------------------------- > > I'm trying to find out the client ip that connects to this server. > But l_cliaddr structure is NULL after succesfull accept call. > As I understand from manuals in this structure must be client ip. > Where I'm wrong and how I can get this ip? > > Thank you for advance. > > -- > With best regards. > ------------------------------------------------------------------ > Sergey Artjushkin Network Operation Center > (SKIV-RIPE) ISP "CARAVAN" > > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-net" in the body of the message -- Barney Wolff "Nonetheless, ease and peace had left this people still curiously tough. They were, if it came to it, difficult to daunt or to kill; and they were, perhaps, so unwearyingly fond of good things not least because they could, when put to it, do without them, and could survive rough handling by grief, foe, or weather in a way that astonished those who did not know them well and looked no further than their bellies and their well-fed faces." J.R.R.T. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message