From a77173a7cd162a0aa47a96361a70cd43d178b4f6 Mon Sep 17 00:00:00 2001 From: brian Date: Tue, 6 Apr 1999 23:06:00 +0000 Subject: Use realhostname() rather than various combinations of gethostbyaddr() & gethostbyname(). Remove brokeness in ftpd for hosts of MAXHOSTNAMELEN length. --- libexec/tftpd/tftpd.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'libexec/tftpd/tftpd.c') diff --git a/libexec/tftpd/tftpd.c b/libexec/tftpd/tftpd.c index d0499c9..f1f8a9a 100644 --- a/libexec/tftpd/tftpd.c +++ b/libexec/tftpd/tftpd.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)tftpd.c 8.1 (Berkeley) 6/4/93"; #endif static const char rcsid[] = - "$Id: tftpd.c,v 1.11 1998/04/12 11:15:54 phk Exp $"; + "$Id: tftpd.c,v 1.12 1998/10/30 16:17:39 dg Exp $"; #endif /* not lint */ /* @@ -65,6 +65,7 @@ static const char rcsid[] = #include #include #include +#include #include #include #include @@ -108,7 +109,6 @@ static int logging; static char *errtomsg __P((int)); static void nak __P((int)); -static char *verifyhost __P((struct sockaddr_in *)); int main(argc, argv) @@ -325,8 +325,11 @@ again: } ecode = (*pf->f_validate)(&filename, tp->th_opcode); if (logging) { - syslog(LOG_INFO, "%s: %s request for %s: %s", - verifyhost(&from), + char host[MAXHOSTNAMELEN + 1]; + + realhostname(host, sizeof host - 1, &from.sin_addr); + host[sizeof host - 1] = '\0'; + syslog(LOG_INFO, "%s: %s request for %s: %s", host, tp->th_opcode == WRQ ? "write" : "read", filename, errtomsg(ecode)); } @@ -670,17 +673,3 @@ nak(error) if (send(peer, buf, length, 0) != length) syslog(LOG_ERR, "nak: %m"); } - -static char * -verifyhost(fromp) - struct sockaddr_in *fromp; -{ - struct hostent *hp; - - hp = gethostbyaddr((char *)&fromp->sin_addr, sizeof (fromp->sin_addr), - fromp->sin_family); - if (hp) - return hp->h_name; - else - return inet_ntoa(fromp->sin_addr); -} -- cgit v1.1