summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorEric Faurot <eric@cvs.openbsd.org>2012-07-29 19:51:37 +0000
committerEric Faurot <eric@cvs.openbsd.org>2012-07-29 19:51:37 +0000
commitf07fbbf62a83ab37ff83d3143bb8ece2d1dbeeef (patch)
tree02d95c62a05a657d9d0dfc413f7bc41073da6e43 /regress
parent1a22e1823995ad9dfa59bf3c7b50c406cb6bc36d (diff)
add a flag to choose between gethostbyname and gethostbyaddr
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libc/asr/bin/gethostnamadr.c21
-rw-r--r--regress/lib/libc/asr/regress.sh4
2 files changed, 13 insertions, 12 deletions
diff --git a/regress/lib/libc/asr/bin/gethostnamadr.c b/regress/lib/libc/asr/bin/gethostnamadr.c
index 7e123654372..b1b3e331a7e 100644
--- a/regress/lib/libc/asr/bin/gethostnamadr.c
+++ b/regress/lib/libc/asr/bin/gethostnamadr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gethostnamadr.c,v 1.1 2012/07/13 17:49:54 eric Exp $ */
+/* $OpenBSD: gethostnamadr.c,v 1.2 2012/07/29 19:51:36 eric Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -40,14 +40,14 @@ usage(void)
int
main(int argc, char *argv[])
{
- int i, ch, isname, family = AF_INET;
+ int i, ch, aflag, family = AF_INET;
struct hostent *h;
char *host;
char addr[16];
- int addraf;
int addrlen;
- while((ch = getopt(argc, argv, "46e")) != -1) {
+ aflag = 0;
+ while((ch = getopt(argc, argv, "46ae")) != -1) {
switch(ch) {
case '4':
family = AF_INET;
@@ -55,6 +55,9 @@ main(int argc, char *argv[])
case '6':
family = AF_INET6;
break;
+ case 'a':
+ aflag = 1;
+ break;
case 'e':
long_err += 1;
break;
@@ -73,20 +76,18 @@ main(int argc, char *argv[])
printf("===> \"%s\"\n", argv[i]);
host = gethostarg(argv[i]);
- if (addr_from_str(addr, &addraf, &addrlen, argv[i]) == -1)
- isname = 1;
- else
- isname = 0;
+ if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1)
+ errx(1, "bad address");
errno = 0;
h_errno = 0;
gai_errno = 0;
rrset_errno = 0;
- if (isname)
+ if (aflag == 0)
h = gethostbyname2(host, family);
else
- h = gethostbyaddr(addr, addrlen, addraf);
+ h = gethostbyaddr(addr, addrlen, family);
if (h)
print_hostent(h);
print_errors();
diff --git a/regress/lib/libc/asr/regress.sh b/regress/lib/libc/asr/regress.sh
index 60b4bbf7ccf..ffd7595cba7 100644
--- a/regress/lib/libc/asr/regress.sh
+++ b/regress/lib/libc/asr/regress.sh
@@ -1,4 +1,4 @@
-# $OpenBSD: regress.sh,v 1.1 2012/07/13 17:49:53 eric Exp $
+# $OpenBSD: regress.sh,v 1.2 2012/07/29 19:51:36 eric Exp $
. regress.subr
@@ -40,7 +40,7 @@ test_gethostbyname()
test_gethostbyaddr()
{
for i in $@; do
- regress gethostnamadr $i
+ regress gethostnamadr -a $i
done
}