summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/lib/hostname.c
diff options
context:
space:
mode:
authordarrenr <darrenr@FreeBSD.org>2005-04-25 17:31:50 +0000
committerdarrenr <darrenr@FreeBSD.org>2005-04-25 17:31:50 +0000
commitd438802dcb3e270d6fcc65f075c808c64853a7c2 (patch)
treee2e1c7115044e6dfc86ff65598566fa32e5f7421 /contrib/ipfilter/lib/hostname.c
parent590450fec65a8e72a8965117398bc8f14938b4a8 (diff)
downloadFreeBSD-src-d438802dcb3e270d6fcc65f075c808c64853a7c2.zip
FreeBSD-src-d438802dcb3e270d6fcc65f075c808c64853a7c2.tar.gz
import ipfilter 4.1.8 into the vendor branch
Diffstat (limited to 'contrib/ipfilter/lib/hostname.c')
-rw-r--r--contrib/ipfilter/lib/hostname.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/ipfilter/lib/hostname.c b/contrib/ipfilter/lib/hostname.c
new file mode 100644
index 0000000..a0109da
--- /dev/null
+++ b/contrib/ipfilter/lib/hostname.c
@@ -0,0 +1,51 @@
+/* $NetBSD$ */
+
+
+#include "ipf.h"
+
+char *hostname(v, ip)
+int v;
+void *ip;
+{
+ static char hostbuf[MAXHOSTNAMELEN+1];
+ struct hostent *hp;
+ struct in_addr ipa;
+ struct netent *np;
+
+ if (v == 4) {
+ ipa.s_addr = *(u_32_t *)ip;
+ if (ipa.s_addr == htonl(0xfedcba98))
+ return "test.host.dots";
+ }
+
+ if ((opts & OPT_NORESOLVE) == 0) {
+ if (v == 4) {
+ hp = gethostbyaddr(ip, 4, AF_INET);
+ if (hp != NULL && hp->h_name != NULL &&
+ *hp->h_name != '\0') {
+ strncpy(hostbuf, hp->h_name, sizeof(hostbuf));
+ hostbuf[sizeof(hostbuf) - 1] = '\0';
+ return hostbuf;
+ }
+
+ np = getnetbyaddr(ipa.s_addr, AF_INET);
+ if (np != NULL && np->n_name != NULL &&
+ *np->n_name != '\0') {
+ strncpy(hostbuf, np->n_name, sizeof(hostbuf));
+ hostbuf[sizeof(hostbuf) - 1] = '\0';
+ return hostbuf;
+ }
+ }
+ }
+
+ if (v == 4) {
+ return inet_ntoa(ipa);
+ }
+#ifdef USE_INET6
+ (void) inet_ntop(AF_INET6, ip, hostbuf, sizeof(hostbuf) - 1);
+ hostbuf[MAXHOSTNAMELEN] = '\0';
+ return hostbuf;
+#else
+ return "IPv6";
+#endif
+}
OpenPOWER on IntegriCloud