Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2001 20:37:31 +0300
From:      "Sergey V. Artjushkin" <skiv@caravan.ru>
To:        freebsd-net@freebsd.org
Subject:   get client ip from accept(2) ?
Message-ID:  <3C0520DB.6090009@caravan.ru>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3C0520DB.6090009>