gethost.c revision 170268
1/* $FreeBSD: head/contrib/ipfilter/lib/gethost.c 170268 2007-06-04 02:54:36Z darrenr $ */ 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 13int gethost(name, hostp) 14char *name; 15u_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} 45