4 * Copyright (C) 2002-2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * $Id: hostname.c,v 1.6.2.2 2007/01/16 02:25:22 darrenr Exp $
17 static char hostbuf[MAXHOSTNAMELEN+1];
22 memset(&ipa, 0, sizeof(ipa)); /* XXX gcc */
25 ipa.s_addr = *(u_32_t *)ip;
26 if (ipa.s_addr == htonl(0xfedcba98))
27 return "test.host.dots";
30 if ((opts & OPT_NORESOLVE) == 0) {
32 hp = gethostbyaddr(ip, 4, AF_INET);
33 if (hp != NULL && hp->h_name != NULL &&
34 *hp->h_name != '\0') {
35 strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
36 hostbuf[sizeof(hostbuf) - 1] = '\0';
40 np = getnetbyaddr(ipa.s_addr, AF_INET);
41 if (np != NULL && np->n_name != NULL &&
42 *np->n_name != '\0') {
43 strncpy(hostbuf, np->n_name, sizeof(hostbuf));
44 hostbuf[sizeof(hostbuf) - 1] = '\0';
51 return inet_ntoa(ipa);
54 (void) inet_ntop(AF_INET6, ip, hostbuf, sizeof(hostbuf) - 1);
55 hostbuf[MAXHOSTNAMELEN] = '\0';