summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/getaddrinfo
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/getaddrinfo')
-rw-r--r--src/regress/lib/libc/getaddrinfo/Makefile19
-rw-r--r--src/regress/lib/libc/getaddrinfo/answer104
-rw-r--r--src/regress/lib/libc/getaddrinfo/gaitest.c188
-rw-r--r--src/regress/lib/libc/getaddrinfo/testsuite.sh89
4 files changed, 400 insertions, 0 deletions
diff --git a/src/regress/lib/libc/getaddrinfo/Makefile b/src/regress/lib/libc/getaddrinfo/Makefile
new file mode 100644
index 0000000000..4d4978a6a2
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/Makefile
@@ -0,0 +1,19 @@
1# $OpenBSD: Makefile,v 1.3 2002/09/02 20:01:43 avsm Exp $
2
3PROG= gaitest
4SRCS= gaitest.c
5NOMAN= # defined
6CLEANFILES+= out
7
8REGRESS_TARGETS=do-test
9
10do-test: ${PROG}
11 sh ${.CURDIR}/testsuite.sh >out 2>&1
12 @if diff -u out ${.CURDIR}/answer; then \
13 echo SUCCESS; \
14 else \
15 echo FAIL; \
16 exit 1; \
17 fi
18
19.include <bsd.regress.mk>
diff --git a/src/regress/lib/libc/getaddrinfo/answer b/src/regress/lib/libc/getaddrinfo/answer
new file mode 100644
index 0000000000..fa4985958f
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/answer
@@ -0,0 +1,104 @@
1== basic ones
2arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http
3ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80
4arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http
5ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80
6arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http
7ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80
8ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80
9arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp
10ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69
11arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp
12ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69
13arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp
14ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69
15ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69
16arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo
17ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7
18ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7
19arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo
20ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7
21ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7
22arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo
23ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7
24ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7
25ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7
26ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7
27
28== specific address family
29arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http
30ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80
31arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http
32ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80
33
34== empty hostname
35arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http
36ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80
37ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80
38arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo
39ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 7
40ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 7
41ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 7
42ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 7
43arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp
44ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 69
45ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69
46arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80
47service not supported for ai_socktype
48arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http
49ai1: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 80
50ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 80
51arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo
52ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 7
53ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv 7
54ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 7
55ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv 7
56arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp
57ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv 69
58ai2: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv 69
59arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80
60service not supported for ai_socktype
61arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80
62ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 80
63ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 80
64arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80
65ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 80
66ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 80
67
68== empty servname
69arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty)
70ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0
71ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0
72arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty)
73ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0
74ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0
75arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty)
76ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0
77ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0
78ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0
79ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0
80arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty)
81name or service is not known
82
83== sock_raw
84arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty)
85ai1: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0
86ai2: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0
87arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty)
88ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0
89ai2: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0
90arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80
91service not supported for ai_socktype
92arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www
93service not supported for ai_socktype
94arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty)
95ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0
96
97== unsupported family
98arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty)
99ai_family not supported
100
101== the following items are specified in jinmei scopeaddr format doc.
102arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http
103ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv 80
104
diff --git a/src/regress/lib/libc/getaddrinfo/gaitest.c b/src/regress/lib/libc/getaddrinfo/gaitest.c
new file mode 100644
index 0000000000..059c1aaa1a
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/gaitest.c
@@ -0,0 +1,188 @@
1/* $OpenBSD: gaitest.c,v 1.5 2004/06/21 21:56:19 itojun Exp $ */
2/* $NetBSD: gaitest.c,v 1.3 2002/07/05 15:47:43 itojun Exp $ */
3
4/*
5 * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/types.h>
34#include <sys/socket.h>
35#include <netinet/in.h>
36#include <arpa/inet.h>
37#include <netdb.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <string.h>
41#include <unistd.h>
42
43struct addrinfo ai;
44
45char host[NI_MAXHOST];
46char serv[NI_MAXSERV];
47int vflag = 0;
48
49static void usage(void);
50static void print1(const char *, const struct addrinfo *, char *, char *);
51int main(int, char *[]);
52
53static void
54usage()
55{
56 fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n");
57}
58
59static void
60print1(title, res, h, s)
61 const char *title;
62 const struct addrinfo *res;
63 char *h;
64 char *s;
65{
66 char *start, *end;
67 int error;
68 const int niflag = NI_NUMERICHOST | NI_NUMERICSERV;
69
70 if (res->ai_addr) {
71 error = getnameinfo(res->ai_addr, res->ai_addr->sa_len,
72 host, sizeof(host), serv, sizeof(serv),
73 niflag);
74 h = host;
75 s = serv;
76 } else
77 error = 0;
78
79 if (vflag) {
80 start = "\t";
81 end = "\n";
82 } else {
83 start = " ";
84 end = "";
85 }
86 printf("%s%s", title, end);
87 printf("%sflags 0x%x%s", start, res->ai_flags, end);
88 printf("%sfamily %d%s", start, res->ai_family, end);
89 printf("%ssocktype %d%s", start, res->ai_socktype, end);
90 printf("%sprotocol %d%s", start, res->ai_protocol, end);
91 printf("%saddrlen %d%s", start, res->ai_addrlen, end);
92 if (error)
93 printf("%serror %d%s", start, error, end);
94 else {
95 printf("%shost %s%s", start, h, end);
96 printf("%sserv %s%s", start, s, end);
97 }
98#if 0
99 if (res->ai_canonname)
100 printf("%scname \"%s\"%s", start, res->ai_canonname, end);
101#endif
102 if (!vflag)
103 printf("\n");
104
105}
106
107int
108main(argc, argv)
109 int argc;
110 char *argv[];
111{
112 struct addrinfo *res;
113 int error, i;
114 char *p, *q;
115 extern int optind;
116 extern char *optarg;
117 int c;
118 char nbuf[10];
119
120 memset(&ai, 0, sizeof(ai));
121 ai.ai_family = PF_UNSPEC;
122 ai.ai_flags |= AI_CANONNAME;
123 while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) {
124 switch (c) {
125 case 'D':
126 ai.ai_socktype = SOCK_DGRAM;
127 break;
128 case 'f':
129 ai.ai_family = atoi(optarg);
130 break;
131 case 'p':
132 ai.ai_protocol = atoi(optarg);
133 break;
134 case 'P':
135 ai.ai_flags |= AI_PASSIVE;
136 break;
137 case 'R':
138 ai.ai_socktype = SOCK_RAW;
139 break;
140 case 's':
141 ai.ai_socktype = atoi(optarg);
142 break;
143 case 'S':
144 ai.ai_socktype = SOCK_STREAM;
145 break;
146 case 'v':
147 vflag++;
148 break;
149 case '4':
150 ai.ai_family = PF_INET;
151 break;
152 case '6':
153 ai.ai_family = PF_INET6;
154 break;
155 default:
156 usage();
157 exit(1);
158 }
159 }
160 argc -= optind;
161 argv += optind;
162
163 if (argc != 2){
164 usage();
165 exit(1);
166 }
167
168 p = *argv[0] ? argv[0] : NULL;
169 q = *argv[1] ? argv[1] : NULL;
170
171 print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)");
172
173 error = getaddrinfo(p, q, &ai, &res);
174 if (error) {
175 printf("%s\n", gai_strerror(error));
176 exit(1);
177 }
178
179 i = 1;
180 do {
181 snprintf(nbuf, sizeof(nbuf), "ai%d:", i);
182 print1(nbuf, res, NULL, NULL);
183
184 i++;
185 } while ((res = res->ai_next) != NULL);
186
187 exit(0);
188}
diff --git a/src/regress/lib/libc/getaddrinfo/testsuite.sh b/src/regress/lib/libc/getaddrinfo/testsuite.sh
new file mode 100644
index 0000000000..1e4e524054
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/testsuite.sh
@@ -0,0 +1,89 @@
1# $OpenBSD: testsuite.sh,v 1.1 2002/07/05 15:54:30 itojun Exp $
2# $NetBSD: testsuite.sh,v 1.3 2002/07/05 15:49:11 itojun Exp $
3
4#
5# Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project.
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12# notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14# notice, this list of conditions and the following disclaimer in the
15# documentation and/or other materials provided with the distribution.
16# 3. Neither the name of the project nor the names of its contributors
17# may be used to endorse or promote products derived from this software
18# without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30# SUCH DAMAGE.
31#
32
33TEST=./gaitest
34#TEST='./test -v'
35#IF=`ifconfig -a | grep -v '^ ' | sed -e 's/:.*//' | head -1 | awk '{print $1}'`
36
37echo '== basic ones'
38$TEST ::1 http
39$TEST 127.0.0.1 http
40$TEST localhost http
41$TEST ::1 tftp
42$TEST 127.0.0.1 tftp
43$TEST localhost tftp
44$TEST ::1 echo
45$TEST 127.0.0.1 echo
46$TEST localhost echo
47echo
48
49echo '== specific address family'
50$TEST -4 localhost http
51$TEST -6 localhost http
52echo
53
54echo '== empty hostname'
55$TEST '' http
56$TEST '' echo
57$TEST '' tftp
58$TEST '' 80
59$TEST -P '' http
60$TEST -P '' echo
61$TEST -P '' tftp
62$TEST -P '' 80
63$TEST -S '' 80
64$TEST -D '' 80
65echo
66
67echo '== empty servname'
68$TEST ::1 ''
69$TEST 127.0.0.1 ''
70$TEST localhost ''
71$TEST '' ''
72echo
73
74echo '== sock_raw'
75$TEST -R -p 0 localhost ''
76$TEST -R -p 59 localhost ''
77$TEST -R -p 59 localhost 80
78$TEST -R -p 59 localhost www
79$TEST -R -p 59 ::1 ''
80echo
81
82echo '== unsupported family'
83$TEST -f 99 localhost ''
84echo
85
86echo '== the following items are specified in jinmei scopeaddr format doc.'
87$TEST fe80::1%lo0 http
88#$TEST fe80::1%$IF http
89echo