1*2393Syz155240 /*
2*2393Syz155240  * Copyright (C) 1993-2005  by Darren Reed.
3*2393Syz155240  * See the IPFILTER.LICENCE file for details on licencing.
4*2393Syz155240  */
5*2393Syz155240 
60Sstevel@tonic-gate #include "ipf.h"
70Sstevel@tonic-gate 
80Sstevel@tonic-gate int gethost(name, hostp)
90Sstevel@tonic-gate char *name;
100Sstevel@tonic-gate u_32_t *hostp;
110Sstevel@tonic-gate {
120Sstevel@tonic-gate 	struct hostent *h;
13*2393Syz155240 	struct netent *n;
140Sstevel@tonic-gate 	u_32_t addr;
150Sstevel@tonic-gate 
16*2393Syz155240 	if (!strcmp(name, "test.host.dots")) {
17*2393Syz155240 		*hostp = htonl(0xfedcba98);
18*2393Syz155240 		return 0;
19*2393Syz155240 	}
20*2393Syz155240 
210Sstevel@tonic-gate 	if (!strcmp(name, "<thishost>"))
220Sstevel@tonic-gate 		name = thishost;
230Sstevel@tonic-gate 
240Sstevel@tonic-gate 	h = gethostbyname(name);
250Sstevel@tonic-gate 	if (h != NULL) {
260Sstevel@tonic-gate 		if ((h->h_addr != NULL) && (h->h_length == sizeof(addr))) {
270Sstevel@tonic-gate 			bcopy(h->h_addr, (char *)&addr, sizeof(addr));
280Sstevel@tonic-gate 			*hostp = addr;
290Sstevel@tonic-gate 			return 0;
300Sstevel@tonic-gate 		}
310Sstevel@tonic-gate 	}
32*2393Syz155240 
33*2393Syz155240 	n = getnetbyname(name);
34*2393Syz155240 	if (n != NULL) {
35*2393Syz155240 		*hostp = (u_32_t)htonl(n->n_net & 0xffffffff);
36*2393Syz155240 		return 0;
37*2393Syz155240 	}
380Sstevel@tonic-gate 	return -1;
390Sstevel@tonic-gate }
40