141edb306SCy Schubert
241edb306SCy Schubert /*
341edb306SCy Schubert * Copyright (C) 2012 by Darren Reed.
441edb306SCy Schubert *
541edb306SCy Schubert * See the IPFILTER.LICENCE file for details on licencing.
641edb306SCy Schubert *
741edb306SCy Schubert * $Id$
841edb306SCy Schubert */
941edb306SCy Schubert
1041edb306SCy Schubert #include "ipf.h"
1141edb306SCy Schubert
12efeb8bffSCy Schubert int
gethost(int family,char * name,i6addr_t * hostp)13efeb8bffSCy Schubert gethost(int family, char *name, i6addr_t *hostp)
1441edb306SCy Schubert {
1541edb306SCy Schubert struct hostent *h;
1641edb306SCy Schubert struct netent *n;
1741edb306SCy Schubert u_32_t addr;
1841edb306SCy Schubert
1941edb306SCy Schubert bzero(hostp, sizeof(*hostp));
2041edb306SCy Schubert if (!strcmp(name, "test.host.dots")) {
2141edb306SCy Schubert if (family == AF_INET) {
2241edb306SCy Schubert hostp->in4.s_addr = htonl(0xfedcba98);
2341edb306SCy Schubert }
2441edb306SCy Schubert #ifdef USE_INET6
2541edb306SCy Schubert if (family == AF_INET6) {
2641edb306SCy Schubert hostp->i6[0] = htonl(0xfe80aa55);
2741edb306SCy Schubert hostp->i6[1] = htonl(0x12345678);
2841edb306SCy Schubert hostp->i6[2] = htonl(0x5a5aa5a5);
2941edb306SCy Schubert hostp->i6[3] = htonl(0xfedcba98);
3041edb306SCy Schubert }
3141edb306SCy Schubert #endif
32*2582ae57SCy Schubert return (0);
3341edb306SCy Schubert }
3441edb306SCy Schubert
3541edb306SCy Schubert if (!strcmp(name, "<thishost>"))
3641edb306SCy Schubert name = thishost;
3741edb306SCy Schubert
3841edb306SCy Schubert if (family == AF_INET) {
3941edb306SCy Schubert h = gethostbyname(name);
4041edb306SCy Schubert if (h != NULL) {
4141edb306SCy Schubert if ((h->h_addr != NULL) &&
4241edb306SCy Schubert (h->h_length == sizeof(addr))) {
4341edb306SCy Schubert bcopy(h->h_addr, (char *)&addr, sizeof(addr));
4441edb306SCy Schubert hostp->in4.s_addr = addr;
45*2582ae57SCy Schubert return (0);
4641edb306SCy Schubert }
4741edb306SCy Schubert }
4841edb306SCy Schubert
4941edb306SCy Schubert n = getnetbyname(name);
5041edb306SCy Schubert if (n != NULL) {
5141edb306SCy Schubert hostp->in4.s_addr = htonl(n->n_net & 0xffffffff);
52*2582ae57SCy Schubert return (0);
5341edb306SCy Schubert }
5441edb306SCy Schubert }
5541edb306SCy Schubert #ifdef USE_INET6
5641edb306SCy Schubert if (family == AF_INET6) {
5741edb306SCy Schubert struct addrinfo hints, *res;
5841edb306SCy Schubert struct sockaddr_in6 *sin6;
5941edb306SCy Schubert
6041edb306SCy Schubert bzero((char *)&hints, sizeof(hints));
6141edb306SCy Schubert hints.ai_family = PF_INET6;
6241edb306SCy Schubert
6341edb306SCy Schubert getaddrinfo(name, NULL, &hints, &res);
6441edb306SCy Schubert if (res != NULL) {
6541edb306SCy Schubert sin6 = (struct sockaddr_in6 *)res->ai_addr;
6641edb306SCy Schubert hostp->in6 = sin6->sin6_addr;
6741edb306SCy Schubert freeaddrinfo(res);
68*2582ae57SCy Schubert return (0);
6941edb306SCy Schubert }
7041edb306SCy Schubert }
7141edb306SCy Schubert #endif
72*2582ae57SCy Schubert return (-1);
7341edb306SCy Schubert }
74