diff options
Diffstat (limited to 'src/regress/lib/libc/asr/bin/gethostnamadr.c')
-rw-r--r-- | src/regress/lib/libc/asr/bin/gethostnamadr.c | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr.c b/src/regress/lib/libc/asr/bin/gethostnamadr.c deleted file mode 100644 index 9cdf7ed448..0000000000 --- a/src/regress/lib/libc/asr/bin/gethostnamadr.c +++ /dev/null | |||
@@ -1,116 +0,0 @@ | |||
1 | /* $OpenBSD: gethostnamadr.c,v 1.3 2018/12/15 15:16:12 eric Exp $ */ | ||
2 | /* | ||
3 | * Copyright (c) 2012 Eric Faurot <eric@openbsd.org> | ||
4 | * | ||
5 | * Permission to use, copy, modify, and distribute this software for any | ||
6 | * purpose with or without fee is hereby granted, provided that the above | ||
7 | * copyright notice and this permission notice appear in all copies. | ||
8 | * | ||
9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
16 | */ | ||
17 | #include <sys/types.h> | ||
18 | #include <sys/socket.h> | ||
19 | #include <netinet/in.h> | ||
20 | #include <arpa/inet.h> | ||
21 | |||
22 | #include <err.h> | ||
23 | #include <errno.h> | ||
24 | #include <getopt.h> | ||
25 | #include <stdio.h> | ||
26 | #include <stdlib.h> | ||
27 | #include <string.h> | ||
28 | |||
29 | #include "common.h" | ||
30 | |||
31 | static void | ||
32 | usage(void) | ||
33 | { | ||
34 | extern const char * __progname; | ||
35 | |||
36 | fprintf(stderr, "usage: %s [-46e] <host...>\n", __progname); | ||
37 | exit(1); | ||
38 | } | ||
39 | |||
40 | int | ||
41 | main(int argc, char *argv[]) | ||
42 | { | ||
43 | int i, ch, aflag, family = AF_INET; | ||
44 | struct hostent *h; | ||
45 | char *host; | ||
46 | char addr[16]; | ||
47 | int addrlen; | ||
48 | |||
49 | aflag = 0; | ||
50 | while((ch = getopt(argc, argv, "46R:ae")) != -1) { | ||
51 | switch(ch) { | ||
52 | case '4': | ||
53 | family = AF_INET; | ||
54 | break; | ||
55 | case '6': | ||
56 | family = AF_INET6; | ||
57 | break; | ||
58 | case 'R': | ||
59 | parseresopt(optarg); | ||
60 | break; | ||
61 | case 'a': | ||
62 | aflag = 1; | ||
63 | break; | ||
64 | case 'e': | ||
65 | long_err += 1; | ||
66 | break; | ||
67 | default: | ||
68 | usage(); | ||
69 | /* NOTREACHED */ | ||
70 | } | ||
71 | } | ||
72 | argc -= optind; | ||
73 | argv += optind; | ||
74 | |||
75 | for(i = 0; i < argc; i++) { | ||
76 | |||
77 | if (i) | ||
78 | printf("\n"); | ||
79 | printf("===> \"%s\"\n", argv[i]); | ||
80 | host = gethostarg(argv[i]); | ||
81 | |||
82 | if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1) | ||
83 | errx(1, "bad address"); | ||
84 | |||
85 | errno = 0; | ||
86 | h_errno = 0; | ||
87 | gai_errno = 0; | ||
88 | rrset_errno = 0; | ||
89 | |||
90 | if (aflag == 0) | ||
91 | h = gethostbyname2(host, family); | ||
92 | else | ||
93 | h = gethostbyaddr(addr, addrlen, family); | ||
94 | if (h) | ||
95 | print_hostent(h); | ||
96 | print_errors(); | ||
97 | } | ||
98 | |||
99 | return (0); | ||
100 | } | ||
101 | |||
102 | int | ||
103 | addr_from_str(char *addr, int *family, int *len, const char *src) | ||
104 | { | ||
105 | if (inet_pton(AF_INET6, src, addr) == 1) { | ||
106 | *family = AF_INET6; | ||
107 | *len = 16; | ||
108 | return (0); | ||
109 | } | ||
110 | if (inet_pton(AF_INET, src, addr) == 1) { | ||
111 | *family = AF_INET; | ||
112 | *len = 4; | ||
113 | return (0); | ||
114 | } | ||
115 | return (-1); | ||
116 | } | ||