to print_host.
-/* $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>
#include <string.h>
#include <syslog.h>
#include <event.h>
+#include <netdb.h>
#include <openssl/ssl.h>
}
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);
}
-/* $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>
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);
-/* $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>
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);
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);
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);
}