xref: /titanic_51/usr/src/cmd/ipf/lib/common/gethost.c (revision f808c858fa61e7769218966759510a8b1190dfcf)
1 /*
2  * Copyright (C) 1993-2005  by Darren Reed.
3  * See the IPFILTER.LICENCE file for details on licencing.
4  */
5 
6 #include "ipf.h"
7 
8 int gethost(name, hostp)
9 char *name;
10 u_32_t *hostp;
11 {
12 	struct hostent *h;
13 	struct netent *n;
14 	u_32_t addr;
15 
16 	if (!strcmp(name, "test.host.dots")) {
17 		*hostp = htonl(0xfedcba98);
18 		return 0;
19 	}
20 
21 	if (!strcmp(name, "<thishost>"))
22 		name = thishost;
23 
24 	h = gethostbyname(name);
25 	if (h != NULL) {
26 		if ((h->h_addr != NULL) && (h->h_length == sizeof(addr))) {
27 			bcopy(h->h_addr, (char *)&addr, sizeof(addr));
28 			*hostp = addr;
29 			return 0;
30 		}
31 	}
32 
33 	n = getnetbyname(name);
34 	if (n != NULL) {
35 		*hostp = (u_32_t)htonl(n->n_net & 0xffffffff);
36 		return 0;
37 	}
38 	return -1;
39 }
40