1637Sml37995 /*
2637Sml37995 * Copyright (C) 2003 by Darren Reed.
3637Sml37995 *
4637Sml37995 * See the IPFILTER.LICENCE file for details on licencing.
5637Sml37995 *
6*2393Syz155240 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7637Sml37995 * Use is subject to license terms.
8637Sml37995 */
9637Sml37995
10637Sml37995 #pragma ident "%Z%%M% %I% %E% SMI"
110Sstevel@tonic-gate
120Sstevel@tonic-gate #include "ipf.h"
130Sstevel@tonic-gate
hostname(v,ip)140Sstevel@tonic-gate char *hostname(v, ip)
150Sstevel@tonic-gate int v;
160Sstevel@tonic-gate void *ip;
170Sstevel@tonic-gate {
18*2393Syz155240 static char hostbuf[MAXHOSTNAMELEN+1];
19*2393Syz155240 struct hostent *hp;
200Sstevel@tonic-gate struct in_addr ipa;
21*2393Syz155240 struct netent *np;
220Sstevel@tonic-gate
230Sstevel@tonic-gate if (v == 4) {
240Sstevel@tonic-gate ipa.s_addr = *(u_32_t *)ip;
25*2393Syz155240 if (ipa.s_addr == htonl(0xfedcba98))
26*2393Syz155240 return "test.host.dots";
27*2393Syz155240 }
28*2393Syz155240
29*2393Syz155240 if ((opts & OPT_NORESOLVE) == 0) {
30*2393Syz155240 if (v == 4) {
31*2393Syz155240 hp = gethostbyaddr(ip, 4, AF_INET);
32*2393Syz155240 if (hp != NULL && hp->h_name != NULL &&
33*2393Syz155240 *hp->h_name != '\0') {
34*2393Syz155240 strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
35*2393Syz155240 hostbuf[sizeof(hostbuf) - 1] = '\0';
36*2393Syz155240 return hostbuf;
37*2393Syz155240 }
38*2393Syz155240
39*2393Syz155240 np = getnetbyaddr(ipa.s_addr, AF_INET);
40*2393Syz155240 if (np != NULL && np->n_name != NULL &&
41*2393Syz155240 *np->n_name != '\0') {
42*2393Syz155240 strncpy(hostbuf, np->n_name, sizeof(hostbuf));
43*2393Syz155240 hostbuf[sizeof(hostbuf) - 1] = '\0';
44*2393Syz155240 return hostbuf;
45*2393Syz155240 }
46*2393Syz155240 }
47*2393Syz155240 }
48*2393Syz155240
49*2393Syz155240 if (v == 4) {
500Sstevel@tonic-gate return inet_ntoa(ipa);
510Sstevel@tonic-gate }
520Sstevel@tonic-gate #ifdef USE_INET6
53*2393Syz155240 (void) inet_ntop(AF_INET6, ip, hostbuf, sizeof(hostbuf) - 1);
54*2393Syz155240 hostbuf[MAXHOSTNAMELEN] = '\0';
550Sstevel@tonic-gate return hostbuf;
560Sstevel@tonic-gate #else
570Sstevel@tonic-gate return "IPv6";
580Sstevel@tonic-gate #endif
590Sstevel@tonic-gate }
60