There is a define in agent++.h header - USE_LISTEN_ADDRESS_FOR_SENDING_TRAPS
.
snmp_request.cpp
, method Snmpx *SnmpRequest::get_new_snmp(Snmpx* snmp, int &status)
. If USE_LISTEN_ADDRESS_FOR_SENDING_TRAPS
is not defined (0.0.0.0 or [::] listen address is more suitable for me, so I’ve undefined it), Snmpx
will be created with ipv4 0.0.0.0 listen address regardless of sending address type (ipv4 or ipv6), so sending traps to ipv6 is not possible.
My workaround looks like this:
Snmpx *SnmpRequest::get_new_snmp(Snmpx* snmp, int &status)
{
Snmpx *snmpx;
status = SNMP_CLASS_ERROR;
#ifdef USE_LISTEN_ADDRESS_FOR_SENDING_TRAPS
if (snmp)
{
UdpAddress addr = snmp->get_listen_address();
addr.set_port(0);
snmpx = new Snmpx(status, addr);
}
else
{
LOG_BEGIN(loggerModuleName, WARNING_LOG | 1);
LOG("SnmpRequestV3: Binding to all interfaces");
LOG_END;
snmpx = new Snmpx(status, 0);
}
#else
if (snmp)
{
if (snmp->get_listen_address().get_ip_version() == IpAddress::version_ipv4)
snmpx = new Snmpx(status, "0.0.0.0");
else
snmpx = new Snmpx(status, "::");
}
else
snmpx = new Snmpx(status, 0);
#endif
return snmpx;
}
What do you think about it? Is there a better solution?