]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/gethost.c
This commit was generated by cvs2svn to compensate for changes in r168616,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / gethost.c
1 /*      $FreeBSD$       */
2
3 #include "ipf.h"
4
5 int gethost(name, hostp)
6 char *name;
7 u_32_t *hostp;
8 {
9         struct hostent *h;
10         struct netent *n;
11         u_32_t addr;
12
13         if (!strcmp(name, "test.host.dots")) {
14                 *hostp = htonl(0xfedcba98);
15                 return 0;
16         }
17
18         if (!strcmp(name, "<thishost>"))
19                 name = thishost;
20
21         h = gethostbyname(name);
22         if (h != NULL) {
23                 if ((h->h_addr != NULL) && (h->h_length == sizeof(addr))) {
24                         bcopy(h->h_addr, (char *)&addr, sizeof(addr));
25                         *hostp = addr;
26                         return 0;
27                 }
28         }
29
30         n = getnetbyname(name);
31         if (n != NULL) {
32                 *hostp = (u_32_t)htonl(n->n_net & 0xffffffff);
33                 return 0;
34         }
35         return -1;
36 }