snmptrapd_sql needs the sending hostname to be made available to it. To do so, it asks for the formating string %B, or CHR_PDU_NAME, which according to a comment will "Try to convert the numerical transport information into a hostname [...] Otherwise falls back to the numeric address format."
The "otherwise" bit was not implemented as suggested - it would only return a plain hostname, or the string "<UNKNOWN>". One might be lead to believe that CHR_PDU_IP would be this fallback, yet it adds a lot more information than just IP address. The sql logging code has both a "transport " column - output from CHR_PDU_IP - as well as a "hostname" column. This seems to be the easiest way to make sure the hostname always has something sensible in it. --- snmplib/transports/snmpIPv4BaseDomain.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/snmplib/transports/snmpIPv4BaseDomain.c b/snmplib/transports/snmpIPv4BaseDomain.c index 41a6cb6..fb98212 100644 --- a/snmplib/transports/snmpIPv4BaseDomain.c +++ b/snmplib/transports/snmpIPv4BaseDomain.c @@ -205,10 +205,9 @@ netsnmp_ipv4_fmtaddr(const char *prefix, netsnmp_transport *t, inet_ntoa(addr_pair->local_addr.sin.sin_addr), ntohs(addr_pair->local_addr.sin.sin_port)); } else if ( t && t->flags & NETSNMP_TRANSPORT_FLAG_HOSTNAME ) { - /* XXX: hmm... why isn't this prefixed */ - /* assuming intentional */ + /* XXX: not prefixed - used by trapd_sql to get plain remote hostname */ host = netsnmp_gethostbyaddr((char *)&to->sin_addr, 4, AF_INET); - return (host ? strdup(host->h_name) : NULL); + return (host ? strdup(host->h_name) : strdup(inet_ntoa(to->sin_addr))); } else { snprintf(tmp, sizeof(tmp), "%s: [%s]:%hu->", prefix, inet_ntoa(to->sin_addr), ntohs(to->sin_port)); -- 1.7.11.7 ------------------------------------------------------------------------------ AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d _______________________________________________ Net-snmp-coders mailing list Net-snmp-coders@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/net-snmp-coders