summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/asr
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/regress/lib/libc/asr
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/regress/lib/libc/asr')
-rw-r--r--src/regress/lib/libc/asr/Makefile52
-rw-r--r--src/regress/lib/libc/asr/bin/Makefile10
-rw-r--r--src/regress/lib/libc/asr/bin/Makefile.inc8
-rw-r--r--src/regress/lib/libc/asr/bin/common.c693
-rw-r--r--src/regress/lib/libc/asr/bin/common.h138
-rw-r--r--src/regress/lib/libc/asr/bin/getaddrinfo.c138
-rw-r--r--src/regress/lib/libc/asr/bin/getaddrinfo/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/gethostnamadr.c116
-rw-r--r--src/regress/lib/libc/asr/bin/gethostnamadr/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getnameinfo.c115
-rw-r--r--src/regress/lib/libc/asr/bin/getnameinfo/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getnetnamadr.c88
-rw-r--r--src/regress/lib/libc/asr/bin/getnetnamadr/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getrrsetbyname.c91
-rw-r--r--src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/res_mkquery.c322
-rw-r--r--src/regress/lib/libc/asr/bin/res_mkquery/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/res_query.c358
-rw-r--r--src/regress/lib/libc/asr/bin/res_query/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/threads.c140
-rw-r--r--src/regress/lib/libc/asr/bin/threads/Makefile10
-rw-r--r--src/regress/lib/libc/asr/regress.sh111
-rw-r--r--src/regress/lib/libc/asr/regress.subr122
23 files changed, 0 insertions, 2568 deletions
diff --git a/src/regress/lib/libc/asr/Makefile b/src/regress/lib/libc/asr/Makefile
deleted file mode 100644
index 12e59536e0..0000000000
--- a/src/regress/lib/libc/asr/Makefile
+++ /dev/null
@@ -1,52 +0,0 @@
1# $OpenBSD: Makefile,v 1.4 2017/03/10 17:23:48 eric Exp $
2
3#
4# Notes on building and running the regression tests
5#
6# The regress suite builds two sets of static executables: the former linked
7# against the system libc, and the latter against the libc found in /usr/obj
8# The idea is to compare the output of all programs with internal changes in
9# the libc (more specifically the resolver). They will be run in a chrooted
10# environment to test various /etc configurations without touching the local
11# machine config files.
12#
13# First, build a libc that needs testing, then:
14#
15# $ make
16# $ doas make install
17# $ doas make regress
18#
19# Tests output goes into a $REGRESSDIR/tmp.XXXXXXXXXX directory, and a digest
20# is displayed at the end.
21#
22
23REGRESSDIR?= /tmp/regress-asr
24REGRESS?= regress.sh
25
26A?= .a
27B?= .b
28
29DIRA?= /usr/lib
30DIRB?= /usr/obj/lib/libc
31
32
33all: build
34
35build:
36 cd bin && EXT=${A} LDFLAGS=-L${DIRA} make
37 cd bin && EXT=${B} LDFLAGS=-L${DIRB} make
38
39clean:
40 cd bin && EXT=${A} make clean
41 cd bin && EXT=${B} make clean
42
43install:
44 mkdir -p ${REGRESSDIR}/bin
45 cd bin && BINDIR=${REGRESSDIR}/bin EXT=${A} make install
46 cd bin && BINDIR=${REGRESSDIR}/bin EXT=${B} make install
47
48uninstall:
49 rm -rf ${REGRESSDIR}
50
51regress:
52 RUNDIR=${REGRESSDIR} A=${A} B=${B} sh ${.CURDIR}/${REGRESS}
diff --git a/src/regress/lib/libc/asr/bin/Makefile b/src/regress/lib/libc/asr/bin/Makefile
deleted file mode 100644
index 1f986a8e69..0000000000
--- a/src/regress/lib/libc/asr/bin/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1SUBDIR= res_mkquery
2SUBDIR+= res_query
3SUBDIR+= gethostnamadr
4SUBDIR+= getnetnamadr
5SUBDIR+= getrrsetbyname
6SUBDIR+= getnameinfo
7SUBDIR+= getaddrinfo
8SUBDIR+= threads
9
10.include <bsd.subdir.mk>
diff --git a/src/regress/lib/libc/asr/bin/Makefile.inc b/src/regress/lib/libc/asr/bin/Makefile.inc
deleted file mode 100644
index 80b4805136..0000000000
--- a/src/regress/lib/libc/asr/bin/Makefile.inc
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile.inc,v 1.2 2012/09/05 21:21:13 eric Exp $
2
3NOMAN= noman
4
5SRCS+= common.c
6CFLAGS+= -Wall -Wstrict-prototypes -Werror -Wundef -g
7LDSTATIC= ${STATIC}
8PROG:= ${PROG}${EXT}
diff --git a/src/regress/lib/libc/asr/bin/common.c b/src/regress/lib/libc/asr/bin/common.c
deleted file mode 100644
index 08a7bccbb7..0000000000
--- a/src/regress/lib/libc/asr/bin/common.c
+++ /dev/null
@@ -1,693 +0,0 @@
1/* $OpenBSD: common.c,v 1.4 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#include <arpa/nameser.h>
22
23#include <err.h>
24#include <errno.h>
25#include <inttypes.h>
26#include <netdb.h>
27#include <resolv.h>
28#include <stdio.h>
29#include <string.h>
30
31#include "common.h"
32
33int long_err;
34int gai_errno;
35int rrset_errno;
36
37
38char *
39gethostarg(char *n)
40{
41 if (n == NULL)
42 return (n);
43 if (!strcmp(n, "NULL"))
44 return (NULL);
45 if (!strcmp(n, "EMPTY"))
46 return ("");
47 return (n);
48}
49
50const char *rrsetstrerror(int);
51char * print_addr(const struct sockaddr *, char *, size_t);
52
53struct kv { int code; const char *name; };
54
55struct kv kv_family[] = {
56 { AF_UNIX, "unix" },
57 { AF_INET, "inet" },
58 { AF_INET6, "inet6" },
59 { 0, NULL, }
60};
61struct kv kv_socktype[] = {
62 { SOCK_STREAM, "stream" },
63 { SOCK_DGRAM, "dgram" },
64 { SOCK_RAW, "raw" },
65 { SOCK_SEQPACKET, "seqpacket" },
66 { 0, NULL, }
67};
68struct kv kv_protocol[] = {
69 { IPPROTO_UDP, "udp" },
70 { IPPROTO_TCP, "tcp" },
71 { IPPROTO_ICMP, "icmp" },
72 { IPPROTO_ICMPV6, "icmpv6" },
73 { 0, NULL, }
74};
75
76static const char *
77kv_lookup_name(struct kv *kv, int code, char *buf, size_t sz)
78{
79 while (kv->name) {
80 if (kv->code == code)
81 return (kv->name);
82 kv++;
83 }
84 snprintf(buf, sz, "%i", code);
85 return (buf);
86}
87
88struct keyval {
89 const char *key;
90 int value;
91};
92
93static struct keyval kv_class[] = {
94 { "IN", C_IN },
95 { "CHAOS", C_CHAOS },
96 { "HS", C_HS },
97 { "ANY", C_ANY },
98 { NULL, 0 },
99};
100
101static struct keyval kv_type[] = {
102 { "A", T_A },
103 { "NS", T_NS },
104 { "MD", T_MD },
105 { "MF", T_MF },
106 { "CNAME", T_CNAME },
107 { "SOA", T_SOA },
108 { "MB", T_MB },
109 { "MG", T_MG },
110 { "MR", T_MR },
111 { "NULL", T_NULL },
112 { "WKS", T_WKS },
113 { "PTR", T_PTR },
114 { "HINFO", T_HINFO },
115 { "MINFO", T_MINFO },
116 { "MX", T_MX },
117 { "TXT", T_TXT },
118
119 { "AAAA", T_AAAA },
120
121 { "AXFR", T_AXFR },
122 { "MAILB", T_MAILB },
123 { "MAILA", T_MAILA },
124 { "ANY", T_ANY },
125 { NULL, 0 },
126};
127
128static struct keyval kv_rcode[] = {
129 { "NOERROR", NOERROR },
130 { "FORMERR", FORMERR },
131 { "SERVFAIL", SERVFAIL },
132 { "NXDOMAIN", NXDOMAIN },
133 { "NOTIMP", NOTIMP },
134 { "REFUSED", REFUSED },
135 { NULL, 0 },
136};
137
138static struct keyval kv_resopt[] = {
139 { "DEBUG", RES_DEBUG },
140 { "AAONLY", RES_AAONLY },
141 { "USEVC", RES_USEVC },
142 { "PRIMARY", RES_PRIMARY },
143 { "IGNTC", RES_IGNTC },
144 { "RECURSE", RES_RECURSE },
145 { "DEFNAMES", RES_DEFNAMES },
146 { "STAYOPEN", RES_STAYOPEN },
147 { "DNSRCH", RES_DNSRCH },
148 { "INSECURE1", RES_INSECURE1 },
149 { "INSECURE2", RES_INSECURE2 },
150 { "NOALIASES", RES_NOALIASES },
151 { "USE_INET6", RES_USE_INET6 },
152 { "USE_EDNS0", RES_USE_EDNS0 },
153 { "USE_DNSSEC", RES_USE_DNSSEC },
154 { NULL, 0 },
155};
156
157const char *
158rcodetostr(uint16_t v)
159{
160 static char buf[16];
161 size_t i;
162
163 for(i = 0; kv_rcode[i].key; i++)
164 if (kv_rcode[i].value == v)
165 return (kv_rcode[i].key);
166
167 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
168
169 return (buf);
170}
171
172const char *
173typetostr(uint16_t v)
174{
175 static char buf[16];
176 size_t i;
177
178 for(i = 0; kv_type[i].key; i++)
179 if (kv_type[i].value == v)
180 return (kv_type[i].key);
181
182 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
183
184 return (buf);
185}
186
187const char *
188classtostr(uint16_t v)
189{
190 static char buf[16];
191 size_t i;
192
193 for(i = 0; kv_class[i].key; i++)
194 if (kv_class[i].value == v)
195 return (kv_class[i].key);
196
197 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
198
199 return (buf);
200}
201
202uint16_t
203strtotype(const char *name)
204{
205 size_t i;
206
207 for(i = 0; kv_type[i].key; i++)
208 if (!strcasecmp(kv_type[i].key, name))
209 return (kv_type[i].value);
210
211 return (0);
212}
213
214uint16_t
215strtoclass(const char *name)
216{
217 size_t i;
218
219 for(i = 0; kv_class[i].key; i++)
220 if (!strcasecmp(kv_class[i].key, name))
221 return (kv_class[i].value);
222
223 return (0);
224}
225
226int
227strtoresopt(const char *name)
228{
229 size_t i;
230
231 for(i = 0; kv_resopt[i].key; i++)
232 if (!strcasecmp(kv_resopt[i].key, name))
233 return (kv_resopt[i].value);
234
235 return (0);
236}
237
238void
239parseresopt(const char *name)
240{
241 static int init = 0;
242 int flag, neg = 0;
243
244 if (init == 0) {
245 res_init();
246 init = 1;
247 }
248
249 if (name[0] == '-') {
250 neg = 1;
251 name++;
252 }
253 else if (name[0] == '+')
254 name++;
255
256 flag = strtoresopt(name);
257 if (flag == 0)
258 errx(1, "unknown reslover option %s", name);
259
260 if (neg)
261 _res.options &= ~flag;
262 else
263 _res.options |= flag;
264}
265
266void
267print_hostent(struct hostent *e)
268{
269 char buf[256], **c;
270
271 printf("name = \"%s\"\n", e->h_name);
272 printf("aliases =");
273 for(c = e->h_aliases; *c; c++)
274 printf(" \"%s\"", *c);
275 printf("\n");
276 printf("addrtype = %i\n", e->h_addrtype);
277 printf("addrlength = %i\n", e->h_length);
278 printf("addr_list =");
279 for(c = e->h_addr_list; *c; c++) {
280 printf(" %s", inet_ntop(e->h_addrtype, *c, buf, sizeof buf));
281 }
282 printf("\n");
283}
284
285void
286print_netent(struct netent *e)
287{
288 char buf[256], **c;
289 uint32_t addr;
290
291 /* network number are given in host order */
292 addr = htonl(e->n_net);
293
294 printf("name = \"%s\"\n", e->n_name);
295 printf("aliases =");
296 for (c = e->n_aliases; *c; c++)
297 printf(" \"%s\"", *c);
298 printf("\n");
299 printf("addrtype = %i\n", e->n_addrtype);
300 printf("net = %s\n", inet_ntop(e->n_addrtype, &addr, buf, sizeof buf));
301}
302
303void
304print_addrinfo(struct addrinfo *ai)
305{
306 char buf[256], bf[64], bt[64], bp[64];
307
308 printf("family=%s socktype=%s protocol=%s addr=%s canonname=%s\n",
309 kv_lookup_name(kv_family, ai->ai_family, bf, sizeof bf),
310 kv_lookup_name(kv_socktype, ai->ai_socktype, bt, sizeof bt),
311 kv_lookup_name(kv_protocol, ai->ai_protocol, bp, sizeof bp),
312 print_addr(ai->ai_addr, buf, sizeof buf),
313 ai->ai_canonname);
314}
315
316const char *
317rrsetstrerror(int e)
318{
319 switch (e) {
320 case 0:
321 return "OK";
322 case ERRSET_NONAME:
323 return "ERRSET_NONAME";
324 case ERRSET_NODATA:
325 return "ERRSET_NODATA";
326 case ERRSET_NOMEMORY:
327 return "ERRSET_NOMEMORY";
328 case ERRSET_INVAL:
329 return "ERRSET_INVAL";
330 case ERRSET_FAIL:
331 return "ERRSET_FAIL";
332 default:
333 return "???";
334 }
335}
336
337void
338print_rrsetinfo(struct rrsetinfo * rrset)
339{
340 printf("rri_flags=%u\n", rrset->rri_flags);
341 printf("rri_rdclass=%u\n", rrset->rri_rdclass);
342 printf("rri_rdtype=%u\n", rrset->rri_rdtype);
343 printf("rri_ttl=%u\n", rrset->rri_ttl);
344 printf("rri_nrdatas=%u\n", rrset->rri_nrdatas);
345 printf("rri_nsigs=%u\n", rrset->rri_nsigs);
346 printf("rri_name=\"%s\"\n", rrset->rri_name);
347}
348
349void
350print_errors(void)
351{
352 switch (long_err) {
353 case 0:
354 return;
355 case 1:
356 printf(" => errno %i, h_errno %i", errno, h_errno);
357 printf(", rrset_errno %i", rrset_errno);
358 printf(", gai_errno %i", gai_errno);
359 printf ("\n");
360 return;
361 default:
362 printf(" => errno %i: %s\n => h_errno %i: %s\n => rrset_errno %i: %s\n",
363 errno, errno ? strerror(errno) : "ok",
364 h_errno, h_errno ? hstrerror(h_errno) : "ok",
365 rrset_errno, rrset_errno ? rrsetstrerror(rrset_errno) : "ok");
366 printf(" => gai_errno %i: %s\n",
367 gai_errno, gai_errno ? gai_strerror(gai_errno) : "ok");
368 }
369}
370
371
372static char *
373print_host(const struct sockaddr *sa, char *buf, size_t len)
374{
375 switch (sa->sa_family) {
376 case AF_INET:
377 inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr,
378 buf, len);
379 break;
380 case AF_INET6:
381 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr,
382 buf, len);
383 break;
384 default:
385 buf[0] = '\0';
386 }
387 return (buf);
388}
389
390
391char *
392print_addr(const struct sockaddr *sa, char *buf, size_t len)
393{
394 char h[256];
395
396 print_host(sa, h, sizeof h);
397
398 switch (sa->sa_family) {
399 case AF_INET:
400 snprintf(buf, len, "%s:%i", h,
401 ntohs(((struct sockaddr_in*)(sa))->sin_port));
402 break;
403 case AF_INET6:
404 snprintf(buf, len, "[%s]:%i", h,
405 ntohs(((struct sockaddr_in6*)(sa))->sin6_port));
406 break;
407 default:
408 snprintf(buf, len, "?");
409 break;
410 }
411
412 return (buf);
413}
414
415void
416packed_init(struct packed *pack, char *data, size_t len)
417{
418 pack->data = data;
419 pack->len = len;
420 pack->offset = 0;
421 pack->err = NULL;
422}
423
424
425static ssize_t
426dname_expand(const unsigned char *data, size_t len, size_t offset,
427 size_t *newoffset, char *dst, size_t max)
428{
429 size_t n, count, end, ptr, start;
430 ssize_t res;
431
432 if (offset >= len)
433 return (-1);
434
435 res = 0;
436 end = start = offset;
437
438 for(; (n = data[offset]); ) {
439 if ((n & 0xc0) == 0xc0) {
440 if (offset + 2 > len)
441 return (-1);
442 ptr = 256 * (n & ~0xc0) + data[offset + 1];
443 if (ptr >= start)
444 return (-1);
445 if (end < offset + 2)
446 end = offset + 2;
447 offset = ptr;
448 continue;
449 }
450 if (offset + n + 1 > len)
451 return (-1);
452
453
454 /* copy n + at offset+1 */
455 if (dst != NULL && max != 0) {
456 count = (max < n + 1) ? (max) : (n + 1);
457 memmove(dst, data + offset, count);
458 dst += count;
459 max -= count;
460 }
461 res += n + 1;
462 offset += n + 1;
463 if (end < offset)
464 end = offset;
465 }
466 if (end < offset + 1)
467 end = offset + 1;
468
469 if (dst != NULL && max != 0)
470 dst[0] = 0;
471 if (newoffset)
472 *newoffset = end;
473 return (res + 1);
474}
475
476static int
477unpack_data(struct packed *p, void *data, size_t len)
478{
479 if (p->err)
480 return (-1);
481
482 if (p->len - p->offset < len) {
483 p->err = "too short";
484 return (-1);
485 }
486
487 memmove(data, p->data + p->offset, len);
488 p->offset += len;
489
490 return (0);
491}
492
493static int
494unpack_u16(struct packed *p, uint16_t *u16)
495{
496 if (unpack_data(p, u16, 2) == -1)
497 return (-1);
498
499 *u16 = ntohs(*u16);
500
501 return (0);
502}
503
504static int
505unpack_u32(struct packed *p, uint32_t *u32)
506{
507 if (unpack_data(p, u32, 4) == -1)
508 return (-1);
509
510 *u32 = ntohl(*u32);
511
512 return (0);
513}
514
515static int
516unpack_inaddr(struct packed *p, struct in_addr *a)
517{
518 return (unpack_data(p, a, 4));
519}
520
521static int
522unpack_in6addr(struct packed *p, struct in6_addr *a6)
523{
524 return (unpack_data(p, a6, 16));
525}
526
527static int
528unpack_dname(struct packed *p, char *dst, size_t max)
529{
530 ssize_t e;
531
532 if (p->err)
533 return (-1);
534
535 e = dname_expand(p->data, p->len, p->offset, &p->offset, dst, max);
536 if (e == -1) {
537 p->err = "bad domain name";
538 return (-1);
539 }
540 if (e < 0 || e > MAXDNAME) {
541 p->err = "domain name too long";
542 return (-1);
543 }
544
545 return (0);
546}
547
548int
549unpack_header(struct packed *p, struct header *h)
550{
551 if (unpack_data(p, h, HFIXEDSZ) == -1)
552 return (-1);
553
554 h->flags = ntohs(h->flags);
555 h->qdcount = ntohs(h->qdcount);
556 h->ancount = ntohs(h->ancount);
557 h->nscount = ntohs(h->nscount);
558 h->arcount = ntohs(h->arcount);
559
560 return (0);
561}
562
563int
564unpack_query(struct packed *p, struct query *q)
565{
566 unpack_dname(p, q->q_dname, sizeof(q->q_dname));
567 unpack_u16(p, &q->q_type);
568 unpack_u16(p, &q->q_class);
569
570 return (p->err) ? (-1) : (0);
571}
572
573int
574unpack_rr(struct packed *p, struct rr *rr)
575{
576 uint16_t rdlen;
577 size_t save_offset;
578
579 unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname));
580 unpack_u16(p, &rr->rr_type);
581 unpack_u16(p, &rr->rr_class);
582 unpack_u32(p, &rr->rr_ttl);
583 unpack_u16(p, &rdlen);
584
585 if (p->err)
586 return (-1);
587
588 if (p->len - p->offset < rdlen) {
589 p->err = "too short";
590 return (-1);
591 }
592
593 save_offset = p->offset;
594
595 switch(rr->rr_type) {
596
597 case T_CNAME:
598 unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname));
599 break;
600
601 case T_MX:
602 unpack_u16(p, &rr->rr.mx.preference);
603 unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange));
604 break;
605
606 case T_NS:
607 unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname));
608 break;
609
610 case T_PTR:
611 unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname));
612 break;
613
614 case T_SOA:
615 unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname));
616 unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname));
617 unpack_u32(p, &rr->rr.soa.serial);
618 unpack_u32(p, &rr->rr.soa.refresh);
619 unpack_u32(p, &rr->rr.soa.retry);
620 unpack_u32(p, &rr->rr.soa.expire);
621 unpack_u32(p, &rr->rr.soa.minimum);
622 break;
623
624 case T_A:
625 if (rr->rr_class != C_IN)
626 goto other;
627 unpack_inaddr(p, &rr->rr.in_a.addr);
628 break;
629
630 case T_AAAA:
631 if (rr->rr_class != C_IN)
632 goto other;
633 unpack_in6addr(p, &rr->rr.in_aaaa.addr6);
634 break;
635 default:
636 other:
637 rr->rr.other.rdata = p->data + p->offset;
638 rr->rr.other.rdlen = rdlen;
639 p->offset += rdlen;
640 }
641
642 if (p->err)
643 return (-1);
644
645 /* make sure that the advertised rdlen is really ok */
646 if (p->offset - save_offset != rdlen)
647 p->err = "bad dlen";
648
649 return (p->err) ? (-1) : (0);
650}
651
652int
653sockaddr_from_str(struct sockaddr *sa, int family, const char *str)
654{
655 struct in_addr ina;
656 struct in6_addr in6a;
657 struct sockaddr_in *sin;
658 struct sockaddr_in6 *sin6;
659
660 switch (family) {
661 case PF_UNSPEC:
662 if (sockaddr_from_str(sa, PF_INET, str) == 0)
663 return (0);
664 return sockaddr_from_str(sa, PF_INET6, str);
665
666 case PF_INET:
667 if (inet_pton(PF_INET, str, &ina) != 1)
668 return (-1);
669
670 sin = (struct sockaddr_in *)sa;
671 memset(sin, 0, sizeof *sin);
672 sin->sin_len = sizeof(struct sockaddr_in);
673 sin->sin_family = PF_INET;
674 sin->sin_addr.s_addr = ina.s_addr;
675 return (0);
676
677 case PF_INET6:
678 if (inet_pton(PF_INET6, str, &in6a) != 1)
679 return (-1);
680
681 sin6 = (struct sockaddr_in6 *)sa;
682 memset(sin6, 0, sizeof *sin6);
683 sin6->sin6_len = sizeof(struct sockaddr_in6);
684 sin6->sin6_family = PF_INET6;
685 sin6->sin6_addr = in6a;
686 return (0);
687
688 default:
689 break;
690 }
691
692 return (-1);
693}
diff --git a/src/regress/lib/libc/asr/bin/common.h b/src/regress/lib/libc/asr/bin/common.h
deleted file mode 100644
index 6a6b90a34f..0000000000
--- a/src/regress/lib/libc/asr/bin/common.h
+++ /dev/null
@@ -1,138 +0,0 @@
1/* $OpenBSD: common.h,v 1.2 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
20#include <arpa/nameser.h>
21
22#include <netinet/in.h>
23
24#include <netdb.h>
25
26
27#define unpack_rr __unpack_rr
28#define unpack_header __unpack_header
29#define packed_init __packed_init
30#define unpack_query __unpack_query
31#define sockaddr_from_str __sockaddr_from_str
32#define print_addr __print_addr
33
34extern int long_err;
35extern int gai_errno;
36extern int rrset_errno;
37
38const char *classtostr(uint16_t);
39const char *typetostr(uint16_t);
40const char *rcodetostr(uint16_t);
41
42uint16_t strtotype(const char*);
43uint16_t strtoclass(const char*);
44int strtoresopt(const char*);
45void parseresopt(const char*);
46
47void print_rrsetinfo(struct rrsetinfo *);
48void print_addrinfo(struct addrinfo *);
49void print_errors(void);
50void print_hostent(struct hostent *);
51void print_netent(struct netent *);
52
53int sockaddr_from_str(struct sockaddr *, int, const char *);
54int addr_from_str(char *, int *, int *, const char *);
55char* gethostarg(char *);
56
57#define QR_MASK (0x1 << 15)
58#define OPCODE_MASK (0xf << 11)
59#define AA_MASK (0x1 << 10)
60#define TC_MASK (0x1 << 9)
61#define RD_MASK (0x1 << 8)
62#define RA_MASK (0x1 << 7)
63#define Z_MASK (0x7 << 4)
64#define RCODE_MASK (0xf)
65
66#define OPCODE(v) ((v) & OPCODE_MASK)
67#define RCODE(v) ((v) & RCODE_MASK)
68
69
70struct packed {
71 char *data;
72 size_t len;
73 size_t offset;
74 const char *err;
75};
76
77struct header {
78 uint16_t id;
79 uint16_t flags;
80 uint16_t qdcount;
81 uint16_t ancount;
82 uint16_t nscount;
83 uint16_t arcount;
84};
85
86struct query {
87 char q_dname[MAXDNAME];
88 uint16_t q_type;
89 uint16_t q_class;
90};
91
92struct rr {
93 char rr_dname[MAXDNAME];
94 uint16_t rr_type;
95 uint16_t rr_class;
96 uint32_t rr_ttl;
97 union {
98 struct {
99 char cname[MAXDNAME];
100 } cname;
101 struct {
102 uint16_t preference;
103 char exchange[MAXDNAME];
104 } mx;
105 struct {
106 char nsname[MAXDNAME];
107 } ns;
108 struct {
109 char ptrname[MAXDNAME];
110 } ptr;
111 struct {
112 char mname[MAXDNAME];
113 char rname[MAXDNAME];
114 uint32_t serial;
115 uint32_t refresh;
116 uint32_t retry;
117 uint32_t expire;
118 uint32_t minimum;
119 } soa;
120 struct {
121 struct in_addr addr;
122 } in_a;
123 struct {
124 struct in6_addr addr6;
125 } in_aaaa;
126 struct {
127 uint16_t rdlen;
128 const void *rdata;
129 } other;
130 } rr;
131};
132
133void packed_init(struct packed*, char*, size_t);
134int pack_header(struct packed*, const struct header*);
135int pack_query(struct packed*, uint16_t, uint16_t, const char*);
136int unpack_header(struct packed*, struct header*);
137int unpack_query(struct packed*, struct query*);
138int unpack_rr(struct packed*, struct rr*);
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo.c b/src/regress/lib/libc/asr/bin/getaddrinfo.c
deleted file mode 100644
index 6605a00c1b..0000000000
--- a/src/regress/lib/libc/asr/bin/getaddrinfo.c
+++ /dev/null
@@ -1,138 +0,0 @@
1/* $OpenBSD: getaddrinfo.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
20#include <netinet/in.h>
21
22#include <err.h>
23#include <errno.h>
24#include <getopt.h>
25#include <netdb.h>
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29
30#include "common.h"
31
32static void
33usage(void)
34{
35 extern const char * __progname;
36
37 fprintf(stderr, "usage: %s [-CHSPe] [-f family] [-p proto] "
38 "[-s servname]\n [-t socktype] <host...>\n", __progname);
39 exit(1);
40}
41
42int
43main(int argc, char *argv[])
44{
45 struct addrinfo *ai, *res, hints;
46 char *servname = NULL, *host;
47 int i, ch;
48
49 memset(&hints, 0, sizeof hints);
50
51 while((ch = getopt(argc, argv, "CFHPR:Sef:p:s:t:")) != -1) {
52 switch(ch) {
53 case 'C':
54 hints.ai_flags |= AI_CANONNAME;
55 break;
56 case 'F':
57 hints.ai_flags |= AI_FQDN;
58 break;
59 case 'H':
60 hints.ai_flags |= AI_NUMERICHOST;
61 break;
62 case 'P':
63 hints.ai_flags |= AI_PASSIVE;
64 break;
65 case 'R':
66 parseresopt(optarg);
67 break;
68 case 'S':
69 hints.ai_flags |= AI_NUMERICSERV;
70 break;
71 case 'e':
72 long_err += 1;
73 break;
74 case 'f':
75 if (!strcmp(optarg, "inet"))
76 hints.ai_family = AF_INET;
77 else if (!strcmp(optarg, "inet6"))
78 hints.ai_family = AF_INET6;
79 else
80 usage();
81 break;
82 case 'p':
83 if (!strcmp(optarg, "udp"))
84 hints.ai_protocol = IPPROTO_UDP;
85 else if (!strcmp(optarg, "tcp"))
86 hints.ai_protocol = IPPROTO_TCP;
87 else if (!strcmp(optarg, "icmp"))
88 hints.ai_protocol = IPPROTO_ICMP;
89 else if (!strcmp(optarg, "icmpv6"))
90 hints.ai_protocol = IPPROTO_ICMPV6;
91 else
92 usage();
93 break;
94 case 's':
95 servname = optarg;
96 break;
97 case 't':
98 if (!strcmp(optarg, "stream"))
99 hints.ai_socktype = SOCK_STREAM;
100 else if (!strcmp(optarg, "dgram"))
101 hints.ai_socktype = SOCK_DGRAM;
102 else if (!strcmp(optarg, "raw"))
103 hints.ai_socktype = SOCK_RAW;
104 else
105 usage();
106 break;
107 default:
108 usage();
109 /* NOTREACHED */
110 }
111 }
112 argc -= optind;
113 argv += optind;
114
115 for(i = 0; i < argc; i++) {
116
117 if (i)
118 printf("\n");
119 printf("===> \"%s\"\n", argv[i]);
120 host = gethostarg(argv[i]);
121
122 errno = 0;
123 h_errno = 0;
124 gai_errno = 0;
125 rrset_errno = 0;
126
127 gai_errno = getaddrinfo(host, servname, &hints, &ai);
128
129 print_errors();
130 if (gai_errno == 0) {
131 for (res = ai; res; res = res->ai_next)
132 print_addrinfo(res);
133 freeaddrinfo(ai);
134 }
135 }
136
137 return (0);
138}
diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile b/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile
deleted file mode 100644
index ec2f104ec7..0000000000
--- a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= getaddrinfo
6SRCS+= getaddrinfo.c
7
8.include <bsd.prog.mk>
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
31static void
32usage(void)
33{
34 extern const char * __progname;
35
36 fprintf(stderr, "usage: %s [-46e] <host...>\n", __progname);
37 exit(1);
38}
39
40int
41main(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
102int
103addr_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}
diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile b/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile
deleted file mode 100644
index 84906ffbbd..0000000000
--- a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= gethostnamadr
6SRCS+= gethostnamadr.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo.c b/src/regress/lib/libc/asr/bin/getnameinfo.c
deleted file mode 100644
index bd0fbe224f..0000000000
--- a/src/regress/lib/libc/asr/bin/getnameinfo.c
+++ /dev/null
@@ -1,115 +0,0 @@
1/* $OpenBSD: getnameinfo.c,v 1.2 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
18#include <err.h>
19#include <errno.h>
20#include <getopt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24
25#include "common.h"
26
27static void
28usage(void)
29{
30 extern const char * __progname;
31
32 fprintf(stderr, "usage: %s [-DFHNSe] [-p portno] <addr...>\n", __progname);
33 exit(1);
34}
35
36int
37main(int argc, char *argv[])
38{
39 char serv[1024];
40 char host[1024];
41 const char *e;
42 int i, ch, flags = 0, port = 0;
43 struct sockaddr_storage ss;
44 struct sockaddr *sa;
45
46 sa = (struct sockaddr*)&ss;
47
48 while((ch = getopt(argc, argv, "DFHNR:Saep:")) != -1) {
49 switch(ch) {
50 case 'D':
51 flags |= NI_DGRAM;
52 break;
53 case 'F':
54 flags |= NI_NOFQDN;
55 break;
56 case 'H':
57 flags |= NI_NUMERICHOST;
58 break;
59 case 'N':
60 flags |= NI_NAMEREQD;
61 break;
62 case 'R':
63 parseresopt(optarg);
64 break;
65 case 'S':
66 flags |= NI_NUMERICSERV;
67 break;
68 case 'e':
69 long_err += 1;
70 break;
71 case 'p':
72 port = strtonum(optarg, 0, 65535, &e);
73 if (e)
74 usage();
75 break;
76 default:
77 usage();
78 /* NOTREACHED */
79 }
80 }
81 argc -= optind;
82 argv += optind;
83
84 for(i = 0; i < argc; i++) {
85
86 if (i)
87 printf("\n");
88 printf("===> \"%s\"\n", argv[i]);
89
90 if (sockaddr_from_str(sa, AF_UNSPEC, argv[i]) == -1) {
91 printf(" => invalid address\n");
92 continue;
93 }
94
95 if (sa->sa_family == PF_INET)
96 ((struct sockaddr_in *)sa)->sin_port = htons(port);
97 else if (sa->sa_family == PF_INET6)
98 ((struct sockaddr_in6 *)sa)->sin6_port = htons(port);
99
100 errno = 0;
101 h_errno = 0;
102 gai_errno = 0;
103 rrset_errno = 0;
104
105 gai_errno = getnameinfo(sa, sa->sa_len, host, sizeof host, serv,
106 sizeof serv, flags);
107
108 if (gai_errno == 0)
109 printf(" %s:%s\n", host, serv);
110 print_errors();
111
112 }
113
114 return (0);
115}
diff --git a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile b/src/regress/lib/libc/asr/bin/getnameinfo/Makefile
deleted file mode 100644
index 4927ee9486..0000000000
--- a/src/regress/lib/libc/asr/bin/getnameinfo/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= getnameinfo
6SRCS+= getnameinfo.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr.c b/src/regress/lib/libc/asr/bin/getnetnamadr.c
deleted file mode 100644
index e615e8663f..0000000000
--- a/src/regress/lib/libc/asr/bin/getnetnamadr.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/* $OpenBSD: getnetnamadr.c,v 1.2 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
31static void
32usage(void)
33{
34 extern const char * __progname;
35
36 fprintf(stderr, "usage: %s [-aen] [host...]\n", __progname);
37 exit(1);
38}
39
40int
41main(int argc, char *argv[])
42{
43 int i, ch, nflag = 0;
44 struct netent *n;
45 char *host;
46
47 while((ch = getopt(argc, argv, "R:en")) != -1) {
48 switch(ch) {
49 case 'R':
50 parseresopt(optarg);
51 break;
52 case 'e':
53 long_err += 1;
54 break;
55 case 'n':
56 nflag = 1;
57 break;
58 default:
59 usage();
60 /* NOTREACHED */
61 }
62 }
63 argc -= optind;
64 argv += optind;
65
66 for(i = 0; i < argc; i++) {
67
68 if (i)
69 printf("\n");
70 printf("===> \"%s\"\n", argv[i]);
71 host = gethostarg(argv[i]);
72
73 errno = 0;
74 h_errno = 0;
75 gai_errno = 0;
76 rrset_errno = 0;
77
78 if (nflag)
79 n = getnetbyname(host);
80 else
81 n = getnetbyaddr(inet_network(host), AF_INET);
82 if (n)
83 print_netent(n);
84 print_errors();
85 }
86
87 return (0);
88}
diff --git a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile b/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile
deleted file mode 100644
index 521bf8eb7e..0000000000
--- a/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= getnetnamadr
6SRCS+= getnetnamadr.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname.c b/src/regress/lib/libc/asr/bin/getrrsetbyname.c
deleted file mode 100644
index 8f48501a3f..0000000000
--- a/src/regress/lib/libc/asr/bin/getrrsetbyname.c
+++ /dev/null
@@ -1,91 +0,0 @@
1/* $OpenBSD: getrrsetbyname.c,v 1.2 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
18#include <sys/types.h>
19
20#include <netinet/in.h>
21#include <arpa/nameser.h>
22
23#include <err.h>
24#include <errno.h>
25#include <getopt.h>
26#include <resolv.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30
31#include "common.h"
32
33static void
34usage(void)
35{
36 extern const char * __progname;
37
38 fprintf(stderr, "usage: %s [-e] [-t type] [host...]\n",
39 __progname);
40 exit(1);
41}
42
43int
44main(int argc, char *argv[])
45{
46 int ch, i;
47 uint16_t type = T_A;
48 char *host;
49 struct rrsetinfo *rrset;
50
51 while((ch = getopt(argc, argv, "R:et:")) != -1) {
52 switch(ch) {
53 case 'R':
54 parseresopt(optarg);
55 break;
56 case 'e':
57 long_err += 1;
58 break;
59 case 't':
60 if ((type = strtotype(optarg)) == 0)
61 usage();
62 break;
63 default:
64 usage();
65 /* NOTREACHED */
66 }
67 }
68 argc -= optind;
69 argv += optind;
70
71 for (i = 0; i < argc; i++) {
72
73 if (i)
74 printf("\n");
75 printf("===> \"%s\"\n", argv[i]);
76 host = gethostarg(argv[i]);
77
78 errno = 0;
79 h_errno = 0;
80 gai_errno = 0;
81 rrset_errno = 0;
82
83 rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset);
84
85 if (rrset_errno == 0)
86 print_rrsetinfo(rrset);
87 print_errors();
88 }
89
90 return (0);
91}
diff --git a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile b/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile
deleted file mode 100644
index 131403bea1..0000000000
--- a/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= getrrsetbyname
6SRCS+= getrrsetbyname.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery.c b/src/regress/lib/libc/asr/bin/res_mkquery.c
deleted file mode 100644
index ed41e1120d..0000000000
--- a/src/regress/lib/libc/asr/bin/res_mkquery.c
+++ /dev/null
@@ -1,322 +0,0 @@
1/* $OpenBSD: res_mkquery.c,v 1.3 2022/01/20 14:18:10 naddy 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
18#include <sys/types.h>
19#include <sys/socket.h>
20
21#include <netinet/in.h>
22#include <arpa/nameser.h>
23#include <arpa/inet.h>
24
25#include <err.h>
26#include <errno.h>
27#include <getopt.h>
28#include <inttypes.h>
29#include <resolv.h>
30#include <stdio.h>
31#include <stdlib.h>
32#include <string.h>
33
34#include "common.h"
35
36/* in asr.c but we don't want them exposed right now */
37static void dump_packet(const void *, size_t);
38
39static char *print_query(struct query *, char *, size_t);
40static char *print_rr(struct rr *, char *, size_t);
41static char *print_host(const struct sockaddr *, char *, size_t);
42static char* print_dname(const char *, char *, size_t);
43
44
45static void
46usage(void)
47{
48 extern const char * __progname;
49
50 fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n",
51 __progname);
52 exit(1);
53}
54
55int
56main(int argc, char *argv[])
57{
58 int ch, i, r;
59 uint16_t type = T_A;
60 char buf[1024], *host;
61
62 while((ch = getopt(argc, argv, "R:et:")) != -1) {
63 switch(ch) {
64 case 'R':
65 parseresopt(optarg);
66 break;
67 case 'e':
68 long_err += 1;
69 break;
70 case 't':
71 if ((type = strtotype(optarg)) == 0)
72 usage();
73 break;
74 default:
75 usage();
76 /* NOTREACHED */
77 }
78 }
79 argc -= optind;
80 argv += optind;
81
82 for (i = 0; i < argc; i++) {
83
84 if (i)
85 printf("\n");
86
87 printf("===> \"%s\"\n", argv[i]);
88 host = gethostarg(argv[i]);
89
90 errno = 0;
91 h_errno = 0;
92 gai_errno = 0;
93 rrset_errno = 0;
94
95 r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf));
96 if (r != -1) {
97 dump_packet(buf, r);
98 printf(";; MSG SIZE %i\n", r);
99 }
100 print_errors();
101 }
102
103 return (0);
104}
105
106#define OPCODE_SHIFT 11
107#define Z_SHIFT 4
108
109static char*
110print_header(struct header *h, char *buf, size_t max)
111{
112 snprintf(buf, max,
113 "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i",
114 (h->flags & QR_MASK) ? "QR":" ",
115 (int)(OPCODE(h->flags) >> OPCODE_SHIFT),
116 (h->flags & AA_MASK) ? "AA":" ",
117 (h->flags & TC_MASK) ? "TC":" ",
118 (h->flags & RD_MASK) ? "RD":" ",
119 (h->flags & RA_MASK) ? "RA":" ",
120 ((h->flags & Z_MASK) >> Z_SHIFT),
121 rcodetostr(RCODE(h->flags)),
122 h->qdcount, h->ancount, h->nscount, h->arcount);
123
124 return buf;
125}
126
127static void
128dump_packet(const void *data, size_t len)
129{
130 char buf[1024];
131 struct packed p;
132 struct header h;
133 struct query q;
134 struct rr rr;
135 int i, an, ns, ar, n;
136
137 packed_init(&p, (char *)data, len);
138
139 if (unpack_header(&p, &h) == -1) {
140 printf(";; BAD PACKET: %s\n", p.err);
141 return;
142 }
143
144 printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf));
145
146 if (h.qdcount)
147 printf(";; QUERY SECTION:\n");
148 for (i = 0; i < h.qdcount; i++) {
149 if (unpack_query(&p, &q) == -1)
150 goto error;
151 printf("%s\n", print_query(&q, buf, sizeof buf));
152 }
153
154 an = 0;
155 ns = an + h.ancount;
156 ar = ns + h.nscount;
157 n = ar + h.arcount;
158
159 for (i = 0; i < n; i++) {
160 if (i == an)
161 printf("\n;; ANSWER SECTION:\n");
162 if (i == ns)
163 printf("\n;; AUTHORITY SECTION:\n");
164 if (i == ar)
165 printf("\n;; ADDITIONAL SECTION:\n");
166
167 if (unpack_rr(&p, &rr) == -1)
168 goto error;
169 printf("%s\n", print_rr(&rr, buf, sizeof buf));
170 }
171
172 if (p.offset != len)
173 printf(";; REMAINING GARBAGE %zu\n", len - p.offset);
174
175 error:
176 if (p.err)
177 printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len,
178 p.err);
179}
180
181static const char *
182inet6_ntoa(struct in6_addr a)
183{
184 static char buf[256];
185 struct sockaddr_in6 si;
186
187 si.sin6_len = sizeof(si);
188 si.sin6_family = PF_INET6;
189 si.sin6_addr = a;
190
191 return print_host((struct sockaddr*)&si, buf, sizeof buf);
192}
193
194static char*
195print_rr(struct rr *rr, char *buf, size_t max)
196{
197 char *res;
198 char tmp[256];
199 char tmp2[256];
200 int r;
201
202 res = buf;
203
204 r = snprintf(buf, max, "%s %u %s %s ",
205 print_dname(rr->rr_dname, tmp, sizeof tmp),
206 rr->rr_ttl,
207 classtostr(rr->rr_class),
208 typetostr(rr->rr_type));
209 if (r == -1) {
210 buf[0] = '\0';
211 return buf;
212 }
213
214 if ((size_t)r >= max)
215 return buf;
216
217 max -= r;
218 buf += r;
219
220 switch(rr->rr_type) {
221 case T_CNAME:
222 print_dname(rr->rr.cname.cname, buf, max);
223 break;
224 case T_MX:
225 snprintf(buf, max, "%"PRIu32" %s",
226 rr->rr.mx.preference,
227 print_dname(rr->rr.mx.exchange, tmp, sizeof tmp));
228 break;
229 case T_NS:
230 print_dname(rr->rr.ns.nsname, buf, max);
231 break;
232 case T_PTR:
233 print_dname(rr->rr.ptr.ptrname, buf, max);
234 break;
235 case T_SOA:
236 snprintf(buf, max,
237 "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32,
238 print_dname(rr->rr.soa.rname, tmp, sizeof tmp),
239 print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2),
240 rr->rr.soa.serial,
241 rr->rr.soa.refresh,
242 rr->rr.soa.retry,
243 rr->rr.soa.expire,
244 rr->rr.soa.minimum);
245 break;
246 case T_A:
247 if (rr->rr_class != C_IN)
248 goto other;
249 snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr));
250 break;
251 case T_AAAA:
252 if (rr->rr_class != C_IN)
253 goto other;
254 snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6));
255 break;
256 default:
257 other:
258 snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen);
259 break;
260 }
261
262 return (res);
263}
264
265static char*
266print_query(struct query *q, char *buf, size_t max)
267{
268 char b[256];
269
270 snprintf(buf, max, "%s %s %s",
271 print_dname(q->q_dname, b, sizeof b),
272 classtostr(q->q_class), typetostr(q->q_type));
273
274 return (buf);
275}
276
277
278static char *
279print_host(const struct sockaddr *sa, char *buf, size_t len)
280{
281 switch (sa->sa_family) {
282 case AF_INET:
283 inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len);
284 break;
285 case AF_INET6:
286 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len);
287 break;
288 default:
289 buf[0] = '\0';
290 }
291 return (buf);
292}
293
294static char*
295print_dname(const char *_dname, char *buf, size_t max)
296{
297 const unsigned char *dname = _dname;
298 char *res;
299 size_t left, count;
300
301 if (_dname[0] == 0) {
302 strlcpy(buf, ".", max);
303 return buf;
304 }
305
306 res = buf;
307 left = max - 1;
308 while (dname[0] && left) {
309 count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
310 memmove(buf, dname + 1, count);
311 dname += dname[0] + 1;
312 left -= count;
313 buf += count;
314 if (left) {
315 left -= 1;
316 *buf++ = '.';
317 }
318 }
319 buf[0] = 0;
320
321 return (res);
322}
diff --git a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile b/src/regress/lib/libc/asr/bin/res_mkquery/Makefile
deleted file mode 100644
index 4ae259e45d..0000000000
--- a/src/regress/lib/libc/asr/bin/res_mkquery/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= res_mkquery
6SRCS+= res_mkquery.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/res_query.c b/src/regress/lib/libc/asr/bin/res_query.c
deleted file mode 100644
index a2c3686ca3..0000000000
--- a/src/regress/lib/libc/asr/bin/res_query.c
+++ /dev/null
@@ -1,358 +0,0 @@
1/* $OpenBSD: res_query.c,v 1.4 2022/01/20 14:18:10 naddy 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
18#include <sys/types.h>
19#include <sys/socket.h>
20#include <sys/time.h>
21
22#include <netinet/in.h>
23#include <arpa/nameser.h>
24#include <arpa/inet.h>
25
26#include <err.h>
27#include <errno.h>
28#include <getopt.h>
29#include <inttypes.h>
30#include <resolv.h>
31#include <stdio.h>
32#include <stdlib.h>
33#include <string.h>
34
35#include "common.h"
36
37/* in asr.c but we don't want them exposed right now */
38static void dump_packet(const void *, size_t);
39
40static char *print_query(struct query *, char *, size_t);
41static char *print_rr(struct rr *, char *, size_t);
42static char *print_host(const struct sockaddr *, char *, size_t);
43static char* print_dname(const char *, char *, size_t);
44
45
46static int
47msec(struct timeval start, struct timeval end)
48{
49 return (int)((end.tv_sec - start.tv_sec) * 1000
50 + (end.tv_usec - start.tv_usec) / 1000);
51}
52
53static void
54usage(void)
55{
56 extern const char * __progname;
57
58 fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n",
59 __progname);
60 exit(1);
61}
62
63int
64main(int argc, char *argv[])
65{
66 struct timeval start, end;
67 time_t when;
68 int ch, i, qflag, dflag, r;
69 uint16_t type = T_A;
70 char buf[1024], *host;
71
72 dflag = 0;
73 qflag = 0;
74
75 while((ch = getopt(argc, argv, "R:deqt:")) != -1) {
76 switch(ch) {
77 case 'R':
78 parseresopt(optarg);
79 break;
80 case 'd':
81 dflag = 1;
82 break;
83 case 'e':
84 long_err += 1;
85 break;
86 case 'q':
87 qflag = 1;
88 break;
89 case 't':
90 if ((type = strtotype(optarg)) == 0)
91 usage();
92 break;
93 default:
94 usage();
95 /* NOTREACHED */
96 }
97 }
98 argc -= optind;
99 argv += optind;
100
101 for (i = 0; i < argc; i++) {
102
103 if (i)
104 printf("\n");
105
106 printf("===> \"%s\"\n", argv[i]);
107 host = gethostarg(argv[i]);
108
109 errno = 0;
110 h_errno = 0;
111 gai_errno = 0;
112 rrset_errno = 0;
113
114 if (gettimeofday(&start, NULL) != 0)
115 err(1, "gettimeofday");
116
117 if (qflag)
118 r = res_query(host, C_IN, type, buf, sizeof(buf));
119 else
120 r = res_search(host, C_IN, type, buf, sizeof(buf));
121
122 if (gettimeofday(&end, NULL) != 0)
123 err(1, "gettimeofday");
124
125 if (r != -1) {
126 dump_packet(buf, r);
127 printf("\n");
128 if (dflag) {
129 printf(";; Query time: %d msec\n",
130 msec(start, end));
131 when = time(NULL);
132 printf(";; WHEN: %s", ctime(&when));
133 }
134 printf(";; MSG SIZE rcvd: %i\n", r);
135 }
136 print_errors();
137 }
138
139 return (0);
140}
141
142#define OPCODE_SHIFT 11
143#define Z_SHIFT 4
144
145static char*
146print_header(struct header *h, char *buf, size_t max)
147{
148 snprintf(buf, max,
149 "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i",
150 (h->flags & QR_MASK) ? "QR":" ",
151 (int)(OPCODE(h->flags) >> OPCODE_SHIFT),
152 (h->flags & AA_MASK) ? "AA":" ",
153 (h->flags & TC_MASK) ? "TC":" ",
154 (h->flags & RD_MASK) ? "RD":" ",
155 (h->flags & RA_MASK) ? "RA":" ",
156 ((h->flags & Z_MASK) >> Z_SHIFT),
157 rcodetostr(RCODE(h->flags)),
158 h->qdcount, h->ancount, h->nscount, h->arcount);
159
160 return buf;
161}
162
163static void
164dump_packet(const void *data, size_t len)
165{
166 char buf[1024];
167 struct packed p;
168 struct header h;
169 struct query q;
170 struct rr rr;
171 int i, an, ns, ar, n;
172
173 packed_init(&p, (char *)data, len);
174
175 if (unpack_header(&p, &h) == -1) {
176 printf(";; BAD PACKET: %s\n", p.err);
177 return;
178 }
179
180 printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf));
181
182 if (h.qdcount)
183 printf(";; QUERY SECTION:\n");
184 for (i = 0; i < h.qdcount; i++) {
185 if (unpack_query(&p, &q) == -1)
186 goto error;
187 printf("%s\n", print_query(&q, buf, sizeof buf));
188 }
189
190 an = 0;
191 ns = an + h.ancount;
192 ar = ns + h.nscount;
193 n = ar + h.arcount;
194
195 for (i = 0; i < n; i++) {
196 if (i == an)
197 printf("\n;; ANSWER SECTION:\n");
198 if (i == ns)
199 printf("\n;; AUTHORITY SECTION:\n");
200 if (i == ar)
201 printf("\n;; ADDITIONAL SECTION:\n");
202
203 if (unpack_rr(&p, &rr) == -1)
204 goto error;
205 printf("%s\n", print_rr(&rr, buf, sizeof buf));
206 }
207
208 if (p.offset != len)
209 printf(";; REMAINING GARBAGE %zu\n", len - p.offset);
210
211 error:
212 if (p.err)
213 printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len,
214 p.err);
215}
216
217static const char *
218inet6_ntoa(struct in6_addr a)
219{
220 static char buf[256];
221 struct sockaddr_in6 si;
222
223 si.sin6_len = sizeof(si);
224 si.sin6_family = PF_INET6;
225 si.sin6_addr = a;
226
227 return print_host((struct sockaddr*)&si, buf, sizeof buf);
228}
229
230static char*
231print_rr(struct rr *rr, char *buf, size_t max)
232{
233 char *res;
234 char tmp[256];
235 char tmp2[256];
236 int r;
237
238 res = buf;
239
240 r = snprintf(buf, max, "%s %u %s %s ",
241 print_dname(rr->rr_dname, tmp, sizeof tmp),
242 rr->rr_ttl,
243 classtostr(rr->rr_class),
244 typetostr(rr->rr_type));
245 if (r == -1) {
246 buf[0] = '\0';
247 return buf;
248 }
249
250 if ((size_t)r >= max)
251 return buf;
252
253 max -= r;
254 buf += r;
255
256 switch(rr->rr_type) {
257 case T_CNAME:
258 print_dname(rr->rr.cname.cname, buf, max);
259 break;
260 case T_MX:
261 snprintf(buf, max, "%"PRIu32" %s",
262 rr->rr.mx.preference,
263 print_dname(rr->rr.mx.exchange, tmp, sizeof tmp));
264 break;
265 case T_NS:
266 print_dname(rr->rr.ns.nsname, buf, max);
267 break;
268 case T_PTR:
269 print_dname(rr->rr.ptr.ptrname, buf, max);
270 break;
271 case T_SOA:
272 snprintf(buf, max,
273 "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32,
274 print_dname(rr->rr.soa.rname, tmp, sizeof tmp),
275 print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2),
276 rr->rr.soa.serial,
277 rr->rr.soa.refresh,
278 rr->rr.soa.retry,
279 rr->rr.soa.expire,
280 rr->rr.soa.minimum);
281 break;
282 case T_A:
283 if (rr->rr_class != C_IN)
284 goto other;
285 snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr));
286 break;
287 case T_AAAA:
288 if (rr->rr_class != C_IN)
289 goto other;
290 snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6));
291 break;
292 default:
293 other:
294 snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen);
295 break;
296 }
297
298 return (res);
299}
300
301static char*
302print_query(struct query *q, char *buf, size_t max)
303{
304 char b[256];
305
306 snprintf(buf, max, "%s %s %s",
307 print_dname(q->q_dname, b, sizeof b),
308 classtostr(q->q_class), typetostr(q->q_type));
309
310 return (buf);
311}
312
313
314static char *
315print_host(const struct sockaddr *sa, char *buf, size_t len)
316{
317 switch (sa->sa_family) {
318 case AF_INET:
319 inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len);
320 break;
321 case AF_INET6:
322 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len);
323 break;
324 default:
325 buf[0] = '\0';
326 }
327 return (buf);
328}
329
330static char*
331print_dname(const char *_dname, char *buf, size_t max)
332{
333 const unsigned char *dname = _dname;
334 char *res;
335 size_t left, count;
336
337 if (_dname[0] == 0) {
338 strlcpy(buf, ".", max);
339 return buf;
340 }
341
342 res = buf;
343 left = max - 1;
344 while (dname[0] && left) {
345 count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
346 memmove(buf, dname + 1, count);
347 dname += dname[0] + 1;
348 left -= count;
349 buf += count;
350 if (left) {
351 left -= 1;
352 *buf++ = '.';
353 }
354 }
355 buf[0] = 0;
356
357 return (res);
358}
diff --git a/src/regress/lib/libc/asr/bin/res_query/Makefile b/src/regress/lib/libc/asr/bin/res_query/Makefile
deleted file mode 100644
index 6f4d83392b..0000000000
--- a/src/regress/lib/libc/asr/bin/res_query/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1# $OpenBSD: Makefile,v 1.2 2017/03/09 08:26:42 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= res_query
6SRCS+= res_query.c
7
8.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/bin/threads.c b/src/regress/lib/libc/asr/bin/threads.c
deleted file mode 100644
index f296f1d6f7..0000000000
--- a/src/regress/lib/libc/asr/bin/threads.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/* $OpenBSD: threads.c,v 1.1.1.1 2012/07/13 17:49:53 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/time.h>
18#include <sys/resource.h>
19
20#include <assert.h>
21#include <err.h>
22#include <getopt.h>
23#include <pthread.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <time.h>
27
28#include <netdb.h>
29
30#define MAX_THREADS 50
31
32int ac;
33char **av;
34int loop;
35int nthreads;
36
37int long_err;
38int gai_errno;
39int rrset_errno;
40
41void async_resolver_done(void *);
42
43void stats(void)
44{
45 struct rusage ru;
46
47 getrusage(RUSAGE_SELF, &ru);
48 printf("%li\n", ru.ru_maxrss);
49}
50
51void*
52task(void *arg)
53{
54 int id, i, j, c;
55 struct addrinfo *ai, *n;
56
57 id = *((int*) arg);
58
59 n = NULL; c =0;
60
61 for(j = 0; j < loop; j++)
62 for(i = 0; i < ac; i++) {
63 if (getaddrinfo(av[i], NULL, NULL, &ai) == 0) {
64/*
65 for (c = 0, n = ai; n; c++, n = n->ai_next);
66 printf("%i:%s: ok: %i\n", id, av[i], c);
67*/
68 freeaddrinfo(ai);
69 } else {
70/*
71 printf("%i:%s: fail\n", id, av[i]);
72*/
73 }
74 }
75 return (NULL);
76}
77
78void
79usage(void)
80{
81 extern const char *__progname;
82 fprintf(stderr, "usage: %s [-L loop] [-l loop] [-t threads] <host> ...\n",
83 __progname);
84}
85
86int
87main(int argc, char **argv)
88{
89 pthread_t th[MAX_THREADS];
90 int th_args[MAX_THREADS], r, i, ch;
91 int n, LOOP;
92
93 nthreads = 1;
94 loop = 1;
95 LOOP = 1;
96
97 while ((ch = getopt(argc, argv, "L:l:t:")) != -1) {
98 switch (ch) {
99 case 'L':
100 LOOP = atoi(optarg);
101 break;
102 case 'l':
103 loop = atoi(optarg);
104 break;
105 case 't':
106 nthreads = atoi(optarg);
107 if (nthreads > MAX_THREADS)
108 nthreads = MAX_THREADS;
109 break;
110 default:
111 usage();
112 /* NOTREACHED */
113 }
114 }
115
116 argc -= optind;
117 argv += optind;
118
119 ac = argc;
120 av = argv;
121
122 printf("%i %i %i\n", LOOP, nthreads, loop);
123 for (n = 0; n < LOOP; n ++) {
124 for (i = 0; i < nthreads; i++) {
125 th_args[i] = i;
126 r = pthread_create(&th[i], NULL, task, (void *) &th_args[i]);
127 if (r == -1)
128 errx(1, "pthread_create");
129 }
130 for (i = 0; i < nthreads; i++)
131 pthread_join(th[i], NULL);
132
133 if (nthreads == 0)
134 task(&n);
135
136 stats();
137 }
138
139 return (0);
140}
diff --git a/src/regress/lib/libc/asr/bin/threads/Makefile b/src/regress/lib/libc/asr/bin/threads/Makefile
deleted file mode 100644
index 3252511cd1..0000000000
--- a/src/regress/lib/libc/asr/bin/threads/Makefile
+++ /dev/null
@@ -1,10 +0,0 @@
1# $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $
2
3.PATH: ${.CURDIR}/..
4
5PROG= threads
6SRCS+= threads.c
7
8LDADD= -lpthread
9
10.include <bsd.prog.mk>
diff --git a/src/regress/lib/libc/asr/regress.sh b/src/regress/lib/libc/asr/regress.sh
deleted file mode 100644
index a0950cefde..0000000000
--- a/src/regress/lib/libc/asr/regress.sh
+++ /dev/null
@@ -1,111 +0,0 @@
1# $OpenBSD: regress.sh,v 1.7 2017/03/10 17:23:48 eric Exp $
2
3. regress.subr
4
5test_res_mkquery()
6{
7 for i in $@; do
8 regress res_mkquery $i
9 done
10}
11
12test_res_query()
13{
14 for i in $@; do
15 regress res_query $i
16 regress res_query -q $i
17 done
18}
19
20test_getrrsetbyname()
21{
22 for i in $@; do
23 regress getrrsetbyname $i
24 regress getrrsetbyname -t MX $i
25 regress getrrsetbyname -t AAAA $i
26 done
27}
28
29test_gethostbyname()
30{
31 for i in $@; do
32 regress gethostnamadr $i
33 regress gethostnamadr -4 $i
34 regress gethostnamadr -6 $i
35 done
36}
37
38test_gethostbyaddr()
39{
40 for i in $@; do
41 regress gethostnamadr -a $i
42 done
43}
44
45test_getaddrinfo()
46{
47 for i in $@; do
48 regress getaddrinfo $i
49 regress getaddrinfo -C $i
50 regress getaddrinfo -F $i
51 regress getaddrinfo -CF $i
52 regress getaddrinfo -P $i
53 regress getaddrinfo -PF $i
54 regress getaddrinfo -PC $i
55 regress getaddrinfo -H $i
56 regress getaddrinfo -p tcp $i
57 regress getaddrinfo -p udp $i
58 regress getaddrinfo -s www $i
59 regress getaddrinfo -s bad $i
60 regress getaddrinfo -S -s 8081 $i
61 regress getaddrinfo -S -s bad $i
62 regress getaddrinfo -P -s syslog $i
63 regress getaddrinfo -P -s syslog -p tcp $i
64 regress getaddrinfo -P -s syslog -p udp $i
65 done
66}
67
68test_getaddrinfo2()
69{
70 for i in $@; do
71 regress getaddrinfo -f inet6 -t raw -p icmpv6 $i
72 done
73}
74
75test_getnameinfo()
76{
77 for i in $@; do
78 regress getnameinfo $i
79 regress getnameinfo -D $i
80 regress getnameinfo -F $i
81 regress getnameinfo -H $i
82 regress getnameinfo -N $i
83 regress getnameinfo -S $i
84 regress getnameinfo -p 80 $i
85 regress getnameinfo -p 514 $i
86 regress getnameinfo -p 514 -D $i
87 regress getnameinfo -p 5566 $i
88 done
89}
90
91WEIRD="EMPTY . .. ..."
92BASIC="localhost $(hostname -s) $(hostname)"
93EXTRA="undeadly.org www.openbsd.org cvs.openbsd.org www.google.com www.bing.com"
94
95ADDRS="0.0.0.0 :: 127.0.0.1 ::1 212.227.193.194"
96
97for e in file bind local; do
98 regress_setenv $e
99
100 test_res_mkquery $WEIRD $BASIC
101 test_res_query $WEIRD $BASIC $EXTRA
102 test_getrrsetbyname $WEIRD $BASIC $EXTRA
103 test_gethostbyname $WEIRD $BASIC $EXTRA
104 test_gethostbyaddr $ADDRS
105 test_getaddrinfo NULL $WEIRD $BASIC $EXTRA
106 test_getaddrinfo2 undeadly.org www.kame.net
107 test_getnameinfo $ADDRS
108 test_gethostbyname $ADDRS
109done
110
111regress_digest
diff --git a/src/regress/lib/libc/asr/regress.subr b/src/regress/lib/libc/asr/regress.subr
deleted file mode 100644
index 6ce645bc33..0000000000
--- a/src/regress/lib/libc/asr/regress.subr
+++ /dev/null
@@ -1,122 +0,0 @@
1#!/bin/sh
2# $OpenBSD: regress.subr,v 1.4 2017/03/14 20:22:06 eric Exp $
3
4set -e
5
6fail()
7{
8 echo "*** ERROR: $@"
9 exit 1
10}
11
12regress()
13{
14 local cmd="$1"
15 local bin0="/bin/${cmd}${A}"
16 local bin1="/bin/${cmd}${B}"
17 local out="${OUTDIR}/test-${COUNT}.out"
18 local out0="${OUTDIR}/test-${COUNT}${A}.out"
19 local out1="${OUTDIR}/test-${COUNT}${B}.out"
20 local err0="${OUTDIR}/test-${COUNT}${A}.err"
21 local err1="${OUTDIR}/test-${COUNT}${B}.err"
22 local outdiff="${OUTDIR}/test-${COUNT}${A}${B}.diff"
23 shift
24
25 test -x "${ROOTDIR}${bin0}" || fail "${ROOTDIR}${bin0}" not executable
26 test -x "${ROOTDIR}${bin1}" || fail "${ROOTDIR}${bin1}" not executable
27
28 echo -n "${cmd} $@ ."
29
30 set +e
31 chroot -u bin "${ROOTDIR}" ${bin0} $@ > ${out0}
32 echo -n .
33 chroot -u bin "${ROOTDIR}" ${bin1} $@ > ${out1}
34 echo -n "."
35
36 diff -u ${out0} ${out1} > ${outdiff}
37 set -e
38 if test -s ${outdiff}; then
39 FAIL=$((FAIL+1))
40 echo fail
41 echo "### FAIL [#${COUNT} env=${REGRESSENV}] ${cmd} $@" >> $ERR
42 cat ${outdiff} >> $ERR
43 echo >> $ERR
44 else
45 rm ${outdiff}
46 rm ${out1}
47 mv ${out0} ${out}
48 OK=$((OK+1))
49 echo ok
50 echo "### OK [#${COUNT} env=$REGRESSENV] ${cmd} $@" >> $OUT
51 cat ${out} >> $OUT
52 echo >> $OUT
53 fi
54
55 COUNT=$((COUNT+1))
56}
57
58regress_setenv()
59{
60 local _name="$1"
61
62 echo "==> using env $_name"
63
64 mkdir -p "${ROOTDIR}/etc/"
65 cp /etc/hosts "${ROOTDIR}/etc/"
66 cp /etc/resolv.conf "${ROOTDIR}/etc/"
67 cp /etc/protocols "${ROOTDIR}/etc/"
68 cp /etc/networks "${ROOTDIR}/etc/"
69 cp /etc/services "${ROOTDIR}/etc/"
70
71 case $_name in
72 empty)
73 rm -f "${ROOTDIR}/etc/*"
74 ;;
75 local)
76 ;;
77 file)
78 grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf"
79 echo "lookup file" >> "${ROOTDIR}/etc/resolv.conf"
80 ;;
81 bind)
82 grep -v lookup /etc/resolv.conf > "${ROOTDIR}/etc/resolv.conf"
83 echo "lookup bind" >> "${ROOTDIR}/etc/resolv.conf"
84 ;;
85 *)
86 fail unknown env $_name
87 ;;
88 esac
89 REGRESSENV=$_name
90}
91
92regress_digest()
93{
94 echo "===> done"
95 test -f $ERR && (echo; cat $ERR; echo "===> errfile=$ERR")
96 echo "===> logfile=$OUT"
97 echo "===> run=$COUNT ok=$OK fail=$FAIL error=$ERROR"
98
99}
100
101# needed for chroot
102test "$(id -u)" -ne 0 && fail need root privileges to run this script
103
104# we really really want to avoid erasing /etc later
105test "${RUNDIR}" || fail RUNDIR is not set
106
107ROOTDIR=$(readlink -fn ${RUNDIR})
108test "${ROOTDIR}" == "/" && fail RUNDIR is root dir: ${RUNDIR}
109
110COUNT=0
111OK=0
112FAIL=0
113ERROR=0
114A=${A:=.a}
115B=${B:=.b}
116
117OUTDIR=$(mktemp -d -p $ROOTDIR)
118chmod a+rx ${OUTDIR}
119echo "===> ${OUTDIR}"
120
121OUT=$OUTDIR/regress.log
122ERR=$OUTDIR/regress.err