NetBSD/dist/ipf/lib/hostnum.c

50 lines
906 B
C
Raw Normal View History

2005-02-08 10:01:52 +03:00
/* $NetBSD: hostnum.c,v 1.5 2005/02/08 07:01:53 martti Exp $ */
2004-03-28 12:55:20 +04:00
/*
* Copyright (C) 1993-2001 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
2005-02-08 10:01:52 +03:00
* Id: hostnum.c,v 1.10.2.1 2004/12/09 19:41:20 darrenr Exp
2004-03-28 12:55:20 +04:00
*/
#include <ctype.h>
#include "ipf.h"
/*
* returns an ip address as a long var as a result of either a DNS lookup or
* straight inet_addr() call
*/
int hostnum(ipa, host, linenum, ifname)
u_32_t *ipa;
char *host;
int linenum;
char *ifname;
{
struct in_addr ip;
if (!strcasecmp("any", host) ||
(ifname && *ifname && !strcasecmp(ifname, host)))
return 0;
#ifdef USE_INET6
if (use_inet6) {
if (inet_pton(AF_INET6, host, ipa) == 1)
return 0;
else
return -1;
}
#endif
if (ISDIGIT(*host) && inet_aton(host, &ip)) {
2004-03-28 12:55:20 +04:00
*ipa = ip.s_addr;
return 0;
}
if (!strcasecmp("<thishost>", host))
host = thishost;
return gethost(host, ipa);
}