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.c186
-rw-r--r--src/regress/lib/libc/getaddrinfo/testsuite.sh89
4 files changed, 398 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..f626f8f7d8
--- /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 www
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 www
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 www cname "localhost"
8ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www cname "localhost"
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 cname "localhost"
15ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 69 cname "localhost"
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 echo
18ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo
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 echo
21ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo
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 echo cname "localhost"
24ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo cname "localhost"
25ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo cname "localhost"
26ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo cname "localhost"
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 www cname "localhost"
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 www cname "localhost"
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 www
37ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www
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 echo
40ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo
41ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo
42ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo
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 www
50ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv www
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 echo
53ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv echo
54ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv echo
55ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv echo
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 www
63ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv www
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 www
66ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv www
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 cname "localhost"
77ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
78ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 cname "localhost"
79ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
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 cname "localhost"
86ai2: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
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 cname "localhost"
89ai2: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 cname "localhost"
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 www
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..a54681b157
--- /dev/null
+++ b/src/regress/lib/libc/getaddrinfo/gaitest.c
@@ -0,0 +1,186 @@
1/* $OpenBSD: gaitest.c,v 1.3 2003/09/02 23:52:16 david 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;
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 (res->ai_canonname)
99 printf("%scname \"%s\"%s", start, res->ai_canonname, end);
100 if (!vflag)
101 printf("\n");
102
103}
104
105int
106main(argc, argv)
107 int argc;
108 char *argv[];
109{
110 struct addrinfo *res;
111 int error, i;
112 char *p, *q;
113 extern int optind;
114 extern char *optarg;
115 int c;
116 char nbuf[10];
117
118 memset(&ai, 0, sizeof(ai));
119 ai.ai_family = PF_UNSPEC;
120 ai.ai_flags |= AI_CANONNAME;
121 while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) {
122 switch (c) {
123 case 'D':
124 ai.ai_socktype = SOCK_DGRAM;
125 break;
126 case 'f':
127 ai.ai_family = atoi(optarg);
128 break;
129 case 'p':
130 ai.ai_protocol = atoi(optarg);
131 break;
132 case 'P':
133 ai.ai_flags |= AI_PASSIVE;
134 break;
135 case 'R':
136 ai.ai_socktype = SOCK_RAW;
137 break;
138 case 's':
139 ai.ai_socktype = atoi(optarg);
140 break;
141 case 'S':
142 ai.ai_socktype = SOCK_STREAM;
143 break;
144 case 'v':
145 vflag++;
146 break;
147 case '4':
148 ai.ai_family = PF_INET;
149 break;
150 case '6':
151 ai.ai_family = PF_INET6;
152 break;
153 default:
154 usage();
155 exit(1);
156 }
157 }
158 argc -= optind;
159 argv += optind;
160
161 if (argc != 2){
162 usage();
163 exit(1);
164 }
165
166 p = *argv[0] ? argv[0] : NULL;
167 q = *argv[1] ? argv[1] : NULL;
168
169 print1("arg:", &ai, p ? p : "(empty)", q ? q : "(empty)");
170
171 error = getaddrinfo(p, q, &ai, &res);
172 if (error) {
173 printf("%s\n", gai_strerror(error));
174 exit(1);
175 }
176
177 i = 1;
178 do {
179 snprintf(nbuf, sizeof(nbuf), "ai%d:", i);
180 print1(nbuf, res, NULL, NULL);
181
182 i++;
183 } while ((res = res->ai_next) != NULL);
184
185 exit(0);
186}
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