summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/asr/bin
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2018-11-07 01:08:50 +0000
committercvs2svn <admin@example.com>2018-11-07 01:08:50 +0000
commit2035faf3f8aa95b888d9416c3cc7328c0ea18beb (patch)
treef08a08d357c5d30455c569890f747c1d9b241316 /src/regress/lib/libc/asr/bin
parentbe03b61c1b8f59ccdd34dbe5f6c6b30de697d28b (diff)
downloadopenbsd-bluhm_20181106.tar.gz
openbsd-bluhm_20181106.tar.bz2
openbsd-bluhm_20181106.zip
This commit was manufactured by cvs2git to create tag 'bluhm_20181106'.bluhm_20181106
Diffstat (limited to 'src/regress/lib/libc/asr/bin')
-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.c635
-rw-r--r--src/regress/lib/libc/asr/bin/common.h136
-rw-r--r--src/regress/lib/libc/asr/bin/getaddrinfo.c135
-rw-r--r--src/regress/lib/libc/asr/bin/getaddrinfo/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/gethostnamadr.c113
-rw-r--r--src/regress/lib/libc/asr/bin/gethostnamadr/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getnameinfo.c112
-rw-r--r--src/regress/lib/libc/asr/bin/getnameinfo/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getnetnamadr.c85
-rw-r--r--src/regress/lib/libc/asr/bin/getnetnamadr/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/getrrsetbyname.c88
-rw-r--r--src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/res_mkquery.c319
-rw-r--r--src/regress/lib/libc/asr/bin/res_mkquery/Makefile8
-rw-r--r--src/regress/lib/libc/asr/bin/res_query.c355
-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
20 files changed, 0 insertions, 2202 deletions
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 c808c86d61..0000000000
--- a/src/regress/lib/libc/asr/bin/common.c
+++ /dev/null
@@ -1,635 +0,0 @@
1/* $OpenBSD: common.c,v 1.3 2014/08/10 07:31:58 guenther 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 uint16_t 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
138
139const char *
140rcodetostr(uint16_t v)
141{
142 static char buf[16];
143 size_t i;
144
145 for(i = 0; kv_rcode[i].key; i++)
146 if (kv_rcode[i].value == v)
147 return (kv_rcode[i].key);
148
149 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
150
151 return (buf);
152}
153
154const char *
155typetostr(uint16_t v)
156{
157 static char buf[16];
158 size_t i;
159
160 for(i = 0; kv_type[i].key; i++)
161 if (kv_type[i].value == v)
162 return (kv_type[i].key);
163
164 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
165
166 return (buf);
167}
168
169const char *
170classtostr(uint16_t v)
171{
172 static char buf[16];
173 size_t i;
174
175 for(i = 0; kv_class[i].key; i++)
176 if (kv_class[i].value == v)
177 return (kv_class[i].key);
178
179 snprintf(buf, sizeof buf, "%"PRIu16"?", v);
180
181 return (buf);
182}
183
184uint16_t
185strtotype(const char *name)
186{
187 size_t i;
188
189 for(i = 0; kv_type[i].key; i++)
190 if (!strcmp(kv_type[i].key, name))
191 return (kv_type[i].value);
192
193 return (0);
194}
195
196uint16_t
197strtoclass(const char *name)
198{
199 size_t i;
200
201 for(i = 0; kv_class[i].key; i++)
202 if (!strcmp(kv_class[i].key, name))
203 return (kv_class[i].value);
204
205 return (0);
206}
207
208void
209print_hostent(struct hostent *e)
210{
211 char buf[256], **c;
212
213 printf("name = \"%s\"\n", e->h_name);
214 printf("aliases =");
215 for(c = e->h_aliases; *c; c++)
216 printf(" \"%s\"", *c);
217 printf("\n");
218 printf("addrtype = %i\n", e->h_addrtype);
219 printf("addrlength = %i\n", e->h_length);
220 printf("addr_list =");
221 for(c = e->h_addr_list; *c; c++) {
222 printf(" %s", inet_ntop(e->h_addrtype, *c, buf, sizeof buf));
223 }
224 printf("\n");
225}
226
227void
228print_netent(struct netent *e)
229{
230 char buf[256], **c;
231 uint32_t addr;
232
233 /* network number are given in host order */
234 addr = htonl(e->n_net);
235
236 printf("name = \"%s\"\n", e->n_name);
237 printf("aliases =");
238 for (c = e->n_aliases; *c; c++)
239 printf(" \"%s\"", *c);
240 printf("\n");
241 printf("addrtype = %i\n", e->n_addrtype);
242 printf("net = %s\n", inet_ntop(e->n_addrtype, &addr, buf, sizeof buf));
243}
244
245void
246print_addrinfo(struct addrinfo *ai)
247{
248 char buf[256], bf[64], bt[64], bp[64];
249
250 printf("family=%s socktype=%s protocol=%s addr=%s canonname=%s\n",
251 kv_lookup_name(kv_family, ai->ai_family, bf, sizeof bf),
252 kv_lookup_name(kv_socktype, ai->ai_socktype, bt, sizeof bt),
253 kv_lookup_name(kv_protocol, ai->ai_protocol, bp, sizeof bp),
254 print_addr(ai->ai_addr, buf, sizeof buf),
255 ai->ai_canonname);
256}
257
258const char *
259rrsetstrerror(int e)
260{
261 switch (e) {
262 case 0:
263 return "OK";
264 case ERRSET_NONAME:
265 return "ERRSET_NONAME";
266 case ERRSET_NODATA:
267 return "ERRSET_NODATA";
268 case ERRSET_NOMEMORY:
269 return "ERRSET_NOMEMORY";
270 case ERRSET_INVAL:
271 return "ERRSET_INVAL";
272 case ERRSET_FAIL:
273 return "ERRSET_FAIL";
274 default:
275 return "???";
276 }
277}
278
279void
280print_rrsetinfo(struct rrsetinfo * rrset)
281{
282 printf("rri_flags=%u\n", rrset->rri_flags);
283 printf("rri_rdclass=%u\n", rrset->rri_rdclass);
284 printf("rri_rdtype=%u\n", rrset->rri_rdtype);
285 printf("rri_ttl=%u\n", rrset->rri_ttl);
286 printf("rri_nrdatas=%u\n", rrset->rri_nrdatas);
287 printf("rri_nsigs=%u\n", rrset->rri_nsigs);
288 printf("rri_name=\"%s\"\n", rrset->rri_name);
289}
290
291void
292print_errors(void)
293{
294 switch (long_err) {
295 case 0:
296 return;
297 case 1:
298 printf(" => errno %i, h_errno %i", errno, h_errno);
299 printf(", rrset_errno %i", rrset_errno);
300 printf(", gai_errno %i", gai_errno);
301 printf ("\n");
302 return;
303 default:
304 printf(" => errno %i: %s\n => h_errno %i: %s\n => rrset_errno %i: %s\n",
305 errno, errno ? strerror(errno) : "ok",
306 h_errno, h_errno ? hstrerror(h_errno) : "ok",
307 rrset_errno, rrset_errno ? rrsetstrerror(rrset_errno) : "ok");
308 printf(" => gai_errno %i: %s\n",
309 gai_errno, gai_errno ? gai_strerror(gai_errno) : "ok");
310 }
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,
320 buf, len);
321 break;
322 case AF_INET6:
323 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr,
324 buf, len);
325 break;
326 default:
327 buf[0] = '\0';
328 }
329 return (buf);
330}
331
332
333char *
334print_addr(const struct sockaddr *sa, char *buf, size_t len)
335{
336 char h[256];
337
338 print_host(sa, h, sizeof h);
339
340 switch (sa->sa_family) {
341 case AF_INET:
342 snprintf(buf, len, "%s:%i", h,
343 ntohs(((struct sockaddr_in*)(sa))->sin_port));
344 break;
345 case AF_INET6:
346 snprintf(buf, len, "[%s]:%i", h,
347 ntohs(((struct sockaddr_in6*)(sa))->sin6_port));
348 break;
349 default:
350 snprintf(buf, len, "?");
351 break;
352 }
353
354 return (buf);
355}
356
357void
358packed_init(struct packed *pack, char *data, size_t len)
359{
360 pack->data = data;
361 pack->len = len;
362 pack->offset = 0;
363 pack->err = NULL;
364}
365
366
367static ssize_t
368dname_expand(const unsigned char *data, size_t len, size_t offset,
369 size_t *newoffset, char *dst, size_t max)
370{
371 size_t n, count, end, ptr, start;
372 ssize_t res;
373
374 if (offset >= len)
375 return (-1);
376
377 res = 0;
378 end = start = offset;
379
380 for(; (n = data[offset]); ) {
381 if ((n & 0xc0) == 0xc0) {
382 if (offset + 2 > len)
383 return (-1);
384 ptr = 256 * (n & ~0xc0) + data[offset + 1];
385 if (ptr >= start)
386 return (-1);
387 if (end < offset + 2)
388 end = offset + 2;
389 offset = ptr;
390 continue;
391 }
392 if (offset + n + 1 > len)
393 return (-1);
394
395
396 /* copy n + at offset+1 */
397 if (dst != NULL && max != 0) {
398 count = (max < n + 1) ? (max) : (n + 1);
399 memmove(dst, data + offset, count);
400 dst += count;
401 max -= count;
402 }
403 res += n + 1;
404 offset += n + 1;
405 if (end < offset)
406 end = offset;
407 }
408 if (end < offset + 1)
409 end = offset + 1;
410
411 if (dst != NULL && max != 0)
412 dst[0] = 0;
413 if (newoffset)
414 *newoffset = end;
415 return (res + 1);
416}
417
418static int
419unpack_data(struct packed *p, void *data, size_t len)
420{
421 if (p->err)
422 return (-1);
423
424 if (p->len - p->offset < len) {
425 p->err = "too short";
426 return (-1);
427 }
428
429 memmove(data, p->data + p->offset, len);
430 p->offset += len;
431
432 return (0);
433}
434
435static int
436unpack_u16(struct packed *p, uint16_t *u16)
437{
438 if (unpack_data(p, u16, 2) == -1)
439 return (-1);
440
441 *u16 = ntohs(*u16);
442
443 return (0);
444}
445
446static int
447unpack_u32(struct packed *p, uint32_t *u32)
448{
449 if (unpack_data(p, u32, 4) == -1)
450 return (-1);
451
452 *u32 = ntohl(*u32);
453
454 return (0);
455}
456
457static int
458unpack_inaddr(struct packed *p, struct in_addr *a)
459{
460 return (unpack_data(p, a, 4));
461}
462
463static int
464unpack_in6addr(struct packed *p, struct in6_addr *a6)
465{
466 return (unpack_data(p, a6, 16));
467}
468
469static int
470unpack_dname(struct packed *p, char *dst, size_t max)
471{
472 ssize_t e;
473
474 if (p->err)
475 return (-1);
476
477 e = dname_expand(p->data, p->len, p->offset, &p->offset, dst, max);
478 if (e == -1) {
479 p->err = "bad domain name";
480 return (-1);
481 }
482 if (e < 0 || e > MAXDNAME) {
483 p->err = "domain name too long";
484 return (-1);
485 }
486
487 return (0);
488}
489
490int
491unpack_header(struct packed *p, struct header *h)
492{
493 if (unpack_data(p, h, HFIXEDSZ) == -1)
494 return (-1);
495
496 h->flags = ntohs(h->flags);
497 h->qdcount = ntohs(h->qdcount);
498 h->ancount = ntohs(h->ancount);
499 h->nscount = ntohs(h->nscount);
500 h->arcount = ntohs(h->arcount);
501
502 return (0);
503}
504
505int
506unpack_query(struct packed *p, struct query *q)
507{
508 unpack_dname(p, q->q_dname, sizeof(q->q_dname));
509 unpack_u16(p, &q->q_type);
510 unpack_u16(p, &q->q_class);
511
512 return (p->err) ? (-1) : (0);
513}
514
515int
516unpack_rr(struct packed *p, struct rr *rr)
517{
518 uint16_t rdlen;
519 size_t save_offset;
520
521 unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname));
522 unpack_u16(p, &rr->rr_type);
523 unpack_u16(p, &rr->rr_class);
524 unpack_u32(p, &rr->rr_ttl);
525 unpack_u16(p, &rdlen);
526
527 if (p->err)
528 return (-1);
529
530 if (p->len - p->offset < rdlen) {
531 p->err = "too short";
532 return (-1);
533 }
534
535 save_offset = p->offset;
536
537 switch(rr->rr_type) {
538
539 case T_CNAME:
540 unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname));
541 break;
542
543 case T_MX:
544 unpack_u16(p, &rr->rr.mx.preference);
545 unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange));
546 break;
547
548 case T_NS:
549 unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname));
550 break;
551
552 case T_PTR:
553 unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname));
554 break;
555
556 case T_SOA:
557 unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname));
558 unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname));
559 unpack_u32(p, &rr->rr.soa.serial);
560 unpack_u32(p, &rr->rr.soa.refresh);
561 unpack_u32(p, &rr->rr.soa.retry);
562 unpack_u32(p, &rr->rr.soa.expire);
563 unpack_u32(p, &rr->rr.soa.minimum);
564 break;
565
566 case T_A:
567 if (rr->rr_class != C_IN)
568 goto other;
569 unpack_inaddr(p, &rr->rr.in_a.addr);
570 break;
571
572 case T_AAAA:
573 if (rr->rr_class != C_IN)
574 goto other;
575 unpack_in6addr(p, &rr->rr.in_aaaa.addr6);
576 break;
577 default:
578 other:
579 rr->rr.other.rdata = p->data + p->offset;
580 rr->rr.other.rdlen = rdlen;
581 p->offset += rdlen;
582 }
583
584 if (p->err)
585 return (-1);
586
587 /* make sure that the advertised rdlen is really ok */
588 if (p->offset - save_offset != rdlen)
589 p->err = "bad dlen";
590
591 return (p->err) ? (-1) : (0);
592}
593
594int
595sockaddr_from_str(struct sockaddr *sa, int family, const char *str)
596{
597 struct in_addr ina;
598 struct in6_addr in6a;
599 struct sockaddr_in *sin;
600 struct sockaddr_in6 *sin6;
601
602 switch (family) {
603 case PF_UNSPEC:
604 if (sockaddr_from_str(sa, PF_INET, str) == 0)
605 return (0);
606 return sockaddr_from_str(sa, PF_INET6, str);
607
608 case PF_INET:
609 if (inet_pton(PF_INET, str, &ina) != 1)
610 return (-1);
611
612 sin = (struct sockaddr_in *)sa;
613 memset(sin, 0, sizeof *sin);
614 sin->sin_len = sizeof(struct sockaddr_in);
615 sin->sin_family = PF_INET;
616 sin->sin_addr.s_addr = ina.s_addr;
617 return (0);
618
619 case PF_INET6:
620 if (inet_pton(PF_INET6, str, &in6a) != 1)
621 return (-1);
622
623 sin6 = (struct sockaddr_in6 *)sa;
624 memset(sin6, 0, sizeof *sin6);
625 sin6->sin6_len = sizeof(struct sockaddr_in6);
626 sin6->sin6_family = PF_INET6;
627 sin6->sin6_addr = in6a;
628 return (0);
629
630 default:
631 break;
632 }
633
634 return (-1);
635}
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 87df4ae4a2..0000000000
--- a/src/regress/lib/libc/asr/bin/common.h
+++ /dev/null
@@ -1,136 +0,0 @@
1/* $OpenBSD: common.h,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/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*);
44
45void print_rrsetinfo(struct rrsetinfo *);
46void print_addrinfo(struct addrinfo *);
47void print_errors(void);
48void print_hostent(struct hostent *);
49void print_netent(struct netent *);
50
51int sockaddr_from_str(struct sockaddr *, int, const char *);
52int addr_from_str(char *, int *, int *, const char *);
53char* gethostarg(char *);
54
55#define QR_MASK (0x1 << 15)
56#define OPCODE_MASK (0xf << 11)
57#define AA_MASK (0x1 << 10)
58#define TC_MASK (0x1 << 9)
59#define RD_MASK (0x1 << 8)
60#define RA_MASK (0x1 << 7)
61#define Z_MASK (0x7 << 4)
62#define RCODE_MASK (0xf)
63
64#define OPCODE(v) ((v) & OPCODE_MASK)
65#define RCODE(v) ((v) & RCODE_MASK)
66
67
68struct packed {
69 char *data;
70 size_t len;
71 size_t offset;
72 const char *err;
73};
74
75struct header {
76 uint16_t id;
77 uint16_t flags;
78 uint16_t qdcount;
79 uint16_t ancount;
80 uint16_t nscount;
81 uint16_t arcount;
82};
83
84struct query {
85 char q_dname[MAXDNAME];
86 uint16_t q_type;
87 uint16_t q_class;
88};
89
90struct rr {
91 char rr_dname[MAXDNAME];
92 uint16_t rr_type;
93 uint16_t rr_class;
94 uint32_t rr_ttl;
95 union {
96 struct {
97 char cname[MAXDNAME];
98 } cname;
99 struct {
100 uint16_t preference;
101 char exchange[MAXDNAME];
102 } mx;
103 struct {
104 char nsname[MAXDNAME];
105 } ns;
106 struct {
107 char ptrname[MAXDNAME];
108 } ptr;
109 struct {
110 char mname[MAXDNAME];
111 char rname[MAXDNAME];
112 uint32_t serial;
113 uint32_t refresh;
114 uint32_t retry;
115 uint32_t expire;
116 uint32_t minimum;
117 } soa;
118 struct {
119 struct in_addr addr;
120 } in_a;
121 struct {
122 struct in6_addr addr6;
123 } in_aaaa;
124 struct {
125 uint16_t rdlen;
126 const void *rdata;
127 } other;
128 } rr;
129};
130
131void packed_init(struct packed*, char*, size_t);
132int pack_header(struct packed*, const struct header*);
133int pack_query(struct packed*, uint16_t, uint16_t, const char*);
134int unpack_header(struct packed*, struct header*);
135int unpack_query(struct packed*, struct query*);
136int 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 7b8674aea9..0000000000
--- a/src/regress/lib/libc/asr/bin/getaddrinfo.c
+++ /dev/null
@@ -1,135 +0,0 @@
1/* $OpenBSD: getaddrinfo.c,v 1.2 2013/03/28 09:36:03 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, "CFHPSef: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 'S':
66 hints.ai_flags |= AI_NUMERICSERV;
67 break;
68 case 'e':
69 long_err += 1;
70 break;
71 case 'f':
72 if (!strcmp(optarg, "inet"))
73 hints.ai_family = AF_INET;
74 else if (!strcmp(optarg, "inet6"))
75 hints.ai_family = AF_INET6;
76 else
77 usage();
78 break;
79 case 'p':
80 if (!strcmp(optarg, "udp"))
81 hints.ai_protocol = IPPROTO_UDP;
82 else if (!strcmp(optarg, "tcp"))
83 hints.ai_protocol = IPPROTO_TCP;
84 else if (!strcmp(optarg, "icmp"))
85 hints.ai_protocol = IPPROTO_ICMP;
86 else if (!strcmp(optarg, "icmpv6"))
87 hints.ai_protocol = IPPROTO_ICMPV6;
88 else
89 usage();
90 break;
91 case 's':
92 servname = optarg;
93 break;
94 case 't':
95 if (!strcmp(optarg, "stream"))
96 hints.ai_socktype = SOCK_STREAM;
97 else if (!strcmp(optarg, "dgram"))
98 hints.ai_socktype = SOCK_DGRAM;
99 else if (!strcmp(optarg, "raw"))
100 hints.ai_socktype = SOCK_RAW;
101 else
102 usage();
103 break;
104 default:
105 usage();
106 /* NOTREACHED */
107 }
108 }
109 argc -= optind;
110 argv += optind;
111
112 for(i = 0; i < argc; i++) {
113
114 if (i)
115 printf("\n");
116 printf("===> \"%s\"\n", argv[i]);
117 host = gethostarg(argv[i]);
118
119 errno = 0;
120 h_errno = 0;
121 gai_errno = 0;
122 rrset_errno = 0;
123
124 gai_errno = getaddrinfo(host, servname, &hints, &ai);
125
126 print_errors();
127 if (gai_errno == 0) {
128 for (res = ai; res; res = res->ai_next)
129 print_addrinfo(res);
130 freeaddrinfo(ai);
131 }
132 }
133
134 return (0);
135}
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 b1b3e331a7..0000000000
--- a/src/regress/lib/libc/asr/bin/gethostnamadr.c
+++ /dev/null
@@ -1,113 +0,0 @@
1/* $OpenBSD: gethostnamadr.c,v 1.2 2012/07/29 19:51:36 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, "46ae")) != -1) {
51 switch(ch) {
52 case '4':
53 family = AF_INET;
54 break;
55 case '6':
56 family = AF_INET6;
57 break;
58 case 'a':
59 aflag = 1;
60 break;
61 case 'e':
62 long_err += 1;
63 break;
64 default:
65 usage();
66 /* NOTREACHED */
67 }
68 }
69 argc -= optind;
70 argv += optind;
71
72 for(i = 0; i < argc; i++) {
73
74 if (i)
75 printf("\n");
76 printf("===> \"%s\"\n", argv[i]);
77 host = gethostarg(argv[i]);
78
79 if (aflag && addr_from_str(addr, &family, &addrlen, host) == -1)
80 errx(1, "bad address");
81
82 errno = 0;
83 h_errno = 0;
84 gai_errno = 0;
85 rrset_errno = 0;
86
87 if (aflag == 0)
88 h = gethostbyname2(host, family);
89 else
90 h = gethostbyaddr(addr, addrlen, family);
91 if (h)
92 print_hostent(h);
93 print_errors();
94 }
95
96 return (0);
97}
98
99int
100addr_from_str(char *addr, int *family, int *len, const char *src)
101{
102 if (inet_pton(AF_INET6, src, addr) == 1) {
103 *family = AF_INET6;
104 *len = 16;
105 return (0);
106 }
107 if (inet_pton(AF_INET, src, addr) == 1) {
108 *family = AF_INET;
109 *len = 4;
110 return (0);
111 }
112 return (-1);
113}
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 8702937a47..0000000000
--- a/src/regress/lib/libc/asr/bin/getnameinfo.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/* $OpenBSD: getnameinfo.c,v 1.1.1.1 2012/07/13 17:49:54 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, "DFHNSaep:")) != -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 'S':
63 flags |= NI_NUMERICSERV;
64 break;
65 case 'e':
66 long_err += 1;
67 break;
68 case 'p':
69 port = strtonum(optarg, 0, 65535, &e);
70 if (e)
71 usage();
72 break;
73 default:
74 usage();
75 /* NOTREACHED */
76 }
77 }
78 argc -= optind;
79 argv += optind;
80
81 for(i = 0; i < argc; i++) {
82
83 if (i)
84 printf("\n");
85 printf("===> \"%s\"\n", argv[i]);
86
87 if (sockaddr_from_str(sa, AF_UNSPEC, argv[i]) == -1) {
88 printf(" => invalid address\n");
89 continue;
90 }
91
92 if (sa->sa_family == PF_INET)
93 ((struct sockaddr_in *)sa)->sin_port = htons(port);
94 else if (sa->sa_family == PF_INET6)
95 ((struct sockaddr_in6 *)sa)->sin6_port = htons(port);
96
97 errno = 0;
98 h_errno = 0;
99 gai_errno = 0;
100 rrset_errno = 0;
101
102 gai_errno = getnameinfo(sa, sa->sa_len, host, sizeof host, serv,
103 sizeof serv, flags);
104
105 if (gai_errno == 0)
106 printf(" %s:%s\n", host, serv);
107 print_errors();
108
109 }
110
111 return (0);
112}
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 4b7414264b..0000000000
--- a/src/regress/lib/libc/asr/bin/getnetnamadr.c
+++ /dev/null
@@ -1,85 +0,0 @@
1/* $OpenBSD: getnetnamadr.c,v 1.1.1.1 2012/07/13 17:49:54 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, "en")) != -1) {
48 switch(ch) {
49 case 'e':
50 long_err += 1;
51 break;
52 case 'n':
53 nflag = 1;
54 break;
55 default:
56 usage();
57 /* NOTREACHED */
58 }
59 }
60 argc -= optind;
61 argv += optind;
62
63 for(i = 0; i < argc; i++) {
64
65 if (i)
66 printf("\n");
67 printf("===> \"%s\"\n", argv[i]);
68 host = gethostarg(argv[i]);
69
70 errno = 0;
71 h_errno = 0;
72 gai_errno = 0;
73 rrset_errno = 0;
74
75 if (nflag)
76 n = getnetbyname(host);
77 else
78 n = getnetbyaddr(inet_network(host), AF_INET);
79 if (n)
80 print_netent(n);
81 print_errors();
82 }
83
84 return (0);
85}
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 4a5aa57209..0000000000
--- a/src/regress/lib/libc/asr/bin/getrrsetbyname.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/* $OpenBSD: getrrsetbyname.c,v 1.1.1.1 2012/07/13 17:49:54 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, "et:")) != -1) {
52 switch(ch) {
53 case 'e':
54 long_err += 1;
55 break;
56 case 't':
57 if ((type = strtotype(optarg)) == 0)
58 usage();
59 break;
60 default:
61 usage();
62 /* NOTREACHED */
63 }
64 }
65 argc -= optind;
66 argv += optind;
67
68 for (i = 0; i < argc; i++) {
69
70 if (i)
71 printf("\n");
72 printf("===> \"%s\"\n", argv[i]);
73 host = gethostarg(argv[i]);
74
75 errno = 0;
76 h_errno = 0;
77 gai_errno = 0;
78 rrset_errno = 0;
79
80 rrset_errno = getrrsetbyname(host, C_IN, type, 0, &rrset);
81
82 if (rrset_errno == 0)
83 print_rrsetinfo(rrset);
84 print_errors();
85 }
86
87 return (0);
88}
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 a52023c5c0..0000000000
--- a/src/regress/lib/libc/asr/bin/res_mkquery.c
+++ /dev/null
@@ -1,319 +0,0 @@
1/* $OpenBSD: res_mkquery.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
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, "et:")) != -1) {
63 switch(ch) {
64 case 'e':
65 long_err += 1;
66 break;
67 case 't':
68 if ((type = strtotype(optarg)) == 0)
69 usage();
70 break;
71 default:
72 usage();
73 /* NOTREACHED */
74 }
75 }
76 argc -= optind;
77 argv += optind;
78
79 for (i = 0; i < argc; i++) {
80
81 if (i)
82 printf("\n");
83
84 printf("===> \"%s\"\n", argv[i]);
85 host = gethostarg(argv[i]);
86
87 errno = 0;
88 h_errno = 0;
89 gai_errno = 0;
90 rrset_errno = 0;
91
92 r = res_mkquery(QUERY, host, C_IN, type, NULL, 0, NULL, buf, sizeof(buf));
93 if (r != -1) {
94 dump_packet(buf, r);
95 printf(";; MSG SIZE %i\n", r);
96 }
97 print_errors();
98 }
99
100 return (0);
101}
102
103#define OPCODE_SHIFT 11
104#define Z_SHIFT 4
105
106static char*
107print_header(struct header *h, char *buf, size_t max)
108{
109 snprintf(buf, max,
110 "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i",
111 (h->flags & QR_MASK) ? "QR":" ",
112 (int)(OPCODE(h->flags) >> OPCODE_SHIFT),
113 (h->flags & AA_MASK) ? "AA":" ",
114 (h->flags & TC_MASK) ? "TC":" ",
115 (h->flags & RD_MASK) ? "RD":" ",
116 (h->flags & RA_MASK) ? "RA":" ",
117 ((h->flags & Z_MASK) >> Z_SHIFT),
118 rcodetostr(RCODE(h->flags)),
119 h->qdcount, h->ancount, h->nscount, h->arcount);
120
121 return buf;
122}
123
124static void
125dump_packet(const void *data, size_t len)
126{
127 char buf[1024];
128 struct packed p;
129 struct header h;
130 struct query q;
131 struct rr rr;
132 int i, an, ns, ar, n;
133
134 packed_init(&p, (char *)data, len);
135
136 if (unpack_header(&p, &h) == -1) {
137 printf(";; BAD PACKET: %s\n", p.err);
138 return;
139 }
140
141 printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf));
142
143 if (h.qdcount)
144 printf(";; QUERY SECTION:\n");
145 for (i = 0; i < h.qdcount; i++) {
146 if (unpack_query(&p, &q) == -1)
147 goto error;
148 printf("%s\n", print_query(&q, buf, sizeof buf));
149 }
150
151 an = 0;
152 ns = an + h.ancount;
153 ar = ns + h.nscount;
154 n = ar + h.arcount;
155
156 for (i = 0; i < n; i++) {
157 if (i == an)
158 printf("\n;; ANSWER SECTION:\n");
159 if (i == ns)
160 printf("\n;; AUTHORITY SECTION:\n");
161 if (i == ar)
162 printf("\n;; ADDITIONAL SECTION:\n");
163
164 if (unpack_rr(&p, &rr) == -1)
165 goto error;
166 printf("%s\n", print_rr(&rr, buf, sizeof buf));
167 }
168
169 if (p.offset != len)
170 printf(";; REMAINING GARBAGE %zu\n", len - p.offset);
171
172 error:
173 if (p.err)
174 printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len,
175 p.err);
176}
177
178static const char *
179inet6_ntoa(struct in6_addr a)
180{
181 static char buf[256];
182 struct sockaddr_in6 si;
183
184 si.sin6_len = sizeof(si);
185 si.sin6_family = PF_INET6;
186 si.sin6_addr = a;
187
188 return print_host((struct sockaddr*)&si, buf, sizeof buf);
189}
190
191static char*
192print_rr(struct rr *rr, char *buf, size_t max)
193{
194 char *res;
195 char tmp[256];
196 char tmp2[256];
197 int r;
198
199 res = buf;
200
201 r = snprintf(buf, max, "%s %u %s %s ",
202 print_dname(rr->rr_dname, tmp, sizeof tmp),
203 rr->rr_ttl,
204 classtostr(rr->rr_class),
205 typetostr(rr->rr_type));
206 if (r == -1) {
207 buf[0] = '\0';
208 return buf;
209 }
210
211 if ((size_t)r >= max)
212 return buf;
213
214 max -= r;
215 buf += r;
216
217 switch(rr->rr_type) {
218 case T_CNAME:
219 print_dname(rr->rr.cname.cname, buf, max);
220 break;
221 case T_MX:
222 snprintf(buf, max, "%"PRIu32" %s",
223 rr->rr.mx.preference,
224 print_dname(rr->rr.mx.exchange, tmp, sizeof tmp));
225 break;
226 case T_NS:
227 print_dname(rr->rr.ns.nsname, buf, max);
228 break;
229 case T_PTR:
230 print_dname(rr->rr.ptr.ptrname, buf, max);
231 break;
232 case T_SOA:
233 snprintf(buf, max,
234 "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32,
235 print_dname(rr->rr.soa.rname, tmp, sizeof tmp),
236 print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2),
237 rr->rr.soa.serial,
238 rr->rr.soa.refresh,
239 rr->rr.soa.retry,
240 rr->rr.soa.expire,
241 rr->rr.soa.minimum);
242 break;
243 case T_A:
244 if (rr->rr_class != C_IN)
245 goto other;
246 snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr));
247 break;
248 case T_AAAA:
249 if (rr->rr_class != C_IN)
250 goto other;
251 snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6));
252 break;
253 default:
254 other:
255 snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen);
256 break;
257 }
258
259 return (res);
260}
261
262static char*
263print_query(struct query *q, char *buf, size_t max)
264{
265 char b[256];
266
267 snprintf(buf, max, "%s %s %s",
268 print_dname(q->q_dname, b, sizeof b),
269 classtostr(q->q_class), typetostr(q->q_type));
270
271 return (buf);
272}
273
274
275static char *
276print_host(const struct sockaddr *sa, char *buf, size_t len)
277{
278 switch (sa->sa_family) {
279 case AF_INET:
280 inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len);
281 break;
282 case AF_INET6:
283 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len);
284 break;
285 default:
286 buf[0] = '\0';
287 }
288 return (buf);
289}
290
291static char*
292print_dname(const char *_dname, char *buf, size_t max)
293{
294 const unsigned char *dname = _dname;
295 char *res;
296 size_t left, n, count;
297
298 if (_dname[0] == 0) {
299 strlcpy(buf, ".", max);
300 return buf;
301 }
302
303 res = buf;
304 left = max - 1;
305 for (n = 0; dname[0] && left; n += dname[0]) {
306 count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
307 memmove(buf, dname + 1, count);
308 dname += dname[0] + 1;
309 left -= count;
310 buf += count;
311 if (left) {
312 left -= 1;
313 *buf++ = '.';
314 }
315 }
316 buf[0] = 0;
317
318 return (res);
319}
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 3565eeebed..0000000000
--- a/src/regress/lib/libc/asr/bin/res_query.c
+++ /dev/null
@@ -1,355 +0,0 @@
1/* $OpenBSD: res_query.c,v 1.2 2017/03/09 07:56:38 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#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, "deqt:")) != -1) {
76 switch(ch) {
77 case 'd':
78 dflag = 1;
79 break;
80 case 'e':
81 long_err += 1;
82 break;
83 case 'q':
84 qflag = 1;
85 break;
86 case 't':
87 if ((type = strtotype(optarg)) == 0)
88 usage();
89 break;
90 default:
91 usage();
92 /* NOTREACHED */
93 }
94 }
95 argc -= optind;
96 argv += optind;
97
98 for (i = 0; i < argc; i++) {
99
100 if (i)
101 printf("\n");
102
103 printf("===> \"%s\"\n", argv[i]);
104 host = gethostarg(argv[i]);
105
106 errno = 0;
107 h_errno = 0;
108 gai_errno = 0;
109 rrset_errno = 0;
110
111 if (gettimeofday(&start, NULL) != 0)
112 err(1, "gettimeofday");
113
114 if (qflag)
115 r = res_query(host, C_IN, type, buf, sizeof(buf));
116 else
117 r = res_search(host, C_IN, type, buf, sizeof(buf));
118
119 if (gettimeofday(&end, NULL) != 0)
120 err(1, "gettimeofday");
121
122 if (r != -1) {
123 dump_packet(buf, r);
124 printf("\n");
125 if (dflag) {
126 printf(";; Query time: %d msec\n",
127 msec(start, end));
128 when = time(NULL);
129 printf(";; WHEN: %s", ctime(&when));
130 }
131 printf(";; MSG SIZE rcvd: %i\n", r);
132 }
133 print_errors();
134 }
135
136 return (0);
137}
138
139#define OPCODE_SHIFT 11
140#define Z_SHIFT 4
141
142static char*
143print_header(struct header *h, char *buf, size_t max)
144{
145 snprintf(buf, max,
146 "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i",
147 (h->flags & QR_MASK) ? "QR":" ",
148 (int)(OPCODE(h->flags) >> OPCODE_SHIFT),
149 (h->flags & AA_MASK) ? "AA":" ",
150 (h->flags & TC_MASK) ? "TC":" ",
151 (h->flags & RD_MASK) ? "RD":" ",
152 (h->flags & RA_MASK) ? "RA":" ",
153 ((h->flags & Z_MASK) >> Z_SHIFT),
154 rcodetostr(RCODE(h->flags)),
155 h->qdcount, h->ancount, h->nscount, h->arcount);
156
157 return buf;
158}
159
160static void
161dump_packet(const void *data, size_t len)
162{
163 char buf[1024];
164 struct packed p;
165 struct header h;
166 struct query q;
167 struct rr rr;
168 int i, an, ns, ar, n;
169
170 packed_init(&p, (char *)data, len);
171
172 if (unpack_header(&p, &h) == -1) {
173 printf(";; BAD PACKET: %s\n", p.err);
174 return;
175 }
176
177 printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf));
178
179 if (h.qdcount)
180 printf(";; QUERY SECTION:\n");
181 for (i = 0; i < h.qdcount; i++) {
182 if (unpack_query(&p, &q) == -1)
183 goto error;
184 printf("%s\n", print_query(&q, buf, sizeof buf));
185 }
186
187 an = 0;
188 ns = an + h.ancount;
189 ar = ns + h.nscount;
190 n = ar + h.arcount;
191
192 for (i = 0; i < n; i++) {
193 if (i == an)
194 printf("\n;; ANSWER SECTION:\n");
195 if (i == ns)
196 printf("\n;; AUTHORITY SECTION:\n");
197 if (i == ar)
198 printf("\n;; ADDITIONAL SECTION:\n");
199
200 if (unpack_rr(&p, &rr) == -1)
201 goto error;
202 printf("%s\n", print_rr(&rr, buf, sizeof buf));
203 }
204
205 if (p.offset != len)
206 printf(";; REMAINING GARBAGE %zu\n", len - p.offset);
207
208 error:
209 if (p.err)
210 printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len,
211 p.err);
212}
213
214static const char *
215inet6_ntoa(struct in6_addr a)
216{
217 static char buf[256];
218 struct sockaddr_in6 si;
219
220 si.sin6_len = sizeof(si);
221 si.sin6_family = PF_INET6;
222 si.sin6_addr = a;
223
224 return print_host((struct sockaddr*)&si, buf, sizeof buf);
225}
226
227static char*
228print_rr(struct rr *rr, char *buf, size_t max)
229{
230 char *res;
231 char tmp[256];
232 char tmp2[256];
233 int r;
234
235 res = buf;
236
237 r = snprintf(buf, max, "%s %u %s %s ",
238 print_dname(rr->rr_dname, tmp, sizeof tmp),
239 rr->rr_ttl,
240 classtostr(rr->rr_class),
241 typetostr(rr->rr_type));
242 if (r == -1) {
243 buf[0] = '\0';
244 return buf;
245 }
246
247 if ((size_t)r >= max)
248 return buf;
249
250 max -= r;
251 buf += r;
252
253 switch(rr->rr_type) {
254 case T_CNAME:
255 print_dname(rr->rr.cname.cname, buf, max);
256 break;
257 case T_MX:
258 snprintf(buf, max, "%"PRIu32" %s",
259 rr->rr.mx.preference,
260 print_dname(rr->rr.mx.exchange, tmp, sizeof tmp));
261 break;
262 case T_NS:
263 print_dname(rr->rr.ns.nsname, buf, max);
264 break;
265 case T_PTR:
266 print_dname(rr->rr.ptr.ptrname, buf, max);
267 break;
268 case T_SOA:
269 snprintf(buf, max,
270 "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32,
271 print_dname(rr->rr.soa.rname, tmp, sizeof tmp),
272 print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2),
273 rr->rr.soa.serial,
274 rr->rr.soa.refresh,
275 rr->rr.soa.retry,
276 rr->rr.soa.expire,
277 rr->rr.soa.minimum);
278 break;
279 case T_A:
280 if (rr->rr_class != C_IN)
281 goto other;
282 snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr));
283 break;
284 case T_AAAA:
285 if (rr->rr_class != C_IN)
286 goto other;
287 snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6));
288 break;
289 default:
290 other:
291 snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen);
292 break;
293 }
294
295 return (res);
296}
297
298static char*
299print_query(struct query *q, char *buf, size_t max)
300{
301 char b[256];
302
303 snprintf(buf, max, "%s %s %s",
304 print_dname(q->q_dname, b, sizeof b),
305 classtostr(q->q_class), typetostr(q->q_type));
306
307 return (buf);
308}
309
310
311static char *
312print_host(const struct sockaddr *sa, char *buf, size_t len)
313{
314 switch (sa->sa_family) {
315 case AF_INET:
316 inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len);
317 break;
318 case AF_INET6:
319 inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len);
320 break;
321 default:
322 buf[0] = '\0';
323 }
324 return (buf);
325}
326
327static char*
328print_dname(const char *_dname, char *buf, size_t max)
329{
330 const unsigned char *dname = _dname;
331 char *res;
332 size_t left, n, count;
333
334 if (_dname[0] == 0) {
335 strlcpy(buf, ".", max);
336 return buf;
337 }
338
339 res = buf;
340 left = max - 1;
341 for (n = 0; dname[0] && left; n += dname[0]) {
342 count = (dname[0] < (left - 1)) ? dname[0] : (left - 1);
343 memmove(buf, dname + 1, count);
344 dname += dname[0] + 1;
345 left -= count;
346 buf += count;
347 if (left) {
348 left -= 1;
349 *buf++ = '.';
350 }
351 }
352 buf[0] = 0;
353
354 return (res);
355}
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>