Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Nov 2001 14:49:49 -0500
From:      Barney Wolff <barney@databus.com>
To:        "Sergey V. Artjushkin" <skiv@caravan.ru>
Cc:        freebsd-net@FreeBSD.ORG
Subject:   Re: get client ip from accept(2) ?
Message-ID:  <20011128144949.A16005@tp.databus.com>
In-Reply-To: <3C0520DB.6090009@caravan.ru>; from skiv@caravan.ru on Wed, Nov 28, 2001 at 08:37:31PM %2B0300
References:  <3C0520DB.6090009@caravan.ru>

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




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