]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/ipfilter/lib/gethost.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / ipfilter / lib / gethost.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2002-2004 by Darren Reed.
5  * 
6  * See the IPFILTER.LICENCE file for details on licencing.  
7  *   
8  * $Id: gethost.c,v 1.3.2.2 2006/06/16 17:20:59 darrenr Exp $ 
9  */     
10
11 #include "ipf.h"
12
13 int gethost(name, hostp)
14 char *name;
15 u_32_t *hostp;
16 {
17         struct hostent *h;
18         struct netent *n;
19         u_32_t addr;
20
21         if (!strcmp(name, "test.host.dots")) {
22                 *hostp = htonl(0xfedcba98);
23                 return 0;
24         }
25
26         if (!strcmp(name, "<thishost>"))
27                 name = thishost;
28
29         h = gethostbyname(name);
30         if (h != NULL) {
31                 if ((h->h_addr != NULL) && (h->h_length == sizeof(addr))) {
32                         bcopy(h->h_addr, (char *)&addr, sizeof(addr));
33                         *hostp = addr;
34                         return 0;
35                 }
36         }
37
38         n = getnetbyname(name);
39         if (n != NULL) {
40                 *hostp = (u_32_t)htonl(n->n_net & 0xffffffff);
41                 return 0;
42         }
43         return -1;
44 }