[Midnightbsd-cvs] src [6524] trunk/usr.bin/getent/getent.c: support ipv6
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Dec 22 16:37:59 EST 2013
Revision: 6524
http://svnweb.midnightbsd.org/src/?rev=6524
Author: laffer1
Date: 2013-12-22 16:37:59 -0500 (Sun, 22 Dec 2013)
Log Message:
-----------
support ipv6
Modified Paths:
--------------
trunk/usr.bin/getent/getent.c
Modified: trunk/usr.bin/getent/getent.c
===================================================================
--- trunk/usr.bin/getent/getent.c 2013-12-22 21:35:25 UTC (rev 6523)
+++ trunk/usr.bin/getent/getent.c 2013-12-22 21:37:59 UTC (rev 6524)
@@ -277,7 +277,7 @@
static int
hosts(int argc, char *argv[])
{
- struct hostent *he;
+ struct hostent *he4, *he6;
char addr[IN6ADDRSZ];
int i, rv;
@@ -285,21 +285,31 @@
assert(argv != NULL);
sethostent(1);
+ he4 = he6 = NULL;
rv = RV_OK;
if (argc == 2) {
- while ((he = gethostent()) != NULL)
- hostsprint(he);
+ while ((he4 = gethostent()) != NULL)
+ hostsprint(he4);
} else {
for (i = 2; i < argc; i++) {
- if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0)
- he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
- else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0)
- he = gethostbyaddr(addr, INADDRSZ, AF_INET);
- else
- he = gethostbyname(argv[i]);
- if (he != NULL)
- hostsprint(he);
- else {
+ if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) {
+ he6 = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6);
+ if (he6 != NULL)
+ hostsprint(he6);
+ } else if (inet_pton(AF_INET, argv[i],
+ (void *)addr) > 0) {
+ he4 = gethostbyaddr(addr, INADDRSZ, AF_INET);
+ if (he4 != NULL)
+ hostsprint(he4);
+ } else {
+ he6 = gethostbyname2(argv[i], AF_INET6);
+ if (he6 != NULL)
+ hostsprint(he6);
+ he4 = gethostbyname(argv[i]);
+ if (he4 != NULL)
+ hostsprint(he4);
+ }
+ if ( he4 == NULL && he6 == NULL ) {
rv = RV_NOTFOUND;
break;
}
More information about the Midnightbsd-cvs
mailing list