diff options
| author | eric <> | 2012-07-13 17:49:54 +0000 | 
|---|---|---|
| committer | eric <> | 2012-07-13 17:49:54 +0000 | 
| commit | adf6731f6e1d04718aee00cb93435143046aee9a (patch) | |
| tree | c9d57f5a2812d08f0e504c69deb162dc89ae78a9 | |
| parent | 20333a35e7159469107dfd2bb6f664bbd518c4d5 (diff) | |
| download | openbsd-adf6731f6e1d04718aee00cb93435143046aee9a.tar.gz openbsd-adf6731f6e1d04718aee00cb93435143046aee9a.tar.bz2 openbsd-adf6731f6e1d04718aee00cb93435143046aee9a.zip | |
import regression suite for asr
Diffstat (limited to '')
23 files changed, 2464 insertions, 0 deletions
| diff --git a/src/regress/lib/libc/asr/Makefile b/src/regress/lib/libc/asr/Makefile new file mode 100644 index 0000000000..f110cbe25e --- /dev/null +++ b/src/regress/lib/libc/asr/Makefile | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ | ||
| 2 | |||
| 3 | # | ||
| 4 | # Note on building and running the regress tests: | ||
| 5 | # | ||
| 6 | # The regress suite builds two sets of static executables: one linked | ||
| 7 | # against the current libc, and one linked against a libc with the resolver | ||
| 8 | # replaced. The idea is to compare the output of all programs in both cases. | ||
| 9 | # | ||
| 10 | # So before building the regression test programs, you need to have the two | ||
| 11 | # libc.a ready. By default, it is assumed that the asr-enabled libc was just | ||
| 12 | # built from src but not installed, so the current libc.a is expected to be | ||
| 13 | # found in /usr/lib, and the new one in /usr/obj/lib/libc. If your setting | ||
| 14 | # is different, just set LIBCDIRSTD and LIBCDIRASR accordingly. | ||
| 15 | # | ||
| 16 | # When done, run "make && make install". This builds and installs the two sets | ||
| 17 | # of programs in REGRESSDIR. They will run chrooted there to allow testing with | ||
| 18 | # various /etc environment without messing up the local machine config files. | ||
| 19 | # | ||
| 20 | # When you are sure everything is in place, run "make regress". This will | ||
| 21 | # create two files: $REGRESSDIR/output.log with the output of all run tests, | ||
| 22 | # and $REGRESSDIR/regress.log with the diffs for those that "failed". | ||
| 23 | # | ||
| 24 | # Note that "install" and "regress" targets need to be run as root. | ||
| 25 | # | ||
| 26 | |||
| 27 | LIBCDIRSTD?= /usr/lib | ||
| 28 | LIBCDIRASR?= /usr/obj/lib/libc | ||
| 29 | |||
| 30 | REGRESSDIR?= /tmp/regress | ||
| 31 | |||
| 32 | all: build | ||
| 33 | |||
| 34 | build: | ||
| 35 | cd bin && EXT=.asr LDFLAGS=-L${LIBCDIRASR} make | ||
| 36 | cd bin && EXT=.std LDFLAGS=-L${LIBCDIRSTD} make | ||
| 37 | |||
| 38 | clean: | ||
| 39 | cd bin && EXT=.std make clean | ||
| 40 | cd bin && EXT=.asr make clean | ||
| 41 | |||
| 42 | install: | ||
| 43 | mkdir -p ${REGRESSDIR}/etc | ||
| 44 | mkdir -p ${REGRESSDIR}/bin | ||
| 45 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=.std make install | ||
| 46 | cd bin && BINDIR=${REGRESSDIR}/bin EXT=.asr make install | ||
| 47 | |||
| 48 | uninstall: | ||
| 49 | rm -rf ${REGRESSDIR} | ||
| 50 | |||
| 51 | regress: | ||
| 52 | RUNDIR=${REGRESSDIR} sh ${.CURDIR}/regress.sh | ||
| diff --git a/src/regress/lib/libc/asr/bin/Makefile b/src/regress/lib/libc/asr/bin/Makefile new file mode 100644 index 0000000000..1f986a8e69 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | SUBDIR= res_mkquery | ||
| 2 | SUBDIR+= res_query | ||
| 3 | SUBDIR+= gethostnamadr | ||
| 4 | SUBDIR+= getnetnamadr | ||
| 5 | SUBDIR+= getrrsetbyname | ||
| 6 | SUBDIR+= getnameinfo | ||
| 7 | SUBDIR+= getaddrinfo | ||
| 8 | SUBDIR+= 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 new file mode 100644 index 0000000000..9a03163906 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/Makefile.inc | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ | ||
| 2 | |||
| 3 | NOMAN= noman | ||
| 4 | |||
| 5 | SRCS+= common.c | ||
| 6 | CFLAGS+= -Wall -Wstrict-prototypes -Werror -Wundef -g | ||
| 7 | LDFLAGS+= -static | ||
| 8 | PROG:= ${PROG}${EXT} | ||
| diff --git a/src/regress/lib/libc/asr/bin/common.c b/src/regress/lib/libc/asr/bin/common.c new file mode 100644 index 0000000000..4402d08373 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/common.c | |||
| @@ -0,0 +1,633 @@ | |||
| 1 | /* $OpenBSD: common.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/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 | |||
| 33 | int long_err; | ||
| 34 | int gai_errno; | ||
| 35 | int rrset_errno; | ||
| 36 | |||
| 37 | |||
| 38 | char * | ||
| 39 | gethostarg(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 | |||
| 50 | const char *rrsetstrerror(int); | ||
| 51 | char * print_addr(const struct sockaddr *, char *, size_t); | ||
| 52 | |||
| 53 | struct kv { int code; const char *name; }; | ||
| 54 | |||
| 55 | struct kv kv_family[] = { | ||
| 56 | { AF_UNIX, "unix" }, | ||
| 57 | { AF_INET, "inet" }, | ||
| 58 | { AF_INET6, "inet6" }, | ||
| 59 | { AF_IMPLINK, "implink" }, | ||
| 60 | { AF_BLUETOOTH, "bluetooth" }, | ||
| 61 | { 0, NULL, } | ||
| 62 | }; | ||
| 63 | struct kv kv_socktype[] = { | ||
| 64 | { SOCK_STREAM, "stream" }, | ||
| 65 | { SOCK_DGRAM, "dgram" }, | ||
| 66 | { SOCK_RAW, "raw" }, | ||
| 67 | { 0, NULL, } | ||
| 68 | }; | ||
| 69 | struct kv kv_protocol[] = { | ||
| 70 | { IPPROTO_UDP, "udp" }, | ||
| 71 | { IPPROTO_TCP, "tcp" }, | ||
| 72 | { 0, NULL, } | ||
| 73 | }; | ||
| 74 | |||
| 75 | static const char * | ||
| 76 | kv_lookup_name(struct kv *kv, int code) | ||
| 77 | { | ||
| 78 | while (kv->name) { | ||
| 79 | if (kv->code == code) | ||
| 80 | return (kv->name); | ||
| 81 | kv++; | ||
| 82 | } | ||
| 83 | return "???"; | ||
| 84 | } | ||
| 85 | |||
| 86 | struct keyval { | ||
| 87 | const char *key; | ||
| 88 | uint16_t value; | ||
| 89 | }; | ||
| 90 | |||
| 91 | static struct keyval kv_class[] = { | ||
| 92 | { "IN", C_IN }, | ||
| 93 | { "CHAOS", C_CHAOS }, | ||
| 94 | { "HS", C_HS }, | ||
| 95 | { "ANY", C_ANY }, | ||
| 96 | { NULL, 0 }, | ||
| 97 | }; | ||
| 98 | |||
| 99 | static struct keyval kv_type[] = { | ||
| 100 | { "A", T_A }, | ||
| 101 | { "NS", T_NS }, | ||
| 102 | { "MD", T_MD }, | ||
| 103 | { "MF", T_MF }, | ||
| 104 | { "CNAME", T_CNAME }, | ||
| 105 | { "SOA", T_SOA }, | ||
| 106 | { "MB", T_MB }, | ||
| 107 | { "MG", T_MG }, | ||
| 108 | { "MR", T_MR }, | ||
| 109 | { "NULL", T_NULL }, | ||
| 110 | { "WKS", T_WKS }, | ||
| 111 | { "PTR", T_PTR }, | ||
| 112 | { "HINFO", T_HINFO }, | ||
| 113 | { "MINFO", T_MINFO }, | ||
| 114 | { "MX", T_MX }, | ||
| 115 | { "TXT", T_TXT }, | ||
| 116 | |||
| 117 | { "AAAA", T_AAAA }, | ||
| 118 | |||
| 119 | { "AXFR", T_AXFR }, | ||
| 120 | { "MAILB", T_MAILB }, | ||
| 121 | { "MAILA", T_MAILA }, | ||
| 122 | { "ANY", T_ANY }, | ||
| 123 | { NULL, 0 }, | ||
| 124 | }; | ||
| 125 | |||
| 126 | static struct keyval kv_rcode[] = { | ||
| 127 | { "NOERROR", NOERROR }, | ||
| 128 | { "FORMERR", FORMERR }, | ||
| 129 | { "SERVFAIL", SERVFAIL }, | ||
| 130 | { "NXDOMAIN", NXDOMAIN }, | ||
| 131 | { "NOTIMP", NOTIMP }, | ||
| 132 | { "REFUSED", REFUSED }, | ||
| 133 | { NULL, 0 }, | ||
| 134 | }; | ||
| 135 | |||
| 136 | |||
| 137 | const char * | ||
| 138 | rcodetostr(uint16_t v) | ||
| 139 | { | ||
| 140 | static char buf[16]; | ||
| 141 | size_t i; | ||
| 142 | |||
| 143 | for(i = 0; kv_rcode[i].key; i++) | ||
| 144 | if (kv_rcode[i].value == v) | ||
| 145 | return (kv_rcode[i].key); | ||
| 146 | |||
| 147 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 148 | |||
| 149 | return (buf); | ||
| 150 | } | ||
| 151 | |||
| 152 | const char * | ||
| 153 | typetostr(uint16_t v) | ||
| 154 | { | ||
| 155 | static char buf[16]; | ||
| 156 | size_t i; | ||
| 157 | |||
| 158 | for(i = 0; kv_type[i].key; i++) | ||
| 159 | if (kv_type[i].value == v) | ||
| 160 | return (kv_type[i].key); | ||
| 161 | |||
| 162 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 163 | |||
| 164 | return (buf); | ||
| 165 | } | ||
| 166 | |||
| 167 | const char * | ||
| 168 | classtostr(uint16_t v) | ||
| 169 | { | ||
| 170 | static char buf[16]; | ||
| 171 | size_t i; | ||
| 172 | |||
| 173 | for(i = 0; kv_class[i].key; i++) | ||
| 174 | if (kv_class[i].value == v) | ||
| 175 | return (kv_class[i].key); | ||
| 176 | |||
| 177 | snprintf(buf, sizeof buf, "%"PRIu16"?", v); | ||
| 178 | |||
| 179 | return (buf); | ||
| 180 | } | ||
| 181 | |||
| 182 | uint16_t | ||
| 183 | strtotype(const char *name) | ||
| 184 | { | ||
| 185 | size_t i; | ||
| 186 | |||
| 187 | for(i = 0; kv_type[i].key; i++) | ||
| 188 | if (!strcmp(kv_type[i].key, name)) | ||
| 189 | return (kv_type[i].value); | ||
| 190 | |||
| 191 | return (0); | ||
| 192 | } | ||
| 193 | |||
| 194 | uint16_t | ||
| 195 | strtoclass(const char *name) | ||
| 196 | { | ||
| 197 | size_t i; | ||
| 198 | |||
| 199 | for(i = 0; kv_class[i].key; i++) | ||
| 200 | if (!strcmp(kv_class[i].key, name)) | ||
| 201 | return (kv_class[i].value); | ||
| 202 | |||
| 203 | return (0); | ||
| 204 | } | ||
| 205 | |||
| 206 | void | ||
| 207 | print_hostent(struct hostent *e) | ||
| 208 | { | ||
| 209 | char buf[256], **c; | ||
| 210 | |||
| 211 | printf("name = \"%s\"\n", e->h_name); | ||
| 212 | printf("aliases ="); | ||
| 213 | for(c = e->h_aliases; *c; c++) | ||
| 214 | printf(" \"%s\"", *c); | ||
| 215 | printf("\n"); | ||
| 216 | printf("addrtype = %i\n", e->h_addrtype); | ||
| 217 | printf("addrlength = %i\n", e->h_length); | ||
| 218 | printf("addr_list ="); | ||
| 219 | for(c = e->h_addr_list; *c; c++) { | ||
| 220 | printf(" %s", inet_ntop(e->h_addrtype, *c, buf, sizeof buf)); | ||
| 221 | } | ||
| 222 | printf("\n"); | ||
| 223 | } | ||
| 224 | |||
| 225 | void | ||
| 226 | print_netent(struct netent *e) | ||
| 227 | { | ||
| 228 | char buf[256], **c; | ||
| 229 | uint32_t addr; | ||
| 230 | |||
| 231 | /* network number are given in host order */ | ||
| 232 | addr = htonl(e->n_net); | ||
| 233 | |||
| 234 | printf("name = \"%s\"\n", e->n_name); | ||
| 235 | printf("aliases ="); | ||
| 236 | for (c = e->n_aliases; *c; c++) | ||
| 237 | printf(" \"%s\"", *c); | ||
| 238 | printf("\n"); | ||
| 239 | printf("addrtype = %i\n", e->n_addrtype); | ||
| 240 | printf("net = %s\n", inet_ntop(e->n_addrtype, &addr, buf, sizeof buf)); | ||
| 241 | } | ||
| 242 | |||
| 243 | void | ||
| 244 | print_addrinfo(struct addrinfo *ai) | ||
| 245 | { | ||
| 246 | char buf[256]; | ||
| 247 | |||
| 248 | printf("family=%s socktype=%s protocol=%s addr=%s canonname=%s\n", | ||
| 249 | kv_lookup_name(kv_family, ai->ai_family), | ||
| 250 | kv_lookup_name(kv_socktype, ai->ai_socktype), | ||
| 251 | kv_lookup_name(kv_protocol, ai->ai_protocol), | ||
| 252 | print_addr(ai->ai_addr, buf, sizeof buf), | ||
| 253 | ai->ai_canonname); | ||
| 254 | } | ||
| 255 | |||
| 256 | const char * | ||
| 257 | rrsetstrerror(int e) | ||
| 258 | { | ||
| 259 | switch (e) { | ||
| 260 | case 0: | ||
| 261 | return "OK"; | ||
| 262 | case ERRSET_NONAME: | ||
| 263 | return "ERRSET_NONAME"; | ||
| 264 | case ERRSET_NODATA: | ||
| 265 | return "ERRSET_NODATA"; | ||
| 266 | case ERRSET_NOMEMORY: | ||
| 267 | return "ERRSET_NOMEMORY"; | ||
| 268 | case ERRSET_INVAL: | ||
| 269 | return "ERRSET_INVAL"; | ||
| 270 | case ERRSET_FAIL: | ||
| 271 | return "ERRSET_FAIL"; | ||
| 272 | default: | ||
| 273 | return "???"; | ||
| 274 | } | ||
| 275 | } | ||
| 276 | |||
| 277 | void | ||
| 278 | print_rrsetinfo(struct rrsetinfo * rrset) | ||
| 279 | { | ||
| 280 | printf("rri_flags=%u\n", rrset->rri_flags); | ||
| 281 | printf("rri_rdclass=%u\n", rrset->rri_rdclass); | ||
| 282 | printf("rri_rdtype=%u\n", rrset->rri_rdtype); | ||
| 283 | printf("rri_ttl=%u\n", rrset->rri_ttl); | ||
| 284 | printf("rri_nrdatas=%u\n", rrset->rri_nrdatas); | ||
| 285 | printf("rri_nsigs=%u\n", rrset->rri_nsigs); | ||
| 286 | printf("rri_name=\"%s\"\n", rrset->rri_name); | ||
| 287 | } | ||
| 288 | |||
| 289 | void | ||
| 290 | print_errors(void) | ||
| 291 | { | ||
| 292 | switch (long_err) { | ||
| 293 | case 0: | ||
| 294 | return; | ||
| 295 | case 1: | ||
| 296 | printf(" => errno %i, h_errno %i", errno, h_errno); | ||
| 297 | printf(", rrset_errno %i", rrset_errno); | ||
| 298 | printf(", gai_errno %i", gai_errno); | ||
| 299 | printf ("\n"); | ||
| 300 | return; | ||
| 301 | default: | ||
| 302 | printf(" => errno %i: %s\n => h_errno %i: %s\n => rrset_errno %i: %s\n", | ||
| 303 | errno, errno ? strerror(errno) : "ok", | ||
| 304 | h_errno, h_errno ? hstrerror(h_errno) : "ok", | ||
| 305 | rrset_errno, rrset_errno ? rrsetstrerror(rrset_errno) : "ok"); | ||
| 306 | printf(" => gai_errno %i: %s\n", | ||
| 307 | gai_errno, gai_errno ? gai_strerror(gai_errno) : "ok"); | ||
| 308 | } | ||
| 309 | } | ||
| 310 | |||
| 311 | |||
| 312 | static char * | ||
| 313 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
| 314 | { | ||
| 315 | switch (sa->sa_family) { | ||
| 316 | case AF_INET: | ||
| 317 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, | ||
| 318 | buf, len); | ||
| 319 | break; | ||
| 320 | case AF_INET6: | ||
| 321 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, | ||
| 322 | buf, len); | ||
| 323 | break; | ||
| 324 | default: | ||
| 325 | buf[0] = '\0'; | ||
| 326 | } | ||
| 327 | return (buf); | ||
| 328 | } | ||
| 329 | |||
| 330 | |||
| 331 | char * | ||
| 332 | print_addr(const struct sockaddr *sa, char *buf, size_t len) | ||
| 333 | { | ||
| 334 | char h[256]; | ||
| 335 | |||
| 336 | print_host(sa, h, sizeof h); | ||
| 337 | |||
| 338 | switch (sa->sa_family) { | ||
| 339 | case AF_INET: | ||
| 340 | snprintf(buf, len, "%s:%i", h, | ||
| 341 | ntohs(((struct sockaddr_in*)(sa))->sin_port)); | ||
| 342 | break; | ||
| 343 | case AF_INET6: | ||
| 344 | snprintf(buf, len, "[%s]:%i", h, | ||
| 345 | ntohs(((struct sockaddr_in6*)(sa))->sin6_port)); | ||
| 346 | break; | ||
| 347 | default: | ||
| 348 | snprintf(buf, len, "?"); | ||
| 349 | break; | ||
| 350 | } | ||
| 351 | |||
| 352 | return (buf); | ||
| 353 | } | ||
| 354 | |||
| 355 | void | ||
| 356 | packed_init(struct packed *pack, char *data, size_t len) | ||
| 357 | { | ||
| 358 | pack->data = data; | ||
| 359 | pack->len = len; | ||
| 360 | pack->offset = 0; | ||
| 361 | pack->err = NULL; | ||
| 362 | } | ||
| 363 | |||
| 364 | |||
| 365 | static ssize_t | ||
| 366 | dname_expand(const unsigned char *data, size_t len, size_t offset, | ||
| 367 | size_t *newoffset, char *dst, size_t max) | ||
| 368 | { | ||
| 369 | size_t n, count, end, ptr, start; | ||
| 370 | ssize_t res; | ||
| 371 | |||
| 372 | if (offset >= len) | ||
| 373 | return (-1); | ||
| 374 | |||
| 375 | res = 0; | ||
| 376 | end = start = offset; | ||
| 377 | |||
| 378 | for(; (n = data[offset]); ) { | ||
| 379 | if ((n & 0xc0) == 0xc0) { | ||
| 380 | if (offset + 2 > len) | ||
| 381 | return (-1); | ||
| 382 | ptr = 256 * (n & ~0xc0) + data[offset + 1]; | ||
| 383 | if (ptr >= start) | ||
| 384 | return (-1); | ||
| 385 | if (end < offset + 2) | ||
| 386 | end = offset + 2; | ||
| 387 | offset = ptr; | ||
| 388 | continue; | ||
| 389 | } | ||
| 390 | if (offset + n + 1 > len) | ||
| 391 | return (-1); | ||
| 392 | |||
| 393 | |||
| 394 | /* copy n + at offset+1 */ | ||
| 395 | if (dst != NULL && max != 0) { | ||
| 396 | count = (max < n + 1) ? (max) : (n + 1); | ||
| 397 | memmove(dst, data + offset, count); | ||
| 398 | dst += count; | ||
| 399 | max -= count; | ||
| 400 | } | ||
| 401 | res += n + 1; | ||
| 402 | offset += n + 1; | ||
| 403 | if (end < offset) | ||
| 404 | end = offset; | ||
| 405 | } | ||
| 406 | if (end < offset + 1) | ||
| 407 | end = offset + 1; | ||
| 408 | |||
| 409 | if (dst != NULL && max != 0) | ||
| 410 | dst[0] = 0; | ||
| 411 | if (newoffset) | ||
| 412 | *newoffset = end; | ||
| 413 | return (res + 1); | ||
| 414 | } | ||
| 415 | |||
| 416 | static int | ||
| 417 | unpack_data(struct packed *p, void *data, size_t len) | ||
| 418 | { | ||
| 419 | if (p->err) | ||
| 420 | return (-1); | ||
| 421 | |||
| 422 | if (p->len - p->offset < len) { | ||
| 423 | p->err = "too short"; | ||
| 424 | return (-1); | ||
| 425 | } | ||
| 426 | |||
| 427 | memmove(data, p->data + p->offset, len); | ||
| 428 | p->offset += len; | ||
| 429 | |||
| 430 | return (0); | ||
| 431 | } | ||
| 432 | |||
| 433 | static int | ||
| 434 | unpack_u16(struct packed *p, uint16_t *u16) | ||
| 435 | { | ||
| 436 | if (unpack_data(p, u16, 2) == -1) | ||
| 437 | return (-1); | ||
| 438 | |||
| 439 | *u16 = ntohs(*u16); | ||
| 440 | |||
| 441 | return (0); | ||
| 442 | } | ||
| 443 | |||
| 444 | static int | ||
| 445 | unpack_u32(struct packed *p, uint32_t *u32) | ||
| 446 | { | ||
| 447 | if (unpack_data(p, u32, 4) == -1) | ||
| 448 | return (-1); | ||
| 449 | |||
| 450 | *u32 = ntohl(*u32); | ||
| 451 | |||
| 452 | return (0); | ||
| 453 | } | ||
| 454 | |||
| 455 | static int | ||
| 456 | unpack_inaddr(struct packed *p, struct in_addr *a) | ||
| 457 | { | ||
| 458 | return (unpack_data(p, a, 4)); | ||
| 459 | } | ||
| 460 | |||
| 461 | static int | ||
| 462 | unpack_in6addr(struct packed *p, struct in6_addr *a6) | ||
| 463 | { | ||
| 464 | return (unpack_data(p, a6, 16)); | ||
| 465 | } | ||
| 466 | |||
| 467 | static int | ||
| 468 | unpack_dname(struct packed *p, char *dst, size_t max) | ||
| 469 | { | ||
| 470 | ssize_t e; | ||
| 471 | |||
| 472 | if (p->err) | ||
| 473 | return (-1); | ||
| 474 | |||
| 475 | e = dname_expand(p->data, p->len, p->offset, &p->offset, dst, max); | ||
| 476 | if (e == -1) { | ||
| 477 | p->err = "bad domain name"; | ||
| 478 | return (-1); | ||
| 479 | } | ||
| 480 | if (e < 0 || e > MAXDNAME) { | ||
| 481 | p->err = "domain name too long"; | ||
| 482 | return (-1); | ||
| 483 | } | ||
| 484 | |||
| 485 | return (0); | ||
| 486 | } | ||
| 487 | |||
| 488 | int | ||
| 489 | unpack_header(struct packed *p, struct header *h) | ||
| 490 | { | ||
| 491 | if (unpack_data(p, h, HFIXEDSZ) == -1) | ||
| 492 | return (-1); | ||
| 493 | |||
| 494 | h->flags = ntohs(h->flags); | ||
| 495 | h->qdcount = ntohs(h->qdcount); | ||
| 496 | h->ancount = ntohs(h->ancount); | ||
| 497 | h->nscount = ntohs(h->nscount); | ||
| 498 | h->arcount = ntohs(h->arcount); | ||
| 499 | |||
| 500 | return (0); | ||
| 501 | } | ||
| 502 | |||
| 503 | int | ||
| 504 | unpack_query(struct packed *p, struct query *q) | ||
| 505 | { | ||
| 506 | unpack_dname(p, q->q_dname, sizeof(q->q_dname)); | ||
| 507 | unpack_u16(p, &q->q_type); | ||
| 508 | unpack_u16(p, &q->q_class); | ||
| 509 | |||
| 510 | return (p->err) ? (-1) : (0); | ||
| 511 | } | ||
| 512 | |||
| 513 | int | ||
| 514 | unpack_rr(struct packed *p, struct rr *rr) | ||
| 515 | { | ||
| 516 | uint16_t rdlen; | ||
| 517 | size_t save_offset; | ||
| 518 | |||
| 519 | unpack_dname(p, rr->rr_dname, sizeof(rr->rr_dname)); | ||
| 520 | unpack_u16(p, &rr->rr_type); | ||
| 521 | unpack_u16(p, &rr->rr_class); | ||
| 522 | unpack_u32(p, &rr->rr_ttl); | ||
| 523 | unpack_u16(p, &rdlen); | ||
| 524 | |||
| 525 | if (p->err) | ||
| 526 | return (-1); | ||
| 527 | |||
| 528 | if (p->len - p->offset < rdlen) { | ||
| 529 | p->err = "too short"; | ||
| 530 | return (-1); | ||
| 531 | } | ||
| 532 | |||
| 533 | save_offset = p->offset; | ||
| 534 | |||
| 535 | switch(rr->rr_type) { | ||
| 536 | |||
| 537 | case T_CNAME: | ||
| 538 | unpack_dname(p, rr->rr.cname.cname, sizeof(rr->rr.cname.cname)); | ||
| 539 | break; | ||
| 540 | |||
| 541 | case T_MX: | ||
| 542 | unpack_u16(p, &rr->rr.mx.preference); | ||
| 543 | unpack_dname(p, rr->rr.mx.exchange, sizeof(rr->rr.mx.exchange)); | ||
| 544 | break; | ||
| 545 | |||
| 546 | case T_NS: | ||
| 547 | unpack_dname(p, rr->rr.ns.nsname, sizeof(rr->rr.ns.nsname)); | ||
| 548 | break; | ||
| 549 | |||
| 550 | case T_PTR: | ||
| 551 | unpack_dname(p, rr->rr.ptr.ptrname, sizeof(rr->rr.ptr.ptrname)); | ||
| 552 | break; | ||
| 553 | |||
| 554 | case T_SOA: | ||
| 555 | unpack_dname(p, rr->rr.soa.mname, sizeof(rr->rr.soa.mname)); | ||
| 556 | unpack_dname(p, rr->rr.soa.rname, sizeof(rr->rr.soa.rname)); | ||
| 557 | unpack_u32(p, &rr->rr.soa.serial); | ||
| 558 | unpack_u32(p, &rr->rr.soa.refresh); | ||
| 559 | unpack_u32(p, &rr->rr.soa.retry); | ||
| 560 | unpack_u32(p, &rr->rr.soa.expire); | ||
| 561 | unpack_u32(p, &rr->rr.soa.minimum); | ||
| 562 | break; | ||
| 563 | |||
| 564 | case T_A: | ||
| 565 | if (rr->rr_class != C_IN) | ||
| 566 | goto other; | ||
| 567 | unpack_inaddr(p, &rr->rr.in_a.addr); | ||
| 568 | break; | ||
| 569 | |||
| 570 | case T_AAAA: | ||
| 571 | if (rr->rr_class != C_IN) | ||
| 572 | goto other; | ||
| 573 | unpack_in6addr(p, &rr->rr.in_aaaa.addr6); | ||
| 574 | break; | ||
| 575 | default: | ||
| 576 | other: | ||
| 577 | rr->rr.other.rdata = p->data + p->offset; | ||
| 578 | rr->rr.other.rdlen = rdlen; | ||
| 579 | p->offset += rdlen; | ||
| 580 | } | ||
| 581 | |||
| 582 | if (p->err) | ||
| 583 | return (-1); | ||
| 584 | |||
| 585 | /* make sure that the advertised rdlen is really ok */ | ||
| 586 | if (p->offset - save_offset != rdlen) | ||
| 587 | p->err = "bad dlen"; | ||
| 588 | |||
| 589 | return (p->err) ? (-1) : (0); | ||
| 590 | } | ||
| 591 | |||
| 592 | int | ||
| 593 | sockaddr_from_str(struct sockaddr *sa, int family, const char *str) | ||
| 594 | { | ||
| 595 | struct in_addr ina; | ||
| 596 | struct in6_addr in6a; | ||
| 597 | struct sockaddr_in *sin; | ||
| 598 | struct sockaddr_in6 *sin6; | ||
| 599 | |||
| 600 | switch (family) { | ||
| 601 | case PF_UNSPEC: | ||
| 602 | if (sockaddr_from_str(sa, PF_INET, str) == 0) | ||
| 603 | return (0); | ||
| 604 | return sockaddr_from_str(sa, PF_INET6, str); | ||
| 605 | |||
| 606 | case PF_INET: | ||
| 607 | if (inet_pton(PF_INET, str, &ina) != 1) | ||
| 608 | return (-1); | ||
| 609 | |||
| 610 | sin = (struct sockaddr_in *)sa; | ||
| 611 | memset(sin, 0, sizeof *sin); | ||
| 612 | sin->sin_len = sizeof(struct sockaddr_in); | ||
| 613 | sin->sin_family = PF_INET; | ||
| 614 | sin->sin_addr.s_addr = ina.s_addr; | ||
| 615 | return (0); | ||
| 616 | |||
| 617 | case PF_INET6: | ||
| 618 | if (inet_pton(PF_INET6, str, &in6a) != 1) | ||
| 619 | return (-1); | ||
| 620 | |||
| 621 | sin6 = (struct sockaddr_in6 *)sa; | ||
| 622 | memset(sin6, 0, sizeof *sin6); | ||
| 623 | sin6->sin6_len = sizeof(struct sockaddr_in6); | ||
| 624 | sin6->sin6_family = PF_INET6; | ||
| 625 | sin6->sin6_addr = in6a; | ||
| 626 | return (0); | ||
| 627 | |||
| 628 | default: | ||
| 629 | break; | ||
| 630 | } | ||
| 631 | |||
| 632 | return (-1); | ||
| 633 | } | ||
| diff --git a/src/regress/lib/libc/asr/bin/common.h b/src/regress/lib/libc/asr/bin/common.h new file mode 100644 index 0000000000..87df4ae4a2 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/common.h | |||
| @@ -0,0 +1,136 @@ | |||
| 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 | |||
| 34 | extern int long_err; | ||
| 35 | extern int gai_errno; | ||
| 36 | extern int rrset_errno; | ||
| 37 | |||
| 38 | const char *classtostr(uint16_t); | ||
| 39 | const char *typetostr(uint16_t); | ||
| 40 | const char *rcodetostr(uint16_t); | ||
| 41 | |||
| 42 | uint16_t strtotype(const char*); | ||
| 43 | uint16_t strtoclass(const char*); | ||
| 44 | |||
| 45 | void print_rrsetinfo(struct rrsetinfo *); | ||
| 46 | void print_addrinfo(struct addrinfo *); | ||
| 47 | void print_errors(void); | ||
| 48 | void print_hostent(struct hostent *); | ||
| 49 | void print_netent(struct netent *); | ||
| 50 | |||
| 51 | int sockaddr_from_str(struct sockaddr *, int, const char *); | ||
| 52 | int addr_from_str(char *, int *, int *, const char *); | ||
| 53 | char* 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 | |||
| 68 | struct packed { | ||
| 69 | char *data; | ||
| 70 | size_t len; | ||
| 71 | size_t offset; | ||
| 72 | const char *err; | ||
| 73 | }; | ||
| 74 | |||
| 75 | struct 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 | |||
| 84 | struct query { | ||
| 85 | char q_dname[MAXDNAME]; | ||
| 86 | uint16_t q_type; | ||
| 87 | uint16_t q_class; | ||
| 88 | }; | ||
| 89 | |||
| 90 | struct 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 | |||
| 131 | void packed_init(struct packed*, char*, size_t); | ||
| 132 | int pack_header(struct packed*, const struct header*); | ||
| 133 | int pack_query(struct packed*, uint16_t, uint16_t, const char*); | ||
| 134 | int unpack_header(struct packed*, struct header*); | ||
| 135 | int unpack_query(struct packed*, struct query*); | ||
| 136 | int 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 new file mode 100644 index 0000000000..8c4abf361e --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getaddrinfo.c | |||
| @@ -0,0 +1,131 @@ | |||
| 1 | /* $OpenBSD: getaddrinfo.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 | |||
| 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 | |||
| 32 | static void | ||
| 33 | usage(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 | |||
| 42 | int | ||
| 43 | main(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 | ||
| 85 | usage(); | ||
| 86 | break; | ||
| 87 | case 's': | ||
| 88 | servname = optarg; | ||
| 89 | break; | ||
| 90 | case 't': | ||
| 91 | if (!strcmp(optarg, "stream")) | ||
| 92 | hints.ai_socktype = SOCK_STREAM; | ||
| 93 | else if (!strcmp(optarg, "dgram")) | ||
| 94 | hints.ai_socktype = SOCK_DGRAM; | ||
| 95 | else if (!strcmp(optarg, "raw")) | ||
| 96 | hints.ai_socktype = SOCK_RAW; | ||
| 97 | else | ||
| 98 | usage(); | ||
| 99 | break; | ||
| 100 | default: | ||
| 101 | usage(); | ||
| 102 | /* NOTREACHED */ | ||
| 103 | } | ||
| 104 | } | ||
| 105 | argc -= optind; | ||
| 106 | argv += optind; | ||
| 107 | |||
| 108 | for(i = 0; i < argc; i++) { | ||
| 109 | |||
| 110 | if (i) | ||
| 111 | printf("\n"); | ||
| 112 | printf("===> \"%s\"\n", argv[i]); | ||
| 113 | host = gethostarg(argv[i]); | ||
| 114 | |||
| 115 | errno = 0; | ||
| 116 | h_errno = 0; | ||
| 117 | gai_errno = 0; | ||
| 118 | rrset_errno = 0; | ||
| 119 | |||
| 120 | gai_errno = getaddrinfo(host, servname, &hints, &ai); | ||
| 121 | |||
| 122 | print_errors(); | ||
| 123 | if (gai_errno == 0) { | ||
| 124 | for (res = ai; res; res = res->ai_next) | ||
| 125 | print_addrinfo(res); | ||
| 126 | freeaddrinfo(ai); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | |||
| 130 | return (0); | ||
| 131 | } | ||
| diff --git a/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile b/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile new file mode 100644 index 0000000000..ec2f104ec7 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getaddrinfo/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getaddrinfo | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..336c6b9db3 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/gethostnamadr.c | |||
| @@ -0,0 +1,112 @@ | |||
| 1 | /* $OpenBSD: gethostnamadr.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 | |||
| 31 | static void | ||
| 32 | usage(void) | ||
| 33 | { | ||
| 34 | extern const char * __progname; | ||
| 35 | |||
| 36 | fprintf(stderr, "usage: %s [-46e] <host...>\n", __progname); | ||
| 37 | exit(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | int | ||
| 41 | main(int argc, char *argv[]) | ||
| 42 | { | ||
| 43 | int i, ch, isname, family = AF_INET; | ||
| 44 | struct hostent *h; | ||
| 45 | char *host; | ||
| 46 | char addr[16]; | ||
| 47 | int addraf; | ||
| 48 | int addrlen; | ||
| 49 | |||
| 50 | while((ch = getopt(argc, argv, "46e")) != -1) { | ||
| 51 | switch(ch) { | ||
| 52 | case '4': | ||
| 53 | family = AF_INET; | ||
| 54 | break; | ||
| 55 | case '6': | ||
| 56 | family = AF_INET6; | ||
| 57 | break; | ||
| 58 | case 'e': | ||
| 59 | long_err += 1; | ||
| 60 | break; | ||
| 61 | default: | ||
| 62 | usage(); | ||
| 63 | /* NOTREACHED */ | ||
| 64 | } | ||
| 65 | } | ||
| 66 | argc -= optind; | ||
| 67 | argv += optind; | ||
| 68 | |||
| 69 | for(i = 0; i < argc; i++) { | ||
| 70 | |||
| 71 | if (i) | ||
| 72 | printf("\n"); | ||
| 73 | printf("===> \"%s\"\n", argv[i]); | ||
| 74 | host = gethostarg(argv[i]); | ||
| 75 | |||
| 76 | if (addr_from_str(addr, &addraf, &addrlen, argv[i]) == -1) | ||
| 77 | isname = 1; | ||
| 78 | else | ||
| 79 | isname = 0; | ||
| 80 | |||
| 81 | errno = 0; | ||
| 82 | h_errno = 0; | ||
| 83 | gai_errno = 0; | ||
| 84 | rrset_errno = 0; | ||
| 85 | |||
| 86 | if (isname) | ||
| 87 | h = gethostbyname2(host, family); | ||
| 88 | else | ||
| 89 | h = gethostbyaddr(addr, addrlen, addraf); | ||
| 90 | if (h) | ||
| 91 | print_hostent(h); | ||
| 92 | print_errors(); | ||
| 93 | } | ||
| 94 | |||
| 95 | return (0); | ||
| 96 | } | ||
| 97 | |||
| 98 | int | ||
| 99 | addr_from_str(char *addr, int *family, int *len, const char *src) | ||
| 100 | { | ||
| 101 | if (inet_pton(AF_INET6, src, addr) == 1) { | ||
| 102 | *family = AF_INET6; | ||
| 103 | *len = 16; | ||
| 104 | return (0); | ||
| 105 | } | ||
| 106 | if (inet_pton(AF_INET, src, addr) == 1) { | ||
| 107 | *family = AF_INET; | ||
| 108 | *len = 4; | ||
| 109 | return (0); | ||
| 110 | } | ||
| 111 | return (-1); | ||
| 112 | } | ||
| diff --git a/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile b/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile new file mode 100644 index 0000000000..84906ffbbd --- /dev/null +++ b/src/regress/lib/libc/asr/bin/gethostnamadr/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= gethostnamadr | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..8702937a47 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getnameinfo.c | |||
| @@ -0,0 +1,112 @@ | |||
| 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 | |||
| 27 | static void | ||
| 28 | usage(void) | ||
| 29 | { | ||
| 30 | extern const char * __progname; | ||
| 31 | |||
| 32 | fprintf(stderr, "usage: %s [-DFHNSe] [-p portno] <addr...>\n", __progname); | ||
| 33 | exit(1); | ||
| 34 | } | ||
| 35 | |||
| 36 | int | ||
| 37 | main(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 new file mode 100644 index 0000000000..4927ee9486 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getnameinfo/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getnameinfo | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..4b7414264b --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getnetnamadr.c | |||
| @@ -0,0 +1,85 @@ | |||
| 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 | |||
| 31 | static void | ||
| 32 | usage(void) | ||
| 33 | { | ||
| 34 | extern const char * __progname; | ||
| 35 | |||
| 36 | fprintf(stderr, "usage: %s [-aen] [host...]\n", __progname); | ||
| 37 | exit(1); | ||
| 38 | } | ||
| 39 | |||
| 40 | int | ||
| 41 | main(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 new file mode 100644 index 0000000000..521bf8eb7e --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getnetnamadr/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getnetnamadr | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..4a5aa57209 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getrrsetbyname.c | |||
| @@ -0,0 +1,88 @@ | |||
| 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 | |||
| 33 | static void | ||
| 34 | usage(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 | |||
| 43 | int | ||
| 44 | main(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 new file mode 100644 index 0000000000..131403bea1 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/getrrsetbyname/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= getrrsetbyname | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..a52023c5c0 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/res_mkquery.c | |||
| @@ -0,0 +1,319 @@ | |||
| 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 */ | ||
| 37 | static void dump_packet(const void *, size_t); | ||
| 38 | |||
| 39 | static char *print_query(struct query *, char *, size_t); | ||
| 40 | static char *print_rr(struct rr *, char *, size_t); | ||
| 41 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
| 42 | static char* print_dname(const char *, char *, size_t); | ||
| 43 | |||
| 44 | |||
| 45 | static void | ||
| 46 | usage(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 | |||
| 55 | int | ||
| 56 | main(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 | |||
| 106 | static char* | ||
| 107 | print_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 | |||
| 124 | static void | ||
| 125 | dump_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 | |||
| 178 | static const char * | ||
| 179 | inet6_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 | |||
| 191 | static char* | ||
| 192 | print_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 | |||
| 262 | static char* | ||
| 263 | print_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 | |||
| 275 | static char * | ||
| 276 | print_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 | |||
| 291 | static char* | ||
| 292 | print_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 new file mode 100644 index 0000000000..770fa9f633 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/res_mkquery/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= res_mkquery${BINEXT} | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..fd96f1de22 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/res_query.c | |||
| @@ -0,0 +1,354 @@ | |||
| 1 | /* $OpenBSD: res_query.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 | #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 */ | ||
| 37 | static void dump_packet(const void *, size_t); | ||
| 38 | |||
| 39 | static char *print_query(struct query *, char *, size_t); | ||
| 40 | static char *print_rr(struct rr *, char *, size_t); | ||
| 41 | static char *print_host(const struct sockaddr *, char *, size_t); | ||
| 42 | static char* print_dname(const char *, char *, size_t); | ||
| 43 | |||
| 44 | |||
| 45 | static int | ||
| 46 | msec(struct timeval start, struct timeval end) | ||
| 47 | { | ||
| 48 | return (int)((end.tv_sec - start.tv_sec) * 1000 | ||
| 49 | + (end.tv_usec - start.tv_usec) / 1000); | ||
| 50 | } | ||
| 51 | |||
| 52 | static void | ||
| 53 | usage(void) | ||
| 54 | { | ||
| 55 | extern const char * __progname; | ||
| 56 | |||
| 57 | fprintf(stderr, "usage: %s [-deq] [-t type] [host...]\n", | ||
| 58 | __progname); | ||
| 59 | exit(1); | ||
| 60 | } | ||
| 61 | |||
| 62 | int | ||
| 63 | main(int argc, char *argv[]) | ||
| 64 | { | ||
| 65 | struct timeval start, end; | ||
| 66 | time_t when; | ||
| 67 | int ch, i, qflag, dflag, r; | ||
| 68 | uint16_t type = T_A; | ||
| 69 | char buf[1024], *host; | ||
| 70 | |||
| 71 | dflag = 0; | ||
| 72 | qflag = 0; | ||
| 73 | |||
| 74 | while((ch = getopt(argc, argv, "deqt:")) != -1) { | ||
| 75 | switch(ch) { | ||
| 76 | case 'd': | ||
| 77 | dflag = 1; | ||
| 78 | break; | ||
| 79 | case 'e': | ||
| 80 | long_err += 1; | ||
| 81 | break; | ||
| 82 | case 'q': | ||
| 83 | qflag = 1; | ||
| 84 | break; | ||
| 85 | case 't': | ||
| 86 | if ((type = strtotype(optarg)) == 0) | ||
| 87 | usage(); | ||
| 88 | break; | ||
| 89 | default: | ||
| 90 | usage(); | ||
| 91 | /* NOTREACHED */ | ||
| 92 | } | ||
| 93 | } | ||
| 94 | argc -= optind; | ||
| 95 | argv += optind; | ||
| 96 | |||
| 97 | for (i = 0; i < argc; i++) { | ||
| 98 | |||
| 99 | if (i) | ||
| 100 | printf("\n"); | ||
| 101 | |||
| 102 | printf("===> \"%s\"\n", argv[i]); | ||
| 103 | host = gethostarg(argv[i]); | ||
| 104 | |||
| 105 | errno = 0; | ||
| 106 | h_errno = 0; | ||
| 107 | gai_errno = 0; | ||
| 108 | rrset_errno = 0; | ||
| 109 | |||
| 110 | if (gettimeofday(&start, NULL) != 0) | ||
| 111 | err(1, "gettimeofday"); | ||
| 112 | |||
| 113 | if (qflag) | ||
| 114 | r = res_query(host, C_IN, type, buf, sizeof(buf)); | ||
| 115 | else | ||
| 116 | r = res_search(host, C_IN, type, buf, sizeof(buf)); | ||
| 117 | |||
| 118 | if (gettimeofday(&end, NULL) != 0) | ||
| 119 | err(1, "gettimeofday"); | ||
| 120 | |||
| 121 | if (r != -1) { | ||
| 122 | dump_packet(buf, r); | ||
| 123 | printf("\n"); | ||
| 124 | if (dflag) { | ||
| 125 | printf(";; Query time: %d msec\n", | ||
| 126 | msec(start, end)); | ||
| 127 | when = time(NULL); | ||
| 128 | printf(";; WHEN: %s", ctime(&when)); | ||
| 129 | } | ||
| 130 | printf(";; MSG SIZE rcvd: %i\n", r); | ||
| 131 | } | ||
| 132 | print_errors(); | ||
| 133 | } | ||
| 134 | |||
| 135 | return (0); | ||
| 136 | } | ||
| 137 | |||
| 138 | #define OPCODE_SHIFT 11 | ||
| 139 | #define Z_SHIFT 4 | ||
| 140 | |||
| 141 | static char* | ||
| 142 | print_header(struct header *h, char *buf, size_t max) | ||
| 143 | { | ||
| 144 | snprintf(buf, max, | ||
| 145 | "id:0x.... %s op:%i %s %s %s %s z:%i r:%s qd:%i an:%i ns:%i ar:%i", | ||
| 146 | (h->flags & QR_MASK) ? "QR":" ", | ||
| 147 | (int)(OPCODE(h->flags) >> OPCODE_SHIFT), | ||
| 148 | (h->flags & AA_MASK) ? "AA":" ", | ||
| 149 | (h->flags & TC_MASK) ? "TC":" ", | ||
| 150 | (h->flags & RD_MASK) ? "RD":" ", | ||
| 151 | (h->flags & RA_MASK) ? "RA":" ", | ||
| 152 | ((h->flags & Z_MASK) >> Z_SHIFT), | ||
| 153 | rcodetostr(RCODE(h->flags)), | ||
| 154 | h->qdcount, h->ancount, h->nscount, h->arcount); | ||
| 155 | |||
| 156 | return buf; | ||
| 157 | } | ||
| 158 | |||
| 159 | static void | ||
| 160 | dump_packet(const void *data, size_t len) | ||
| 161 | { | ||
| 162 | char buf[1024]; | ||
| 163 | struct packed p; | ||
| 164 | struct header h; | ||
| 165 | struct query q; | ||
| 166 | struct rr rr; | ||
| 167 | int i, an, ns, ar, n; | ||
| 168 | |||
| 169 | packed_init(&p, (char *)data, len); | ||
| 170 | |||
| 171 | if (unpack_header(&p, &h) == -1) { | ||
| 172 | printf(";; BAD PACKET: %s\n", p.err); | ||
| 173 | return; | ||
| 174 | } | ||
| 175 | |||
| 176 | printf(";; HEADER %s\n", print_header(&h, buf, sizeof buf)); | ||
| 177 | |||
| 178 | if (h.qdcount) | ||
| 179 | printf(";; QUERY SECTION:\n"); | ||
| 180 | for (i = 0; i < h.qdcount; i++) { | ||
| 181 | if (unpack_query(&p, &q) == -1) | ||
| 182 | goto error; | ||
| 183 | printf("%s\n", print_query(&q, buf, sizeof buf)); | ||
| 184 | } | ||
| 185 | |||
| 186 | an = 0; | ||
| 187 | ns = an + h.ancount; | ||
| 188 | ar = ns + h.nscount; | ||
| 189 | n = ar + h.arcount; | ||
| 190 | |||
| 191 | for (i = 0; i < n; i++) { | ||
| 192 | if (i == an) | ||
| 193 | printf("\n;; ANSWER SECTION:\n"); | ||
| 194 | if (i == ns) | ||
| 195 | printf("\n;; AUTHORITY SECTION:\n"); | ||
| 196 | if (i == ar) | ||
| 197 | printf("\n;; ADDITIONAL SECTION:\n"); | ||
| 198 | |||
| 199 | if (unpack_rr(&p, &rr) == -1) | ||
| 200 | goto error; | ||
| 201 | printf("%s\n", print_rr(&rr, buf, sizeof buf)); | ||
| 202 | } | ||
| 203 | |||
| 204 | if (p.offset != len) | ||
| 205 | printf(";; REMAINING GARBAGE %zu\n", len - p.offset); | ||
| 206 | |||
| 207 | error: | ||
| 208 | if (p.err) | ||
| 209 | printf(";; ERROR AT OFFSET %zu/%zu: %s\n", p.offset, p.len, | ||
| 210 | p.err); | ||
| 211 | } | ||
| 212 | |||
| 213 | static const char * | ||
| 214 | inet6_ntoa(struct in6_addr a) | ||
| 215 | { | ||
| 216 | static char buf[256]; | ||
| 217 | struct sockaddr_in6 si; | ||
| 218 | |||
| 219 | si.sin6_len = sizeof(si); | ||
| 220 | si.sin6_family = PF_INET6; | ||
| 221 | si.sin6_addr = a; | ||
| 222 | |||
| 223 | return print_host((struct sockaddr*)&si, buf, sizeof buf); | ||
| 224 | } | ||
| 225 | |||
| 226 | static char* | ||
| 227 | print_rr(struct rr *rr, char *buf, size_t max) | ||
| 228 | { | ||
| 229 | char *res; | ||
| 230 | char tmp[256]; | ||
| 231 | char tmp2[256]; | ||
| 232 | int r; | ||
| 233 | |||
| 234 | res = buf; | ||
| 235 | |||
| 236 | r = snprintf(buf, max, "%s %u %s %s ", | ||
| 237 | print_dname(rr->rr_dname, tmp, sizeof tmp), | ||
| 238 | rr->rr_ttl, | ||
| 239 | classtostr(rr->rr_class), | ||
| 240 | typetostr(rr->rr_type)); | ||
| 241 | if (r == -1) { | ||
| 242 | buf[0] = '\0'; | ||
| 243 | return buf; | ||
| 244 | } | ||
| 245 | |||
| 246 | if ((size_t)r >= max) | ||
| 247 | return buf; | ||
| 248 | |||
| 249 | max -= r; | ||
| 250 | buf += r; | ||
| 251 | |||
| 252 | switch(rr->rr_type) { | ||
| 253 | case T_CNAME: | ||
| 254 | print_dname(rr->rr.cname.cname, buf, max); | ||
| 255 | break; | ||
| 256 | case T_MX: | ||
| 257 | snprintf(buf, max, "%"PRIu32" %s", | ||
| 258 | rr->rr.mx.preference, | ||
| 259 | print_dname(rr->rr.mx.exchange, tmp, sizeof tmp)); | ||
| 260 | break; | ||
| 261 | case T_NS: | ||
| 262 | print_dname(rr->rr.ns.nsname, buf, max); | ||
| 263 | break; | ||
| 264 | case T_PTR: | ||
| 265 | print_dname(rr->rr.ptr.ptrname, buf, max); | ||
| 266 | break; | ||
| 267 | case T_SOA: | ||
| 268 | snprintf(buf, max, | ||
| 269 | "%s %s %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32, | ||
| 270 | print_dname(rr->rr.soa.rname, tmp, sizeof tmp), | ||
| 271 | print_dname(rr->rr.soa.mname, tmp2, sizeof tmp2), | ||
| 272 | rr->rr.soa.serial, | ||
| 273 | rr->rr.soa.refresh, | ||
| 274 | rr->rr.soa.retry, | ||
| 275 | rr->rr.soa.expire, | ||
| 276 | rr->rr.soa.minimum); | ||
| 277 | break; | ||
| 278 | case T_A: | ||
| 279 | if (rr->rr_class != C_IN) | ||
| 280 | goto other; | ||
| 281 | snprintf(buf, max, "%s", inet_ntoa(rr->rr.in_a.addr)); | ||
| 282 | break; | ||
| 283 | case T_AAAA: | ||
| 284 | if (rr->rr_class != C_IN) | ||
| 285 | goto other; | ||
| 286 | snprintf(buf, max, "%s", inet6_ntoa(rr->rr.in_aaaa.addr6)); | ||
| 287 | break; | ||
| 288 | default: | ||
| 289 | other: | ||
| 290 | snprintf(buf, max, "(rdlen=%"PRIu16 ")", rr->rr.other.rdlen); | ||
| 291 | break; | ||
| 292 | } | ||
| 293 | |||
| 294 | return (res); | ||
| 295 | } | ||
| 296 | |||
| 297 | static char* | ||
| 298 | print_query(struct query *q, char *buf, size_t max) | ||
| 299 | { | ||
| 300 | char b[256]; | ||
| 301 | |||
| 302 | snprintf(buf, max, "%s %s %s", | ||
| 303 | print_dname(q->q_dname, b, sizeof b), | ||
| 304 | classtostr(q->q_class), typetostr(q->q_type)); | ||
| 305 | |||
| 306 | return (buf); | ||
| 307 | } | ||
| 308 | |||
| 309 | |||
| 310 | static char * | ||
| 311 | print_host(const struct sockaddr *sa, char *buf, size_t len) | ||
| 312 | { | ||
| 313 | switch (sa->sa_family) { | ||
| 314 | case AF_INET: | ||
| 315 | inet_ntop(AF_INET, &((struct sockaddr_in*)sa)->sin_addr, buf, len); | ||
| 316 | break; | ||
| 317 | case AF_INET6: | ||
| 318 | inet_ntop(AF_INET6, &((struct sockaddr_in6*)sa)->sin6_addr, buf, len); | ||
| 319 | break; | ||
| 320 | default: | ||
| 321 | buf[0] = '\0'; | ||
| 322 | } | ||
| 323 | return (buf); | ||
| 324 | } | ||
| 325 | |||
| 326 | static char* | ||
| 327 | print_dname(const char *_dname, char *buf, size_t max) | ||
| 328 | { | ||
| 329 | const unsigned char *dname = _dname; | ||
| 330 | char *res; | ||
| 331 | size_t left, n, count; | ||
| 332 | |||
| 333 | if (_dname[0] == 0) { | ||
| 334 | strlcpy(buf, ".", max); | ||
| 335 | return buf; | ||
| 336 | } | ||
| 337 | |||
| 338 | res = buf; | ||
| 339 | left = max - 1; | ||
| 340 | for (n = 0; dname[0] && left; n += dname[0]) { | ||
| 341 | count = (dname[0] < (left - 1)) ? dname[0] : (left - 1); | ||
| 342 | memmove(buf, dname + 1, count); | ||
| 343 | dname += dname[0] + 1; | ||
| 344 | left -= count; | ||
| 345 | buf += count; | ||
| 346 | if (left) { | ||
| 347 | left -= 1; | ||
| 348 | *buf++ = '.'; | ||
| 349 | } | ||
| 350 | } | ||
| 351 | buf[0] = 0; | ||
| 352 | |||
| 353 | return (res); | ||
| 354 | } | ||
| diff --git a/src/regress/lib/libc/asr/bin/res_query/Makefile b/src/regress/lib/libc/asr/bin/res_query/Makefile new file mode 100644 index 0000000000..75380ee079 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/res_query/Makefile | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= res_query${BINEXT} | ||
| 6 | SRCS+= 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 new file mode 100644 index 0000000000..f296f1d6f7 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/threads.c | |||
| @@ -0,0 +1,140 @@ | |||
| 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 | |||
| 32 | int ac; | ||
| 33 | char **av; | ||
| 34 | int loop; | ||
| 35 | int nthreads; | ||
| 36 | |||
| 37 | int long_err; | ||
| 38 | int gai_errno; | ||
| 39 | int rrset_errno; | ||
| 40 | |||
| 41 | void async_resolver_done(void *); | ||
| 42 | |||
| 43 | void stats(void) | ||
| 44 | { | ||
| 45 | struct rusage ru; | ||
| 46 | |||
| 47 | getrusage(RUSAGE_SELF, &ru); | ||
| 48 | printf("%li\n", ru.ru_maxrss); | ||
| 49 | } | ||
| 50 | |||
| 51 | void* | ||
| 52 | task(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 | |||
| 78 | void | ||
| 79 | usage(void) | ||
| 80 | { | ||
| 81 | extern const char *__progname; | ||
| 82 | fprintf(stderr, "usage: %s [-L loop] [-l loop] [-t threads] <host> ...\n", | ||
| 83 | __progname); | ||
| 84 | } | ||
| 85 | |||
| 86 | int | ||
| 87 | main(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 new file mode 100644 index 0000000000..3252511cd1 --- /dev/null +++ b/src/regress/lib/libc/asr/bin/threads/Makefile | |||
| @@ -0,0 +1,10 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1.1.1 2012/07/13 17:49:54 eric Exp $ | ||
| 2 | |||
| 3 | .PATH: ${.CURDIR}/.. | ||
| 4 | |||
| 5 | PROG= threads | ||
| 6 | SRCS+= threads.c | ||
| 7 | |||
| 8 | LDADD= -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 new file mode 100644 index 0000000000..b4d1c1db59 --- /dev/null +++ b/src/regress/lib/libc/asr/regress.sh | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | # $OpenBSD: regress.sh,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ | ||
| 2 | |||
| 3 | . regress.subr | ||
| 4 | |||
| 5 | EFLAG= | ||
| 6 | |||
| 7 | test_res_mkquery() | ||
| 8 | { | ||
| 9 | for i in $@; do | ||
| 10 | regress res_mkquery $i | ||
| 11 | done | ||
| 12 | } | ||
| 13 | |||
| 14 | test_res_query() | ||
| 15 | { | ||
| 16 | for i in $@; do | ||
| 17 | regress res_query $i | ||
| 18 | regress res_query -q $i | ||
| 19 | done | ||
| 20 | } | ||
| 21 | |||
| 22 | test_getrrsetbyname() | ||
| 23 | { | ||
| 24 | for i in $@; do | ||
| 25 | regress getrrsetbyname $i | ||
| 26 | regress getrrsetbyname -t MX $i | ||
| 27 | regress getrrsetbyname -t AAAA $i | ||
| 28 | done | ||
| 29 | } | ||
| 30 | |||
| 31 | test_gethostbyname() | ||
| 32 | { | ||
| 33 | for i in $@; do | ||
| 34 | regress gethostnamadr $i | ||
| 35 | regress gethostnamadr -4 $i | ||
| 36 | regress gethostnamadr -6 $i | ||
| 37 | done | ||
| 38 | } | ||
| 39 | |||
| 40 | test_gethostbyaddr() | ||
| 41 | { | ||
| 42 | for i in $@; do | ||
| 43 | regress gethostnamadr $i | ||
| 44 | done | ||
| 45 | } | ||
| 46 | |||
| 47 | test_getaddrinfo() | ||
| 48 | { | ||
| 49 | for i in $@; do | ||
| 50 | regress getaddrinfo $i | ||
| 51 | regress getaddrinfo -C $i | ||
| 52 | regress getaddrinfo -F $i | ||
| 53 | regress getaddrinfo -CF $i | ||
| 54 | regress getaddrinfo -P $i | ||
| 55 | regress getaddrinfo -PF $i | ||
| 56 | regress getaddrinfo -PC $i | ||
| 57 | regress getaddrinfo -H $i | ||
| 58 | regress getaddrinfo -p tcp $i | ||
| 59 | regress getaddrinfo -p udp $i | ||
| 60 | regress getaddrinfo -s www $i | ||
| 61 | regress getaddrinfo -s bad $i | ||
| 62 | regress getaddrinfo -S -s 8081 $i | ||
| 63 | regress getaddrinfo -S -s bad $i | ||
| 64 | regress getaddrinfo -P -s syslog $i | ||
| 65 | regress getaddrinfo -P -s syslog -p tcp $i | ||
| 66 | regress getaddrinfo -P -s syslog -p udp $i | ||
| 67 | done | ||
| 68 | } | ||
| 69 | |||
| 70 | test_getnameinfo() | ||
| 71 | { | ||
| 72 | for i in $@; do | ||
| 73 | regress getnameinfo $i | ||
| 74 | regress getnameinfo -D $i | ||
| 75 | regress getnameinfo -F $i | ||
| 76 | regress getnameinfo -H $i | ||
| 77 | regress getnameinfo -N $i | ||
| 78 | regress getnameinfo -S $i | ||
| 79 | regress getnameinfo -p 80 $i | ||
| 80 | regress getnameinfo -p 514 $i | ||
| 81 | regress getnameinfo -p 514 -D $i | ||
| 82 | regress getnameinfo -p 5566 $i | ||
| 83 | done | ||
| 84 | } | ||
| 85 | |||
| 86 | WEIRD="EMPTY . .. ..." | ||
| 87 | BASIC="localhost $(hostname -s) $(hostname)" | ||
| 88 | EXTRA="undeadly.org www.openbsd.org cvs.openbsd.org" | ||
| 89 | |||
| 90 | ADDRS="0.0.0.0 :: 127.0.0.1 ::1 212.227.193.194" | ||
| 91 | |||
| 92 | for e in file bind; do | ||
| 93 | regress_setenv $e | ||
| 94 | |||
| 95 | test_res_mkquery $WEIRD $BASIC | ||
| 96 | test_res_query $WEIRD $BASIC $EXTRA | ||
| 97 | test_getrrsetbyname $WEIRD $BASIC $EXTRA | ||
| 98 | test_gethostbyname $WEIRD $BASIC $EXTRA | ||
| 99 | test_gethostbyaddr $ADDRS | ||
| 100 | test_getaddrinfo NULL $WEIRD $BASIC $EXTRA | ||
| 101 | test_getnameinfo $ADDRS | ||
| 102 | done | ||
| 103 | |||
| 104 | regress_digest | ||
| diff --git a/src/regress/lib/libc/asr/regress.subr b/src/regress/lib/libc/asr/regress.subr new file mode 100644 index 0000000000..dafb7ddf75 --- /dev/null +++ b/src/regress/lib/libc/asr/regress.subr | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # $OpenBSD: regress.subr,v 1.1.1.1 2012/07/13 17:49:53 eric Exp $ | ||
| 3 | |||
| 4 | TOTAL=0 | ||
| 5 | FAIL=0 | ||
| 6 | OK=0 | ||
| 7 | |||
| 8 | EXT0=.std | ||
| 9 | EXT1=.asr | ||
| 10 | EFLAG=-ee | ||
| 11 | |||
| 12 | set -e | ||
| 13 | |||
| 14 | fail() | ||
| 15 | { | ||
| 16 | echo "*** ERROR: $@" | ||
| 17 | exit 1 | ||
| 18 | } | ||
| 19 | |||
| 20 | regress() | ||
| 21 | { | ||
| 22 | local out; | ||
| 23 | local _cmd=$1; | ||
| 24 | local _bin0=/bin/$_cmd$EXT0 | ||
| 25 | local _bin1=/bin/$_cmd$EXT1 | ||
| 26 | shift; | ||
| 27 | |||
| 28 | TOTAL=$((TOTAL+1)) | ||
| 29 | |||
| 30 | # XXX with user "bin" | ||
| 31 | test -x $_RUNDIR$_bin0 || fail $_RUNDIR$_bin0 not executable | ||
| 32 | test -x $_RUNDIR$_bin1 || fail $_RUNDIR$_bin1 not executable | ||
| 33 | |||
| 34 | out=/tmp/asr_regress | ||
| 35 | |||
| 36 | echo -n $_cmd $EFLAG $@ "." | ||
| 37 | |||
| 38 | set +e | ||
| 39 | chroot -u bin "$_RUNDIR" $_bin0 $EFLAG $@ > $out.0 | ||
| 40 | echo -n . | ||
| 41 | chroot -u bin "$_RUNDIR" $_bin1 $EFLAG $@ > $out.1 | ||
| 42 | echo -n ". " | ||
| 43 | |||
| 44 | diff -u $out.0 $out.1 > $out.diff | ||
| 45 | set -e | ||
| 46 | if test -s $out.diff; then | ||
| 47 | FAIL=$((FAIL+1)) | ||
| 48 | echo fail | ||
| 49 | echo "*** FAIL (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $REG | ||
| 50 | tail -n +3 $out.diff >> $REG | ||
| 51 | echo >> $REG | ||
| 52 | else | ||
| 53 | OK=$((OK+1)) | ||
| 54 | echo ok | ||
| 55 | echo "OK (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $OUT | ||
| 56 | cat $out.0 >> $OUT | ||
| 57 | echo >> $OUT | ||
| 58 | fi | ||
| 59 | rm $out.diff $out.0 $out.1 | ||
| 60 | } | ||
| 61 | |||
| 62 | regress_setenv() | ||
| 63 | { | ||
| 64 | local _name="$1" | ||
| 65 | |||
| 66 | echo "===> using env $_name" | ||
| 67 | |||
| 68 | cp /etc/hosts $_RUNDIR/etc/ | ||
| 69 | cp /etc/resolv.conf $_RUNDIR/etc/ | ||
| 70 | cp /etc/protocols $_RUNDIR/etc/ | ||
| 71 | cp /etc/networks $_RUNDIR/etc/ | ||
| 72 | |||
| 73 | case $_name in | ||
| 74 | empty) | ||
| 75 | rm -f $_RUNDIR/etc/* | ||
| 76 | ;; | ||
| 77 | local) | ||
| 78 | ;; | ||
| 79 | file) | ||
| 80 | grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf | ||
| 81 | echo "lookup file" >> $_RUNDIR/etc/resolv.conf | ||
| 82 | ;; | ||
| 83 | bind) | ||
| 84 | grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf | ||
| 85 | echo "lookup bind" >> $_RUNDIR/etc/resolv.conf | ||
| 86 | ;; | ||
| 87 | *) | ||
| 88 | fail unknown env $_name | ||
| 89 | ;; | ||
| 90 | esac | ||
| 91 | REGRESSENV=$_name | ||
| 92 | } | ||
| 93 | |||
| 94 | regress_digest() | ||
| 95 | { | ||
| 96 | echo | ||
| 97 | cat $REG | ||
| 98 | echo "===>" run=$TOTAL fail=$FAIL | ||
| 99 | } | ||
| 100 | |||
| 101 | |||
| 102 | # needed for chroot | ||
| 103 | test "$(id -u)" -ne 0 && fail need root privileges to run this script | ||
| 104 | |||
| 105 | # we really really want to avoid erasing /etc later | ||
| 106 | test "$RUNDIR" || fail RUNDIR is not set | ||
| 107 | _RUNDIR=$(readlink -fn ${RUNDIR}) | ||
| 108 | test "$_RUNDIR" == / && fail RUNDIR is root dir: $RUNDIR | ||
| 109 | |||
| 110 | OUT=$_RUNDIR/output.log | ||
| 111 | REG=$_RUNDIR/regress.log | ||
| 112 | |||
| 113 | echo -n > $REG | ||
| 114 | echo -n > $OUT | ||
