4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
13 int gethost(family, name, hostp)
22 bzero(hostp, sizeof(*hostp));
23 if (!strcmp(name, "test.host.dots")) {
24 if (family == AF_INET) {
25 hostp->in4.s_addr = htonl(0xfedcba98);
28 if (family == AF_INET6) {
29 hostp->i6[0] = htonl(0xfe80aa55);
30 hostp->i6[1] = htonl(0x12345678);
31 hostp->i6[2] = htonl(0x5a5aa5a5);
32 hostp->i6[3] = htonl(0xfedcba98);
38 if (!strcmp(name, "<thishost>"))
41 if (family == AF_INET) {
42 h = gethostbyname(name);
44 if ((h->h_addr != NULL) &&
45 (h->h_length == sizeof(addr))) {
46 bcopy(h->h_addr, (char *)&addr, sizeof(addr));
47 hostp->in4.s_addr = addr;
52 n = getnetbyname(name);
54 hostp->in4.s_addr = htonl(n->n_net & 0xffffffff);
59 if (family == AF_INET6) {
60 struct addrinfo hints, *res;
61 struct sockaddr_in6 *sin6;
63 bzero((char *)&hints, sizeof(hints));
64 hints.ai_family = PF_INET6;
66 getaddrinfo(name, NULL, &hints, &res);
68 sin6 = (struct sockaddr_in6 *)res->ai_addr;
69 hostp->in6 = sin6->sin6_addr;