Subject: Re: minimal code for a telnet-like daemon?
To: David Wetzel <dave@turbocat.de>
From: Simon Burge <simonb@netbsd.org>
List: netbsd-help
Date: 12/28/1999 15:20:25
David Wetzel wrote:
> I want to get the IP adress and host name of the remote box. The following
> is from the current fingerd.c file:
>
> -------------------------------
> if (logging) {
> sval = sizeof(ss);
> if (getpeername(0, (struct sockaddr *)&ss, &sval) < 0)
> err("getpeername: %s", strerror(errno));
> (void)getnameinfo((struct sockaddr *)&ss, sval,
> hostbuf, sizeof(hostbuf), NULL, 0, 0);
> lp = hostbuf;
> -------------------------------
>
> But getnameinfo does not exist on my netbsd 1.4.1 machine. Is there an other
> simple way to find this out?
This fragment is ipv6 aware. The code from the 1.4.1 fingerd has:
if (logging) {
sval = sizeof(sin);
if (getpeername(0, (struct sockaddr *)&sin, &sval) < 0)
err("getpeername: %s", strerror(errno));
if ((hp = gethostbyaddr((char *)&sin.sin_addr.s_addr,
sizeof(sin.sin_addr.s_addr), AF_INET)))
lp = hp->h_name;
else
lp = inet_ntoa(sin.sin_addr);
}
Note the usage of gethostbyaddr() instead of getnameinfo().
Simon.