From owner-freebsd-questions Thu Dec 6 7:19:13 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id DAD2337B405 for ; Thu, 6 Dec 2001 07:19:08 -0800 (PST) Received: from hades.hell.gr (patr530-a110.otenet.gr [212.205.215.110]) by mailsrv.otenet.gr (8.11.5/8.11.5) with ESMTP id fB6FIxd13596; Thu, 6 Dec 2001 17:19:01 +0200 (EET) Received: (from charon@localhost) by hades.hell.gr (8.11.6/8.11.6) id fB6F7pn15979; Thu, 6 Dec 2001 17:07:51 +0200 (EET) (envelope-from charon@labs.gr) Date: Thu, 6 Dec 2001 17:07:51 +0200 From: Giorgos Keramidas To: "Sergey V. Artjushkin" Cc: freebsd-questions@FreeBSD.ORG Subject: Re: get client ip from accept(2) ? Message-ID: <20011206150750.GI13203@hades.hell.gr> References: <3C052091.70205@caravan.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3C052091.70205@caravan.ru> User-Agent: Mutt/1.3.23.2i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On 2001-11-28 20:36:17, 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); } > ---------------------------------------- Unless I have missed something, in your program (this is far from a complete source fragment, no types of variables are shown), you should be able to use `l_cliaddr.sin_addr.s_addr' to get the IP address of the client in network byte-order after your accept() call finishes. -giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message