Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / hostname.c
blob4bca028c16f10e1f8e57cd508de62afe28149486
1 /*
2 * Copyright (C) 2003 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
7 * Use is subject to license terms.
8 */
10 #pragma ident "%Z%%M% %I% %E% SMI"
12 #include "ipf.h"
14 char *hostname(v, ip)
15 int v;
16 void *ip;
18 static char hostbuf[MAXHOSTNAMELEN+1];
19 struct hostent *hp;
20 struct in_addr ipa;
21 struct netent *np;
23 if (v == 4) {
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 (v == 4) {
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';
36 return hostbuf;
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';
44 return hostbuf;
49 if (v == 4) {
50 return inet_ntoa(ipa);
52 #ifdef USE_INET6
53 (void) inet_ntop(AF_INET6, ip, hostbuf, sizeof(hostbuf) - 1);
54 hostbuf[MAXHOSTNAMELEN] = '\0';
55 return hostbuf;
56 #else
57 return "IPv6";
58 #endif