summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2008-07-18 12:30:07 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2008-07-18 12:30:07 +0000
commit453a0e03f8b9c4b001c0c1aa2d1084663ff12bb0 (patch)
tree688d7a907264eb666f549b4d963ee3a038e8f048 /usr.sbin
parent736247fd945c4d85368d503fb285a9014f91e69e (diff)
merge log_host with relayd's version using getnameinfo and rename it
to print_host.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/snmpd/log.c20
-rw-r--r--usr.sbin/snmpd/snmpd.h4
-rw-r--r--usr.sbin/snmpd/snmpe.c8
3 files changed, 15 insertions, 17 deletions
diff --git a/usr.sbin/snmpd/log.c b/usr.sbin/snmpd/log.c
index f1d773c35f0..7603cb5cfef 100644
--- a/usr.sbin/snmpd/log.c
+++ b/usr.sbin/snmpd/log.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: log.c,v 1.1 2007/12/05 09:22:44 reyk Exp $ */
+/* $OpenBSD: log.c,v 1.2 2008/07/18 12:30:06 reyk Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -36,6 +36,7 @@
#include <string.h>
#include <syslog.h>
#include <event.h>
+#include <netdb.h>
#include <openssl/ssl.h>
@@ -168,15 +169,12 @@ fatalx(const char *emsg)
}
const char *
-log_host(struct sockaddr_storage *ss, char *buf, size_t len)
+print_host(struct sockaddr_storage *ss, char *buf, size_t len)
{
- int af = ss->ss_family;
- void *ptr;
-
- bzero(buf, len);
- if (af == AF_INET)
- ptr = &((struct sockaddr_in *)ss)->sin_addr;
- else
- ptr = &((struct sockaddr_in6 *)ss)->sin6_addr;
- return (inet_ntop(af, ptr, buf, len));
+ if (getnameinfo((struct sockaddr *)ss, ss->ss_len,
+ buf, len, NULL, 0, NI_NUMERICHOST) != 0) {
+ buf[0] = '\0';
+ return (NULL);
+ }
+ return (buf);
}
diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h
index 3a0fe23babe..16969ebf1dd 100644
--- a/usr.sbin/snmpd/snmpd.h
+++ b/usr.sbin/snmpd/snmpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpd.h,v 1.19 2008/06/29 16:00:22 ragge Exp $ */
+/* $OpenBSD: snmpd.h,v 1.20 2008/07/18 12:30:06 reyk Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net>
@@ -353,7 +353,7 @@ void log_info(const char *, ...);
void log_debug(const char *, ...);
__dead void fatal(const char *);
__dead void fatalx(const char *);
-const char *log_host(struct sockaddr_storage *, char *, size_t);
+const char *print_host(struct sockaddr_storage *, char *, size_t);
/* buffer.c */
struct buf *buf_open(size_t);
diff --git a/usr.sbin/snmpd/snmpe.c b/usr.sbin/snmpd/snmpe.c
index 3c0d871754e..da02d59e7c3 100644
--- a/usr.sbin/snmpd/snmpe.c
+++ b/usr.sbin/snmpd/snmpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpe.c,v 1.18 2008/03/12 14:11:52 reyk Exp $ */
+/* $OpenBSD: snmpe.c,v 1.19 2008/07/18 12:30:06 reyk Exp $ */
/*
* Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net>
@@ -234,7 +234,7 @@ snmpe_bind(struct address *addr)
if (bind(s, (struct sockaddr *)&addr->ss, addr->ss.ss_len) == -1)
goto bad;
- if (log_host(&addr->ss, buf, sizeof(buf)) == NULL)
+ if (print_host(&addr->ss, buf, sizeof(buf)) == NULL)
goto bad;
log_info("snmpe_bind: binding to address %s:%d", buf, addr->port);
@@ -582,7 +582,7 @@ snmpe_parse(struct sockaddr_storage *ss,
msg->sm_error = errval;
msg->sm_errorindex = erridx;
- log_host(ss, host, sizeof(host));
+ print_host(ss, host, sizeof(host));
log_debug("snmpe_parse: %s: SNMPv%d '%s' context %d request %lld",
host, msg->sm_version + 1, msg->sm_community, msg->sm_context,
msg->sm_request);
@@ -691,7 +691,7 @@ snmpe_parse(struct sockaddr_storage *ss,
parsefail:
stats->snmp_inasnparseerrs++;
fail:
- log_host(ss, host, sizeof(host));
+ print_host(ss, host, sizeof(host));
log_debug("snmpe_parse: %s: %s", host, errstr);
return (-1);
}