Date: Thu, 6 Dec 2001 17:07:51 +0200 From: Giorgos Keramidas <charon@labs.gr> To: "Sergey V. Artjushkin" <skiv@caravan.ru> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: get client ip from accept(2) ? Message-ID: <20011206150750.GI13203@hades.hell.gr> In-Reply-To: <3C052091.70205@caravan.ru> References: <3C052091.70205@caravan.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011206150750.GI13203>