Changeset View
Changeset View
Standalone View
Standalone View
head/lib/libc/tests/sys/sendfile_test.c
Show First 20 Lines • Show All 91 Lines • ▼ Show 20 Lines | generate_random_port(int seed) | ||||
printf("Random port generated: %d\n", random_port); | printf("Random port generated: %d\n", random_port); | ||||
return (random_port); | return (random_port); | ||||
} | } | ||||
static void | static void | ||||
resolve_localhost(struct addrinfo **res, int domain, int type, int port) | resolve_localhost(struct addrinfo **res, int domain, int type, int port) | ||||
{ | { | ||||
const char *host; | |||||
char *serv; | char *serv; | ||||
struct addrinfo hints; | struct addrinfo hints; | ||||
int error; | int error; | ||||
ATF_REQUIRE_MSG(domain == AF_INET || domain == AF_INET6, | switch (domain) { | ||||
"unhandled domain: %d", domain); | case AF_INET: | ||||
host = "127.0.0.1"; | |||||
break; | |||||
case AF_INET6: | |||||
host = "::1"; | |||||
break; | |||||
default: | |||||
atf_tc_fail("unhandled domain: %d", domain); | |||||
} | |||||
ATF_REQUIRE_MSG(asprintf(&serv, "%d", port) >= 0, | ATF_REQUIRE_MSG(asprintf(&serv, "%d", port) >= 0, | ||||
"asprintf failed: %s", strerror(errno)); | "asprintf failed: %s", strerror(errno)); | ||||
memset(&hints, 0, sizeof(hints)); | memset(&hints, 0, sizeof(hints)); | ||||
hints.ai_family = domain; | hints.ai_family = domain; | ||||
hints.ai_flags = AI_ADDRCONFIG|AI_NUMERICSERV; | hints.ai_flags = AI_ADDRCONFIG|AI_NUMERICSERV|AI_NUMERICHOST; | ||||
hints.ai_socktype = type; | hints.ai_socktype = type; | ||||
error = getaddrinfo("localhost", serv, &hints, res); | error = getaddrinfo(host, serv, &hints, res); | ||||
ATF_REQUIRE_EQ_MSG(error, 0, | ATF_REQUIRE_EQ_MSG(error, 0, | ||||
"getaddrinfo failed: %s", gai_strerror(error)); | "getaddrinfo failed: %s", gai_strerror(error)); | ||||
free(serv); | free(serv); | ||||
} | } | ||||
static int | static int | ||||
make_socket(int domain, int type, int protocol) | make_socket(int domain, int type, int protocol) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,023 Lines • Show Last 20 Lines |