aboutsummaryrefslogtreecommitdiff
path: root/lib/libutil
diff options
context:
space:
mode:
authorBrian Somers <brian@FreeBSD.org>2001-01-28 21:51:25 +0000
committerBrian Somers <brian@FreeBSD.org>2001-01-28 21:51:25 +0000
commitf169f2f02076be4e42f51c62f3d09d0e319cc900 (patch)
treee28469cbabe37fbab94a645fd42026903d6f0a1a /lib/libutil
parent0212e4b63beda1f0cb9e9451746559994ec8a6ab (diff)
downloadsrc-f169f2f02076be4e42f51c62f3d09d0e319cc900.tar.gz
src-f169f2f02076be4e42f51c62f3d09d0e319cc900.zip
Call trimdomain properly for ip4 addresses.
PR: 24659 realhostname_sa() stuff submitted by: Jim.Pirzyk@disney.com
Notes
Notes: svn path=/head/; revision=71753
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/realhostname.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/lib/libutil/realhostname.c b/lib/libutil/realhostname.c
index a6f10d689300..26bd5e6174ea 100644
--- a/lib/libutil/realhostname.c
+++ b/lib/libutil/realhostname.c
@@ -52,28 +52,33 @@ struct sockinet {
int
realhostname(char *host, size_t hsize, const struct in_addr *ip)
{
+ char trimmed[MAXHOSTNAMELEN+1];
int result;
struct hostent *hp;
result = HOSTNAME_INVALIDADDR;
hp = gethostbyaddr((char *)ip, sizeof(*ip), AF_INET);
- if (hp != NULL && strlen(hp->h_name) <= hsize) {
- char lookup[MAXHOSTNAMELEN];
-
- strncpy(lookup, hp->h_name, sizeof(lookup) - 1);
- lookup[sizeof(lookup) - 1] = '\0';
- hp = gethostbyname(lookup);
- if (hp == NULL)
- result = HOSTNAME_INVALIDNAME;
- else for (; ; hp->h_addr_list++) {
- if (hp->h_addr_list[0] == NULL) {
- result = HOSTNAME_INCORRECTNAME;
- break;
- }
- if (!memcmp(*hp->h_addr_list, ip, sizeof(*ip))) {
- strncpy(host, lookup, hsize);
- return HOSTNAME_FOUND;
+ if (hp != NULL) {
+ strlcpy(trimmed, hp->h_name, sizeof(trimmed));
+ trimdomain(trimmed, strlen(trimmed));
+ if (strlen(trimmed) <= hsize) {
+ char lookup[MAXHOSTNAMELEN];
+
+ strncpy(lookup, hp->h_name, sizeof(lookup) - 1);
+ lookup[sizeof(lookup) - 1] = '\0';
+ hp = gethostbyname(lookup);
+ if (hp == NULL)
+ result = HOSTNAME_INVALIDNAME;
+ else for (; ; hp->h_addr_list++) {
+ if (*hp->h_addr_list == NULL) {
+ result = HOSTNAME_INCORRECTNAME;
+ break;
+ }
+ if (!memcmp(*hp->h_addr_list, ip, sizeof(*ip))) {
+ strncpy(host, trimmed, hsize);
+ return HOSTNAME_FOUND;
+ }
}
}
}
@@ -131,20 +136,15 @@ realhostname_sa(char *host, size_t hsize, struct sockaddr *addr, int addrlen)
freeaddrinfo(ores);
goto numeric;
}
- if (strlen(ores->ai_canonname) > hsize) {
- if (addr->sa_family == AF_INET) {
- freeaddrinfo(ores);
- goto numeric;
- }
- strncpy(buf,
- ores->ai_canonname,
- sizeof(buf));
- trimdomain(buf, hsize);
- strncpy(host, buf, hsize);
- } else
- strncpy(host,
- ores->ai_canonname,
- hsize);
+ strncpy(buf, ores->ai_canonname,
+ sizeof(buf));
+ trimdomain(buf, hsize);
+ strncpy(host, buf, hsize);
+ if (strlen(host) > hsize &&
+ addr->sa_family == AF_INET) {
+ freeaddrinfo(ores);
+ goto numeric;
+ }
break;
}
((struct sockinet *)addr)->si_port = port;