gethost.c revision 145510
1/* $NetBSD$ */ 2 3#include "ipf.h" 4 5int gethost(name, hostp) 6char *name; 7u_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} 37