diff options
Diffstat (limited to 'contrib/netbsd-tests/lib/libc/net')
29 files changed, 2287 insertions, 0 deletions
diff --git a/contrib/netbsd-tests/lib/libc/net/gen_ether_subr b/contrib/netbsd-tests/lib/libc/net/gen_ether_subr new file mode 100755 index 0000000..9f9b63c --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/gen_ether_subr @@ -0,0 +1,25 @@ +#!/bin/sh + +awk ' +BEGIN { + print + print "#include <ctype.h>" + print "#include <sys/types.h>" + print "#include <errno.h>" + print + print "#define ETHER_ADDR_LEN 6" + print + print "int ether_aton_r(u_char *dest, size_t len, const char *str);" + print +} +/^ether_aton_r/ { + print prevline + out = 1 +} +{ + if (out) print + else prevline = $0 +} +/^}$/ { + if (out) exit(0) +}' $1 >$2 diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/README b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/README new file mode 100644 index 0000000..e856fe7 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/README @@ -0,0 +1,7 @@ +This test may fail if + + - your /etc/services file is not in sync with what this test expects + - your /etc/hosts file or DNS have unusual entries for "localhost" + (a duplicate "localhost 127.0.0.1" line in /etc/hosts for example) + +On kernels without IPv6 support some of the tests are skipped. diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4.exp new file mode 100644 index 0000000..d2945f2 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4.exp @@ -0,0 +1,36 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv tftp +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4v6.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4v6.exp new file mode 100644 index 0000000..0238f83 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/basics_v4v6.exp @@ -0,0 +1,42 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv tftp +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv tftp +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv tftp +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv tftp +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv tftp +ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv tftp +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv echo +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv echo +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv echo +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo +ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/h_gai.c b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/h_gai.c new file mode 100644 index 0000000..939fcdb --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/h_gai.c @@ -0,0 +1,186 @@ +/* $NetBSD: h_gai.c,v 1.1 2011/01/12 02:58:40 pgoyette Exp $ */ + +/* + * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <netdb.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <arpa/inet.h> + +struct addrinfo ai; + +char host[NI_MAXHOST]; +char serv[NI_MAXSERV]; +int vflag = 0; + +static void usage(void); +static void print1(const char *, const struct addrinfo *, char *, char *); +int main(int, char *[]); + +static void +usage() +{ + fprintf(stderr, "usage: test [-f family] [-s socktype] [-p proto] [-DPRSv46] host serv\n"); +} + +static void +print1(const char *title, const struct addrinfo *res, char *h, char *s) +{ + const char *start, *end; + int error; + const int niflag = NI_NUMERICHOST; + + if (res->ai_addr) { + error = getnameinfo(res->ai_addr, res->ai_addr->sa_len, + host, sizeof(host), serv, sizeof(serv), + niflag); + h = host; + s = serv; + } else + error = 0; + + if (vflag) { + start = "\t"; + end = "\n"; + } else { + start = " "; + end = ""; + } + printf("%s%s", title, end); + printf("%sflags 0x%x%s", start, res->ai_flags, end); + printf("%sfamily %d%s", start, res->ai_family, end); + printf("%ssocktype %d%s", start, res->ai_socktype, end); + printf("%sprotocol %d%s", start, res->ai_protocol, end); + printf("%saddrlen %d%s", start, res->ai_addrlen, end); + if (error) + printf("%serror %d%s", start, error, end); + else { + printf("%shost %s%s", start, h, end); + printf("%sserv %s%s", start, s, end); + } +#if 0 + if (res->ai_canonname) + printf("%scname \"%s\"%s", start, res->ai_canonname, end); +#endif + if (!vflag) + printf("\n"); + +} + +int +main(int argc, char *argv[]) +{ + struct addrinfo *res; + int error, i; + char *p, *q; + extern int optind; + extern char *optarg; + int c; + char nbuf[10]; + + memset(&ai, 0, sizeof(ai)); + ai.ai_family = PF_UNSPEC; + ai.ai_flags |= AI_CANONNAME; + while ((c = getopt(argc, argv, "Df:p:PRs:Sv46")) != -1) { + switch (c) { + case 'D': + ai.ai_socktype = SOCK_DGRAM; + break; + case 'f': + ai.ai_family = atoi(optarg); + break; + case 'p': + ai.ai_protocol = atoi(optarg); + break; + case 'P': + ai.ai_flags |= AI_PASSIVE; + break; + case 'R': + ai.ai_socktype = SOCK_RAW; + break; + case 's': + ai.ai_socktype = atoi(optarg); + break; + case 'S': + ai.ai_socktype = SOCK_STREAM; + break; + case 'v': + vflag++; + break; + case '4': + ai.ai_family = PF_INET; + break; + case '6': + ai.ai_family = PF_INET6; + break; + default: + usage(); + exit(1); + } + } + argc -= optind; + argv += optind; + + if (argc != 2){ + usage(); + exit(1); + } + + p = *argv[0] ? argv[0] : NULL; + q = *argv[1] ? argv[1] : NULL; + + strncpy(nbuf, "(empty)", sizeof(nbuf)); + print1("arg:", &ai, p ? p : nbuf , q ? q : nbuf); + + error = getaddrinfo(p, q, &ai, &res); + if (error) { + printf("%s\n", gai_strerror(error)); + exit(1); + } + + i = 1; + do { + snprintf(nbuf, sizeof(nbuf), "ai%d:", i); + print1(nbuf, res, NULL, NULL); + + i++; + } while ((res = res->ai_next) != NULL); + printf("\n"); + + exit(0); +} diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4.exp new file mode 100644 index 0000000..21059c7 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4.exp @@ -0,0 +1,38 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http +ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv http +ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv http + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo +ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv echo +ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv echo + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp +ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv tftp +ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv tftp + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv http +ai2: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv http + +arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4v6.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4v6.exp new file mode 100644 index 0000000..7d30fea --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_host_v4v6.exp @@ -0,0 +1,56 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http +ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv echo +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv echo +ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv echo +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv echo + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv tftp +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv tftp +ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv tftp +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv tftp + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http +ai3: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv http +ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv http +ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv http +ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv http +ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv http + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv echo +ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv echo +ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv echo +ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv echo +ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv echo + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv tftp +ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv tftp +ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv tftp +ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv tftp +ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv tftp + +arg: flags 0x3 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x3 family 24 socktype 2 protocol 17 addrlen 28 host :: serv http +ai2: flags 0x3 family 24 socktype 1 protocol 6 addrlen 28 host :: serv http +ai3: flags 0x3 family 2 socktype 2 protocol 17 addrlen 16 host 0.0.0.0 serv http +ai4: flags 0x3 family 2 socktype 1 protocol 6 addrlen 16 host 0.0.0.0 serv http + +arg: flags 0x2 family 0 socktype 1 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 0 socktype 2 protocol 0 addrlen 0 host (empty) serv 80 +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4.exp new file mode 100644 index 0000000..9de5c56 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4.exp @@ -0,0 +1,14 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) +hostname nor servname provided, or not known diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4v6.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4v6.exp new file mode 100644 index 0000000..1df5663 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/no_serv_v4v6.exp @@ -0,0 +1,16 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host ::1 serv (empty) +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host 127.0.0.1 serv (empty) +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv 0 +ai2: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv 0 +ai3: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv 0 +ai4: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host (empty) serv (empty) +hostname nor servname provided, or not known diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/scoped.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/scoped.exp new file mode 100644 index 0000000..d06d163 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/scoped.exp @@ -0,0 +1,4 @@ +arg: flags 0x2 family 0 socktype 0 protocol 0 addrlen 0 host fe80::1%lo0 serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host fe80::1%lo0 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host fe80::1%lo0 serv http + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4.exp new file mode 100644 index 0000000..bc850e0 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4.exp @@ -0,0 +1,13 @@ +arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 +servname not supported for ai_socktype +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www +servname not supported for ai_socktype +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) +ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4v6.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4v6.exp new file mode 100644 index 0000000..a4f2fb8 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/sock_raw_v4v6.exp @@ -0,0 +1,15 @@ +arg: flags 0x2 family 0 socktype 3 protocol 0 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 24 socktype 3 protocol 0 addrlen 28 host ::1 serv 0 +ai2: flags 0x2 family 2 socktype 3 protocol 0 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv (empty) +ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 +ai2: flags 0x2 family 2 socktype 3 protocol 59 addrlen 16 host 127.0.0.1 serv 0 + +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv 80 +servname not supported for ai_socktype +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host localhost serv www +servname not supported for ai_socktype +arg: flags 0x2 family 0 socktype 3 protocol 59 addrlen 0 host ::1 serv (empty) +ai1: flags 0x2 family 24 socktype 3 protocol 59 addrlen 28 host ::1 serv 0 + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4.exp new file mode 100644 index 0000000..1c0ce43 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4.exp @@ -0,0 +1,6 @@ +arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http +No address associated with hostname diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4v6.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4v6.exp new file mode 100644 index 0000000..e24036e --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/spec_fam_v4v6.exp @@ -0,0 +1,8 @@ +arg: flags 0x2 family 2 socktype 0 protocol 0 addrlen 0 host localhost serv http +ai1: flags 0x2 family 2 socktype 2 protocol 17 addrlen 16 host 127.0.0.1 serv http +ai2: flags 0x2 family 2 socktype 1 protocol 6 addrlen 16 host 127.0.0.1 serv http + +arg: flags 0x2 family 24 socktype 0 protocol 0 addrlen 0 host localhost serv http +ai1: flags 0x2 family 24 socktype 2 protocol 17 addrlen 28 host ::1 serv http +ai2: flags 0x2 family 24 socktype 1 protocol 6 addrlen 28 host ::1 serv http + diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh new file mode 100755 index 0000000..94a3c0b --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/t_getaddrinfo.sh @@ -0,0 +1,198 @@ +# $NetBSD: t_getaddrinfo.sh,v 1.2 2011/06/15 07:54:32 jmmv Exp $ + +# +# Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, and 2002 WIDE Project. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the project nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# + +check_output() +{ + if [ "$2" = "none" ] ; then + exp="${1}.exp" + elif [ "$2" = "hosts" ] ; then + # Determine if localhost has an IPv6 address or not + lcl=$( cat /etc/hosts | \ + sed -e 's/#.*$//' -e 's/[ ][ ]*/ /g' | \ + awk '/ localhost($| )/ {printf "%s ", $1}' ) + if [ "${lcl%*::*}" = "${lcl}" ] ; then + exp="${1}_v4.exp" + else + exp="${1}_v4v6.exp" + fi + elif [ "$2" = "ifconfig" ] ; then + lcl=$( ifconfig lo0 | grep inet6 ) + if [ -n "${lcl}" ] ; then + exp="${1}_v4v6.exp" + else + exp="${1}_v4.exp" + fi + else + atf_fail "Invalid family_match_type $2 requested." + fi + + cmp -s $(atf_get_srcdir)/data/${exp} out && return + diff -u $(atf_get_srcdir)/data/${exp} out && \ + atf_fail "Actual output does not match expected output" +} + +atf_test_case basic +basic_head() +{ + atf_set "descr" "Testing basic ones" +} +basic_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST ::1 http + $TEST 127.0.0.1 http + $TEST localhost http + $TEST ::1 tftp + $TEST 127.0.0.1 tftp + $TEST localhost tftp + $TEST ::1 echo + $TEST 127.0.0.1 echo + $TEST localhost echo ) > out 2>&1 + + check_output basics hosts +} + +atf_test_case specific +specific_head() +{ + atf_set "descr" "Testing specific address family" +} +specific_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST -4 localhost http + $TEST -6 localhost http ) > out 2>&1 + + check_output spec_fam hosts +} + +atf_test_case empty_hostname +empty_hostname_head() +{ + atf_set "descr" "Testing empty hostname" +} +empty_hostname_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST '' http + $TEST '' echo + $TEST '' tftp + $TEST '' 80 + $TEST -P '' http + $TEST -P '' echo + $TEST -P '' tftp + $TEST -P '' 80 + $TEST -S '' 80 + $TEST -D '' 80 ) > out 2>&1 + + check_output no_host ifconfig +} + +atf_test_case empty_servname +empty_servname_head() +{ + atf_set "descr" "Testing empty service name" +} +empty_servname_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST ::1 '' + $TEST 127.0.0.1 '' + $TEST localhost '' + $TEST '' '' ) > out 2>&1 + + check_output no_serv hosts +} + +atf_test_case sock_raw +sock_raw_head() +{ + atf_set "descr" "Testing raw socket" +} +sock_raw_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST -R -p 0 localhost '' + $TEST -R -p 59 localhost '' + $TEST -R -p 59 localhost 80 + $TEST -R -p 59 localhost www + $TEST -R -p 59 ::1 '' ) > out 2>&1 + + check_output sock_raw hosts +} + +atf_test_case unsupported_family +unsupported_family_head() +{ + atf_set "descr" "Testing unsupported family" +} +unsupported_family_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST -f 99 localhost '' ) > out 2>&1 + + check_output unsup_fam none +} + +atf_test_case scopeaddr +scopeaddr_head() +{ + atf_set "descr" "Testing scoped address format" +} +scopeaddr_body() +{ + TEST=$(atf_get_srcdir)/h_gai + + ( $TEST fe80::1%lo0 http +# IF=`ifconfig -a | grep -v '^ ' | \ +# sed -e 's/:.*//' | head -1 | awk '{print $1}'` +# $TEST fe80::1%$IF http + ) > out 2>&1 + + check_output scoped none +} + +atf_init_test_cases() +{ + atf_add_test_case basic + atf_add_test_case specific + atf_add_test_case empty_hostname + atf_add_test_case empty_servname + atf_add_test_case sock_raw + atf_add_test_case unsupported_family + atf_add_test_case scopeaddr +} diff --git a/contrib/netbsd-tests/lib/libc/net/getaddrinfo/unsup_fam.exp b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/unsup_fam.exp new file mode 100644 index 0000000..b6133c0 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/getaddrinfo/unsup_fam.exp @@ -0,0 +1,2 @@ +arg: flags 0x2 family 99 socktype 0 protocol 0 addrlen 0 host localhost serv (empty) +ai_family not supported diff --git a/contrib/netbsd-tests/lib/libc/net/h_dns_server.c b/contrib/netbsd-tests/lib/libc/net/h_dns_server.c new file mode 100644 index 0000000..47472de --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/h_dns_server.c @@ -0,0 +1,298 @@ +/* $NetBSD: h_dns_server.c,v 1.4 2014/03/29 16:10:54 gson Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andreas Gustafsson. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * A minimal DNS server capable of providing canned answers to the + * specific queries issued by t_hostent.sh and nothing more. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: h_dns_server.c,v 1.4 2014/03/29 16:10:54 gson Exp $"); + +#include <ctype.h> +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <memory.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <sys/socket.h> + +#include <netinet/in.h> +#include <netinet6/in6.h> + +union sockaddr_either { + struct sockaddr s; + struct sockaddr_in sin; + struct sockaddr_in6 sin6; +}; + +#ifdef DEBUG +#define DPRINTF(...) fprintf(stderr, __VA_ARGS__) +#else +#define DPRINTF(...) +#endif + +/* A DNS question and its corresponding answer */ + +struct dns_data { + size_t qname_size; + const char *qname; /* Wire-encode question name */ + int qtype; + size_t answer_size; + const char *answer; /* One wire-encoded answer RDATA */ +}; + +/* Convert C string constant to length + data pair */ +#define STR_DATA(s) sizeof(s) - 1, s + +/* Canned DNS queestion-answer pairs */ +struct dns_data data[] = { + /* Forward mappings */ + /* localhost IN A -> 127.0.0.1 */ + { STR_DATA("\011localhost\000"), 1, + STR_DATA("\177\000\000\001") }, + /* localhost IN AAAA -> ::1 */ + { STR_DATA("\011localhost\000"), 28, + STR_DATA("\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\001") }, + /* sixthavenue.astron.com IN A -> 38.117.134.16 */ + { STR_DATA("\013sixthavenue\006astron\003com\000"), 1, + STR_DATA("\046\165\206\020") }, + /* sixthavenue.astron.com IN AAAA -> 2620:106:3003:1f00:3e4a:92ff:fef4:e180 */ + { STR_DATA("\013sixthavenue\006astron\003com\000"), 28, + STR_DATA("\x26\x20\x01\x06\x30\x03\x1f\x00\x3e\x4a\x92\xff\xfe\xf4\xe1\x80") }, + /* Reverse mappings */ + { STR_DATA("\0011\0010\0010\003127\007in-addr\004arpa\000"), 12, + STR_DATA("\011localhost\000") }, + { STR_DATA("\0011\0010\0010\0010\0010\0010\0010\0010" + "\0010\0010\0010\0010\0010\0010\0010\0010" + "\0010\0010\0010\0010\0010\0010\0010\0010" + "\0010\0010\0010\0010\0010\0010\0010\0010" + "\003ip6\004arpa\000"), 12, + STR_DATA("\011localhost\000") }, + { STR_DATA("\00216\003134\003117\00238" + "\007in-addr\004arpa\000"), 12, + STR_DATA("\013sixthavenue\006astron\003com\000") }, + { STR_DATA("\0010\0018\0011\001e\0014\001f\001e\001f" + "\001f\001f\0012\0019\001a\0014\001e\0013" + "\0010\0010\001f\0011\0013\0010\0010\0013" + "\0016\0010\0011\0010\0010\0012\0016\0012" + "\003ip6\004arpa\000"), 12, + STR_DATA("\013sixthavenue\006astron\003com\000") }, + /* End marker */ + { STR_DATA(""), 0, STR_DATA("") } +}; + +/* + * Compare two DNS names for equality. If equal, return their + * length, and if not, return zero. Does not handle compression. + */ +static int +name_eq(const unsigned char *a, const unsigned char *b) { + const unsigned char *a_save = a; + for (;;) { + int i; + int lena = *a++; + int lenb = *b++; + if (lena != lenb) + return 0; + if (lena == 0) + return a - a_save; + for (i = 0; i < lena; i++) + if (tolower(a[i]) != tolower(b[i])) + return 0; + a += lena; + b += lena; + } +} + +#ifdef DEBUG +static char * +name2str(const void *v, char *buf, size_t buflen) { + const unsigned char *a = v; + char *b = buf; + char *eb = buf + buflen; + +#define ADDC(c) do { \ + if (b < eb) \ + *b++ = c; \ + else \ + return NULL; \ + } while (/*CONSTCOND*/0) + for (int did = 0;; did++) { + int lena = *a++; + if (lena == 0) { + ADDC('\0'); + return buf; + } + if (did) + ADDC('.'); + for (int i = 0; i < lena; i++) + ADDC(a[i]); + a += lena; + } +} +#endif + +int main(int argc, char **argv) { + int s, r, protocol; + union sockaddr_either saddr; + struct dns_data *dp; + unsigned char *p; + char pidfile_name[40]; + FILE *f; + int one = 1; +#ifdef DEBUG + char buf1[1024], buf2[1024]; +#endif + + if (argc < 2 || ((protocol = argv[1][0]) != '4' && protocol != '6')) + errx(1, "usage: dns_server 4 | 6"); + s = socket(protocol == '4' ? PF_INET : PF_INET6, SOCK_DGRAM, IPPROTO_UDP); + if (s < 0) + err(1, "socket"); + if (protocol == '4') { + memset(&saddr.sin, 0, sizeof(saddr.sin)); + saddr.sin.sin_family = AF_INET; + saddr.sin.sin_len = sizeof(saddr.sin); + saddr.sin.sin_port = htons(53); + saddr.sin.sin_addr.s_addr = INADDR_ANY; + } else { + static struct in6_addr loopback = IN6ADDR_LOOPBACK_INIT; + memset(&saddr.sin6, 0, sizeof(saddr.sin6)); + saddr.sin6.sin6_family = AF_INET6; + saddr.sin6.sin6_len = sizeof(saddr.sin6); + saddr.sin6.sin6_port = htons(53); + saddr.sin6.sin6_addr = loopback; + } + + r = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + if (r < 0) + err(1, "setsockopt"); + + r = bind(s, + (struct sockaddr *) &saddr, + protocol == '4' ? sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6)); + if (r < 0) + err(1, "bind"); + + snprintf(pidfile_name, sizeof pidfile_name, + "dns_server_%c.pid", protocol); + f = fopen(pidfile_name, "w"); + fprintf(f, "%d", getpid()); + fclose(f); +#ifdef DEBUG + daemon(0, 1); +#else + daemon(0, 0); +#endif + + for (;;) { + unsigned char buf[512]; + union sockaddr_either from; + ssize_t nrecv, nsent; + socklen_t fromlen = + protocol == '4' ? sizeof(struct sockaddr_in) : + sizeof(struct sockaddr_in6); + memset(buf, 0, sizeof buf); + nrecv = recvfrom(s, buf, sizeof buf, 0, &from.s, &fromlen); + if (nrecv < 0) + err(1, "recvfrom"); + if (nrecv < 12) { + DPRINTF("Too short %zd\n", nrecv); + continue; + } + if ((buf[2] & 0x80) != 0) { + DPRINTF("Not a query 0x%x\n", buf[2]); + continue; + } + if (!(buf[4] == 0 && buf[5] == 1)) { + DPRINTF("QCOUNT is not 1 0x%x 0x%x\n", buf[4], buf[5]); + continue; /* QDCOUNT is not 1 */ + } + + for (dp = data; dp->qname_size != 0; dp++) { + int qtype, qclass; + p = buf + 12; /* Point to QNAME */ + int n = name_eq(p, (const unsigned char *) dp->qname); + if (n == 0) { + DPRINTF("no match name %s != %s\n", + name2str(p, buf1, sizeof(buf1)), + name2str(dp->qname, buf2, sizeof(buf2))); + continue; /* Name does not match */ + } + DPRINTF("match name %s\n", + name2str(p, buf1, sizeof(buf1))); + p += n; /* Skip QNAME */ + qtype = *p++ << 8; + qtype |= *p++; + if (qtype != dp->qtype) { + DPRINTF("no match name 0x%x != 0x%x\n", + qtype, dp->qtype); + continue; + } + DPRINTF("match type 0x%x\n", qtype); + qclass = *p++ << 8; + qclass |= *p++; + if (qclass != 1) { /* IN */ + DPRINTF("no match class %d != 1\n", qclass); + continue; + } + DPRINTF("match class %d\n", qclass); + goto found; + } + continue; + found: + buf[2] |= 0x80; /* QR */ + buf[3] |= 0x80; /* RA */ + memset(buf + 6, 0, 6); /* Clear ANCOUNT, NSCOUNT, ARCOUNT */ + buf[7] = 1; /* ANCOUNT */ + memcpy(p, dp->qname, dp->qname_size); + p += dp->qname_size; + *p++ = dp->qtype >> 8; + *p++ = dp->qtype & 0xFF; + *p++ = 0; + *p++ = 1; /* IN */ + memset(p, 0, 4); /* TTL = 0 */ + p += 4; + *p++ = 0; /* RDLENGTH MSB */ + *p++ = dp->answer_size; /* RDLENGTH LSB */ + memcpy(p, dp->answer, dp->answer_size); + p += dp->answer_size; + nsent = sendto(s, buf, p - buf, 0, &from.s, fromlen); + DPRINTF("sent %zd\n", nsent); + if (nsent != p - buf) + warn("sendto"); + } +} diff --git a/contrib/netbsd-tests/lib/libc/net/h_hostent.c b/contrib/netbsd-tests/lib/libc/net/h_hostent.c new file mode 100644 index 0000000..4a72923 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/h_hostent.c @@ -0,0 +1,195 @@ +/* $NetBSD: h_hostent.c,v 1.2 2014/01/09 02:18:10 christos Exp $ */ + +/*- + * Copyright (c) 2013 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: h_hostent.c,v 1.2 2014/01/09 02:18:10 christos Exp $"); + +#include <stdio.h> +#include <string.h> +#include <nsswitch.h> +#include <netdb.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <err.h> + +#include <netinet/in.h> +#include <sys/types.h> +#include <arpa/nameser.h> +#include <arpa/inet.h> + +#include "hostent.h" + +extern const char *__res_conf_name; + +static void +phostent(const struct hostent *h) +{ + size_t i; + char buf[1024]; + const int af = h->h_length == NS_INADDRSZ ? AF_INET : AF_INET6; + + printf("name=%s, length=%d, addrtype=%d, aliases=[", + h->h_name, h->h_length, h->h_addrtype); + + for (i = 0; h->h_aliases[i]; i++) + printf("%s%s", i == 0 ? "" : " ", h->h_aliases[i]); + + printf("] addr_list=["); + + for (i = 0; h->h_addr_list[i]; i++) + printf("%s%s", i == 0 ? "" : " ", inet_ntop(af, + h->h_addr_list[i], buf, (socklen_t)sizeof(buf))); + + printf("]\n"); +} + +static void +usage(void) +{ + (void)fprintf(stderr, "Usage: %s [-f <hostsfile>] " + "[-t <any|dns|nis|files>] " + "[-46a] <name|address>\n", getprogname()); + exit(EXIT_FAILURE); +} + +static void +getby(int (*f)(void *, void *, va_list), struct getnamaddr *info, ...) +{ + va_list ap; + int e; + + va_start(ap, info); + e = (*f)(info, NULL, ap); + va_end(ap); + switch (e) { + case NS_SUCCESS: + phostent(info->hp); + break; + default: + printf("error %d\n", e); + break; + } +} + +static void +geta(struct hostent *hp) { + if (hp == NULL) + printf("error %d\n", h_errno); + else + phostent(hp); +} + +int +main(int argc, char *argv[]) +{ + int (*f)(void *, void *, va_list) = NULL; + const char *type = "any"; + int c, af, e, byaddr, len; + struct hostent hent; + struct getnamaddr info; + char buf[4096]; + + af = AF_INET; + byaddr = 0; + len = 0; + info.hp = &hent; + info.buf = buf; + info.buflen = sizeof(buf); + info.he = &e; + + while ((c = getopt(argc, argv, "46af:r:t:")) != -1) { + switch (c) { + case '4': + af = AF_INET; + break; + case '6': + af = AF_INET6; + break; + case 'a': + byaddr++; + break; + case 'f': + _hf_sethostsfile(optarg); + break; + case 'r': + __res_conf_name = optarg; + break; + case 't': + type = optarg; + break; + default: + usage(); + } + } + + argc -= optind; + argv += optind; + + if (argc != 1) + usage(); + + switch (*type) { + case 'a': + break; + case 'd': + f = byaddr ? _dns_gethtbyaddr : _dns_gethtbyname; + break; +#ifdef YP + case 'n': + f = byaddr ? _yp_gethtbyaddr : _yp_gethtbyname; + break; +#endif + case 'f': + f = byaddr ? _hf_gethtbyaddr : _hf_gethtbyname; + break; + default: + errx(EXIT_FAILURE, "Unknown db type `%s'", type); + } + + if (byaddr) { + struct in6_addr addr; + af = strchr(*argv, ':') ? AF_INET6 : AF_INET; + len = af == AF_INET ? NS_INADDRSZ : NS_IN6ADDRSZ; + if (inet_pton(af, *argv, &addr) == -1) + err(EXIT_FAILURE, "Can't parse `%s'", *argv); + if (*type == 'a') + geta(gethostbyaddr((const char *)&addr, len, af)); + else + getby(f, &info, &addr, len, af); + } else { + if (*type == 'a') + geta(gethostbyname2(*argv, af)); + else + getby(f, &info, *argv, len, af); + } + + return 0; +} diff --git a/contrib/netbsd-tests/lib/libc/net/h_nsd_recurse.c b/contrib/netbsd-tests/lib/libc/net/h_nsd_recurse.c new file mode 100644 index 0000000..2f315d2 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/h_nsd_recurse.c @@ -0,0 +1,107 @@ +/* $NetBSD: h_nsd_recurse.c,v 1.2 2011/01/13 02:24:51 pgoyette Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__COPYRIGHT("@(#) Copyright (c) 2008\ + The NetBSD Foundation, inc. All rights reserved."); +__RCSID("$NetBSD: h_nsd_recurse.c,v 1.2 2011/01/13 02:24:51 pgoyette Exp $"); + +#define _REENTRANT + +#include <assert.h> +#include <nsswitch.h> +#include <pthread.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> + +static const ns_src testsrc[] = { + { "test", NS_SUCCESS }, + { NULL, 0 } +}; + +static int +func3(void *rv, void *cb_data, va_list ap) +{ + (void)printf("func3: enter\n"); + (void)printf("func3: exit\n"); + + return NS_SUCCESS; +} + +static int +func2(void *rv, void *cb_data, va_list ap) +{ + static const ns_dtab dtab[] = { + { "test", func3, NULL }, + { NULL, NULL, NULL } + }; + int r; + + (void)printf("func2: enter\n"); + r = nsdispatch(NULL, dtab, "test", "test", testsrc); + (void)printf("func2: exit\n"); + + return r; +} + +static int +func1(void) +{ + static const ns_dtab dtab[] = { + { "test", func2, NULL }, + { NULL, NULL, NULL } + }; + int r; + + (void)printf("func1: enter\n"); + r = nsdispatch(NULL, dtab, "test", "test", testsrc); + (void)printf("func1: exit\n"); + + return r; +} + +static void * +thrfunc(void *arg) +{ + pthread_exit(NULL); +} + +int +main(int argc, char *argv[]) +{ + pthread_t thr; + void *threval; + + assert(pthread_create(&thr, NULL, thrfunc, NULL) == 0); + assert(func1() == NS_SUCCESS); + assert(pthread_join(thr, &threval) == 0); +} diff --git a/contrib/netbsd-tests/lib/libc/net/h_protoent.c b/contrib/netbsd-tests/lib/libc/net/h_protoent.c new file mode 100644 index 0000000..f37a85c --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/h_protoent.c @@ -0,0 +1,97 @@ +/* $NetBSD: h_protoent.c,v 1.2 2011/04/07 18:14:09 jruoho Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <netdb.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <stdio.h> + +static void +pserv(const struct protoent *prp) +{ + char **pp; + + printf("name=%s, proto=%d, aliases=", + prp->p_name, prp->p_proto); + for (pp = prp->p_aliases; *pp; pp++) + printf("%s ", *pp); + printf("\n"); +} + +static void +usage(void) +{ + (void)fprintf(stderr, "Usage: %s\n" + "\t%s -p <proto>\n" + "\t%s -n <name>\n", getprogname(), getprogname(), + getprogname()); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + struct protoent *prp; + const char *proto = NULL, *name = NULL; + int c; + + while ((c = getopt(argc, argv, "p:n:")) != -1) { + switch (c) { + case 'n': + name = optarg; + break; + case 'p': + proto = optarg; + break; + default: + usage(); + } + } + + if (proto && name) + usage(); + if (proto) { + if ((prp = getprotobynumber(atoi(proto))) != NULL) + pserv(prp); + return 0; + } + if (name) { + if ((prp = getprotobyname(name)) != NULL) + pserv(prp); + return 0; + } + + setprotoent(0); + while ((prp = getprotoent()) != NULL) + pserv(prp); + endprotoent(); + return 0; +} diff --git a/contrib/netbsd-tests/lib/libc/net/h_servent.c b/contrib/netbsd-tests/lib/libc/net/h_servent.c new file mode 100644 index 0000000..6d7efd8 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/h_servent.c @@ -0,0 +1,100 @@ +/* $NetBSD: h_servent.c,v 1.2 2011/04/07 18:14:09 jruoho Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <netdb.h> +#include <stdint.h> +#include <stdlib.h> +#include <unistd.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <stdio.h> + +static void +pserv(const struct servent *svp) +{ + char **pp; + + printf("name=%s, port=%d, proto=%s, aliases=", + svp->s_name, ntohs((uint16_t)svp->s_port), svp->s_proto); + for (pp = svp->s_aliases; *pp; pp++) + printf("%s ", *pp); + printf("\n"); +} + +static void +usage(void) +{ + (void)fprintf(stderr, "Usage: %s\n" + "\t%s -p <port> [-P <proto>]\n" + "\t%s -n <name> [-P <proto>]\n", getprogname(), getprogname(), + getprogname()); + exit(1); +} + +int +main(int argc, char *argv[]) +{ + struct servent *svp; + const char *port = NULL, *proto = NULL, *name = NULL; + int c; + + while ((c = getopt(argc, argv, "p:n:P:")) != -1) { + switch (c) { + case 'n': + name = optarg; + break; + case 'p': + port = optarg; + break; + case 'P': + proto = optarg; + break; + default: + usage(); + } + } + + if (port && name) + usage(); + if (port) { + if ((svp = getservbyport(htons(atoi(port)), proto)) != NULL) + pserv(svp); + return 0; + } + if (name) { + if ((svp = getservbyname(name, proto)) != NULL) + pserv(svp); + return 0; + } + + setservent(0); + while ((svp = getservent()) != NULL) + pserv(svp); + endservent(); + return 0; +} diff --git a/contrib/netbsd-tests/lib/libc/net/hosts b/contrib/netbsd-tests/lib/libc/net/hosts new file mode 100644 index 0000000..87ccbe8 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/hosts @@ -0,0 +1,11 @@ +# $NetBSD: hosts,v 1.1 2013/08/16 15:29:45 christos Exp $ +# +# Host Database +# This file should contain the addresses and aliases +# for local hosts that share this file. +# It is used only for "ifconfig" and other operations +# before the nameserver is started. +# +# +::1 localhost localhost. localhost.localdomain. +127.0.0.1 localhost localhost. localhost.localdomain. diff --git a/contrib/netbsd-tests/lib/libc/net/resolv.conf b/contrib/netbsd-tests/lib/libc/net/resolv.conf new file mode 100644 index 0000000..bbc8559 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/resolv.conf @@ -0,0 +1 @@ +nameserver 127.0.0.1 diff --git a/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c b/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c new file mode 100644 index 0000000..6ca3c5b --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_ether_aton.c @@ -0,0 +1,104 @@ +/* $NetBSD: t_ether_aton.c,v 1.1 2011/11/01 22:36:53 pgoyette Exp $ */ + +/*- + * Copyright (c) 2010 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_ether_aton.c,v 1.1 2011/11/01 22:36:53 pgoyette Exp $"); + +#include <atf-c.h> +#include <stdio.h> +#include <ctype.h> +#include <sys/types.h> +#include <err.h> +#include <string.h> +#include <errno.h> + +#define ETHER_ADDR_LEN 6 + +int ether_aton_r(u_char *dest, size_t len, const char *str); + +static const struct { + u_char res[ETHER_ADDR_LEN]; + const char *str; + int error; +} tests[] = { + { { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab }, "01:23:45:67:89:ab", 0 }, + { { 0x00, 0x01, 0x22, 0x03, 0x14, 0x05 }, "0:1:22-3:14:05", 0 }, + { { 0x00, 0x01, 0x22, 0x03, 0x14, 0x05 }, "000122031405", 0 }, + { { 0x0a, 0x0B, 0xcc, 0xdD, 0xEE, 0x0f }, "0a0BccdDEE0f", 0 }, +#define ZERO { 0, 0, 0, 0, 0, 0 } + { ZERO, "0:1:2-3:04:05:06", ENAMETOOLONG }, + { ZERO, "0:1:2-3:04:", ENOBUFS }, + { ZERO, "0:1:2-3:04:x7", EINVAL }, + { ZERO, "1:x-3:04:05:7", EINVAL }, + { ZERO, NULL, 0 }, +}; + +ATF_TC(tc_ether_aton); +ATF_TC_HEAD(tc_ether_aton, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that ether_aton(3) works"); +} + +ATF_TC_BODY(tc_ether_aton, tc) +{ + u_char dest[ETHER_ADDR_LEN]; + size_t t; + int e, r; + const char *s; + + for (t = 0; tests[t].str; t++) { + s = tests[t].str; + if ((e = tests[t].error) == 0) { + if (ether_aton_r(dest, sizeof(dest), s) != e) + atf_tc_fail("failed on `%s'", s); + if (memcmp(dest, tests[t].res, sizeof(dest)) != 0) + atf_tc_fail("unexpected result on `%s'", s); + } else { + if ((r = ether_aton_r(dest, sizeof(dest), s)) != e) + atf_tc_fail("unexpectedly succeeded on `%s' " + "(%d != %d)", s, r, e); + } + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, tc_ether_aton); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libc/net/t_getprotoent.c b/contrib/netbsd-tests/lib/libc/net/t_getprotoent.c new file mode 100644 index 0000000..1c1a0e0 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_getprotoent.c @@ -0,0 +1,233 @@ +/* $NetBSD: t_getprotoent.c,v 1.2 2012/04/04 10:03:53 joerg Exp $ */ + +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jukka Ruohonen. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_getprotoent.c,v 1.2 2012/04/04 10:03:53 joerg Exp $"); + +#include <atf-c.h> +#include <netdb.h> +#include <limits.h> +#include <stdio.h> +#include <string.h> + +static const struct { + const char *name; + int number; +} protos[] = { + + { "icmp", 1 }, { "tcp", 6 }, { "udp", 17 }, { "gre", 47 }, + { "esp", 50 }, { "ah", 51 }, { "sctp", 132}, { "ipv6-icmp", 58 } +}; + +ATF_TC(endprotoent_rewind); +ATF_TC_HEAD(endprotoent_rewind, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that endprotoent(3) rewinds"); +} + +ATF_TC_BODY(endprotoent_rewind, tc) +{ + struct protoent *p; + int i = 0; + + setprotoent(0); + + while ((p = getprotoent()) != NULL && i <= 10) { + ATF_REQUIRE(p->p_proto == i); + i++; + } + + i = 0; + endprotoent(); + + while ((p = getprotoent()) != NULL && i <= 10) { + ATF_REQUIRE(p->p_proto == i); + i++; + } + + endprotoent(); +} + +ATF_TC(getprotobyname_basic); +ATF_TC_HEAD(getprotobyname_basic, tc) +{ + atf_tc_set_md_var(tc, "descr", "A naive test of getprotobyname(3)"); +} + +ATF_TC_BODY(getprotobyname_basic, tc) +{ + struct protoent *p; + size_t i; + + for (i = 0; i < __arraycount(protos); i++) { + + p = getprotobyname(protos[i].name); + + ATF_REQUIRE(p != NULL); + ATF_REQUIRE(p->p_proto == protos[i].number); + ATF_REQUIRE(strcmp(p->p_name, protos[i].name) == 0); + } + + endprotoent(); +} + +ATF_TC(getprotobyname_err); +ATF_TC_HEAD(getprotobyname_err, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test EOF from getprotobyname(3)"); +} + +ATF_TC_BODY(getprotobyname_err, tc) +{ + static const char * name[] = + { "xxx", "yyy", "xyz", ".as.d}9x.._?!!#\xa4,\xa8^//&%%,", + "0", "", "tCp", "uDp", "t c p", "tcp ", " tcp" }; + + size_t i; + + for (i = 0; i < __arraycount(name); i++) + ATF_REQUIRE(getprotobyname(name[i]) == NULL); + + endprotoent(); +} + +ATF_TC(getprotobynumber_basic); +ATF_TC_HEAD(getprotobynumber_basic, tc) +{ + atf_tc_set_md_var(tc, "descr", "A naive test of getprotobynumber(3)"); +} + +ATF_TC_BODY(getprotobynumber_basic, tc) +{ + struct protoent *p; + size_t i; + + /* + * No ATF_CHECK() due static storage. + */ + for (i = 0; i < __arraycount(protos); i++) { + + p = getprotobynumber(protos[i].number); + + ATF_REQUIRE(p != NULL); + ATF_REQUIRE(p->p_proto == protos[i].number); + ATF_REQUIRE(strcmp(p->p_name, protos[i].name) == 0); + } + + endprotoent(); +} + +ATF_TC(getprotobynumber_err); +ATF_TC_HEAD(getprotobynumber_err, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test EOF from getprotobynumber(3)"); +} + +ATF_TC_BODY(getprotobynumber_err, tc) +{ + static const int number[] = { -1, -99999, INT_MAX, 1000000000 }; + size_t i; + + for (i = 0; i < __arraycount(number); i++) + ATF_REQUIRE(getprotobynumber(number[i]) == NULL); + + endprotoent(); +} + +ATF_TC(getprotoent_next); +ATF_TC_HEAD(getprotoent_next, tc) +{ + atf_tc_set_md_var(tc, "descr", "getprotoent(3) returns next line?"); +} + +ATF_TC_BODY(getprotoent_next, tc) +{ + struct protoent *p; + int i = 0; + + /* + * The range [0, 60] is already reserved by IANA. + */ + while ((p = getprotoent()) != NULL && i <= 60) { + ATF_CHECK(p->p_proto == i); + i++; + } + + endprotoent(); +} + +ATF_TC(setprotoent_rewind); +ATF_TC_HEAD(setprotoent_rewind, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that setprotoent(3) rewinds"); +} + +ATF_TC_BODY(setprotoent_rewind, tc) +{ + struct protoent *p; + + setprotoent(0); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 0); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 1); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 2); + + setprotoent(0); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 0); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 1); + + p = getprotoent(); + ATF_REQUIRE(p->p_proto == 2); + + endprotoent(); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, getprotobyname_basic); + ATF_TP_ADD_TC(tp, getprotobyname_err); + ATF_TP_ADD_TC(tp, getprotobynumber_basic); + ATF_TP_ADD_TC(tp, getprotobynumber_err); + ATF_TP_ADD_TC(tp, endprotoent_rewind); + ATF_TP_ADD_TC(tp, getprotoent_next); + ATF_TP_ADD_TC(tp, setprotoent_rewind); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libc/net/t_hostent.sh b/contrib/netbsd-tests/lib/libc/net/t_hostent.sh new file mode 100755 index 0000000..b597b6d --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_hostent.sh @@ -0,0 +1,240 @@ +# $NetBSD: t_hostent.sh,v 1.10 2014/01/13 11:08:14 gson Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +n6="sixthavenue.astron.com" +a6="2620:106:3003:1f00:3e4a:92ff:fef4:e180" +ans6="name=$n6, length=16, addrtype=24, aliases=[] addr_list=[$a6]\n" + +n4="sixthavenue.astron.com" +a4="38.117.134.16" +ans4="name=$n4, length=4, addrtype=2, aliases=[] addr_list=[$a4]\n" + +l6="localhost" +al6="::1" +loc6="name=$l6, length=16, addrtype=24, aliases=[localhost. localhost.localdomain.] addr_list=[$al6]\n" + +l4="localhost" +al4="127.0.0.1" +loc4="name=$l4, length=4, addrtype=2, aliases=[localhost. localhost.localdomain.] addr_list=[$al4]\n" + +dir="$(atf_get_srcdir)" +res="-r ${dir}/resolv.conf" + +# Hijack DNS traffic using a single rump server instance and a DNS +# server listening on its loopback address. + +start_dns_server() { + export RUMP_SERVER=unix:///tmp/rumpserver + rump_server -lrumpdev -lrumpnet -lrumpnet_net -lrumpnet_netinet \ + -lrumpnet_netinet6 -lrumpnet_local $RUMP_SERVER + HIJACK_DNS="LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK='socket=inet:inet6'" + eval $HIJACK_DNS ${dir}/h_dns_server $1 +} + +stop_dns_server() { + export RUMP_SERVER=unix:///tmp/rumpserver + kill $(cat dns_server_$1.pid) + rump.halt +} + +atf_test_case gethostbyname4 cleanup +gethostbyname4_head() +{ + atf_set "descr" "Checks gethostbyname2(3) for AF_INET (auto, as determined by nsswitch.conf(5)" +} +gethostbyname4_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -4 $n4" +} +gethostbyname4_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case gethostbyname6 cleanup cleanup +gethostbyname6_head() +{ + atf_set "descr" "Checks gethostbyname2(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" +} +gethostbyname6_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -6 $n6" +} +gethostbyname6_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case gethostbyaddr4 cleanup +gethostbyaddr4_head() +{ + atf_set "descr" "Checks gethostbyaddr(3) for AF_INET (auto, as determined by nsswitch.conf(5)" +} +gethostbyaddr4_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a4" +} +gethostbyaddr4_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case gethostbyaddr6 cleanup +gethostbyaddr6_head() +{ + atf_set "descr" "Checks gethostbyaddr(3) for AF_INET6 (auto, as determined by nsswitch.conf(5)" +} +gethostbyaddr6_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t auto -a $a6" +} +gethostbyaddr6_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case hostsbynamelookup4 +hostsbynamelookup4_head() +{ + atf_set "descr" "Checks /etc/hosts name lookup for AF_INET" +} +hostsbynamelookup4_body() +{ + atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 $l4" +} + +atf_test_case hostsbynamelookup6 +hostsbynamelookup6_head() +{ + atf_set "descr" "Checks /etc/hosts name lookup for AF_INET6" +} +hostsbynamelookup6_body() +{ + atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 $l6" +} + +atf_test_case hostsbyaddrlookup4 +hostsbyaddrlookup4_head() +{ + atf_set "descr" "Checks /etc/hosts address lookup for AF_INET" +} +hostsbyaddrlookup4_body() +{ + atf_check -o inline:"$loc4" -x "${dir}/h_hostent -f ${dir}/hosts -t file -4 -a $al4" +} + +atf_test_case hostsbyaddrlookup6 +hostsbyaddrlookup6_head() +{ + atf_set "descr" "Checks /etc/hosts address lookup for AF_INET6" +} +hostsbyaddrlookup6_body() +{ + atf_check -o inline:"$loc6" -x "${dir}/h_hostent -f ${dir}/hosts -t file -6 -a $al6" +} + +atf_test_case dnsbynamelookup4 cleanup +dnsbynamelookup4_head() +{ + atf_set "descr" "Checks DNS name lookup for AF_INET" +} +dnsbynamelookup4_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 $n4" +} +dnsbynamelookup4_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case dnsbynamelookup6 cleanup +dnsbynamelookup6_head() +{ + atf_set "descr" "Checks DNS name lookup for AF_INET6" +} +dnsbynamelookup6_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 $n6" +} +dnsbynamelookup6_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case dnsbyaddrlookup4 cleanup +dnsbyaddrlookup4_head() +{ + atf_set "descr" "Checks DNS address lookup for AF_INET" +} +dnsbyaddrlookup4_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans4" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -4 -a $a4" +} +dnsbyaddrlookup4_cleanup() +{ + stop_dns_server 4 +} + +atf_test_case dnsbyaddrlookup6 cleanup +dnsbyaddrlookup6_head() +{ + atf_set "descr" "Checks dns address lookup for AF_INET6" +} +dnsbyaddrlookup6_body() +{ + start_dns_server 4 + atf_check -o inline:"$ans6" -x "$HIJACK_DNS ${dir}/h_hostent ${res} -t dns -6 -a $a6" +} +dnsbyaddrlookup6_cleanup() +{ + stop_dns_server 4 +} + +atf_init_test_cases() +{ + atf_add_test_case gethostbyname4 + atf_add_test_case gethostbyname6 + atf_add_test_case gethostbyaddr4 + atf_add_test_case gethostbyaddr6 + + atf_add_test_case hostsbynamelookup4 + atf_add_test_case hostsbynamelookup6 + atf_add_test_case hostsbyaddrlookup4 + atf_add_test_case hostsbyaddrlookup6 + + atf_add_test_case dnsbynamelookup4 + atf_add_test_case dnsbynamelookup6 + atf_add_test_case dnsbyaddrlookup4 + atf_add_test_case dnsbyaddrlookup6 +} diff --git a/contrib/netbsd-tests/lib/libc/net/t_nsdispatch.sh b/contrib/netbsd-tests/lib/libc/net/t_nsdispatch.sh new file mode 100755 index 0000000..b584369 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_nsdispatch.sh @@ -0,0 +1,51 @@ +# $NetBSD: t_nsdispatch.sh,v 1.1 2011/01/13 01:56:44 pgoyette Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case recurse +recurse_head() +{ + atf_set "descr" "Checks recursive calls to nsdispatch()" \ + "within threaded program" +} +recurse_body() +{ + cat >exp <<EOF +func1: enter +func2: enter +func3: enter +func3: exit +func2: exit +func1: exit +EOF + + atf_check -o file:exp "$(atf_get_srcdir)/h_nsd_recurse" +} + +atf_init_test_cases() +{ + atf_add_test_case recurse +} diff --git a/contrib/netbsd-tests/lib/libc/net/t_protoent.sh b/contrib/netbsd-tests/lib/libc/net/t_protoent.sh new file mode 100755 index 0000000..322d426 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_protoent.sh @@ -0,0 +1,91 @@ +# $NetBSD: t_protoent.sh,v 1.2 2012/09/03 15:32:18 christos Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case protoent +protoent_head() +{ + atf_set "descr" "Checks {get,set,end}protoent(3)" +} +protoent_body() +{ + # + # Munge original to: + # (1) match output format of the test program + # (2) fold all names for the same port/proto together + # (3) prune duplicates + # + tr '\t' ' ' </etc/protocols | awk ' + function add(key, name, i, n, ar) { + n = split(names[key], ar); + for (i = 1; i <= n; i++) { + if (name == ar[i]) { + return; + } + } + delete ar; + names[key] = names[key] " " name; + } + { + sub("#.*", "", $0); + gsub(" *", " ", $0); + if (NF == 0) { + next; + } + add($2, $1, 0); + for (i = 3; i <= NF; i++) { + add($2, $i, 1); + } + } + END { + for (key in names) { + proto = key; + + n = split(names[key], ar); + printf "name=%s, proto=%s, aliases=", ar[1], proto; + for (i=2; i<=n; i++) { + if (i>2) { + printf " "; + } + printf "%s", ar[i]; + } + printf "\n"; + delete ar; + } + } + ' | sort >exp + + # run test program + "$(atf_get_srcdir)/h_protoent" | sed 's/ *$//' | sort >out + + diff -u exp out || \ + atf_fail "Observed output does not match reference output" +} + +atf_init_test_cases() +{ + atf_add_test_case protoent +} diff --git a/contrib/netbsd-tests/lib/libc/net/t_servent.sh b/contrib/netbsd-tests/lib/libc/net/t_servent.sh new file mode 100755 index 0000000..b9aa2b7 --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/net/t_servent.sh @@ -0,0 +1,93 @@ +# $NetBSD: t_servent.sh,v 1.1 2011/01/12 17:32:27 pgoyette Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case servent +servent_head() +{ + atf_set "descr" "Checks {get,set,end}servent(3)" +} +servent_body() +{ + # + # Munge original to: + # (1) match output format of the test program + # (2) fold all names for the same port/proto together + # (3) prune duplicates + # + tr '\t' ' ' </etc/services | awk ' + function add(key, name, i, n, ar) { + n = split(names[key], ar); + for (i=1; i<=n; i++) { + if (name == ar[i]) { + return; + } + } + delete ar; + names[key] = names[key] " " name; + } + + { + sub("#.*", "", $0); + gsub(" *", " ", $0); + if (NF==0) { + next; + } + add($2, $1, 0); + for (i=3; i<=NF; i++) { + add($2, $i, 1); + } + } + END { + for (key in names) { + portproto = key; + sub("/", ", proto=", portproto); + portproto = "port=" portproto; + + n = split(names[key], ar); + printf "name=%s, %s, aliases=", ar[1], portproto; + for (i=2; i<=n; i++) { + if (i>2) { + printf " "; + } + printf "%s", ar[i]; + } + printf "\n"; + delete ar; + } + } + ' | sort >exp + + # run test program + "$(atf_get_srcdir)/h_servent" | sed 's/ *$//' | sort >out + + diff -u exp out || atf_fail "Observed output does not match reference output" +} + +atf_init_test_cases() +{ + atf_add_test_case servent +} |