4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
14 hostname(int family, void *ip)
16 static char hostbuf[MAXHOSTNAMELEN+1];
21 memset(&ipa, 0, sizeof(ipa)); /* XXX gcc */
23 if (family == AF_INET) {
24 ipa.s_addr = *(u_32_t *)ip;
25 if (ipa.s_addr == htonl(0xfedcba98))
26 return ("test.host.dots");
29 if ((opts & OPT_NORESOLVE) == 0) {
30 if (family == AF_INET) {
31 hp = gethostbyaddr(ip, 4, AF_INET);
32 if (hp != NULL && hp->h_name != NULL &&
33 *hp->h_name != '\0') {
34 strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
35 hostbuf[sizeof(hostbuf) - 1] = '\0';
39 np = getnetbyaddr(ipa.s_addr, AF_INET);
40 if (np != NULL && np->n_name != NULL &&
41 *np->n_name != '\0') {
42 strncpy(hostbuf, np->n_name, sizeof(hostbuf));
43 hostbuf[sizeof(hostbuf) - 1] = '\0';
49 if (family == AF_INET) {
50 return (inet_ntoa(ipa));
53 (void) inet_ntop(AF_INET6, ip, hostbuf, sizeof(hostbuf) - 1);
54 hostbuf[MAXHOSTNAMELEN] = '\0';