Define SNMP trap listener for traps to IPv4 and IPv6 together with snmp4j

My Linux machine has both IPv4 and IPv6 (dual stack).

When I define trap listener (SNMP class) as IPv4: new DefaultUdpTransportMapping(new UdpAddress(InetAddress.getByName(IPv4),162)), listener not receives traps sent to IPv6 address.

And vice versa, when I define listener as IPv6: new DefaultUdpTransportMapping(GenericAddress.parse(“udp:[”+IPv6+"]/162")), listener not receives traps sent to IPv4 address.

I have tried to define two transport mappings (IPv4 and IPv6) into the same MessageDispatcher and initialize Snmp object with such MessageDispatcher :

        MessageDispatcher mtDispatcher =
    new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
    snmp = new Snmp(mtDispatcher);

But this solution also not works.

I should receive both traps from different senders registered on different IP types of my Linux machine.

If somebody knows right solution, please, advise.

Thank you in advance.
Alex Fooks

You have not written how you specified the listen address, but that is crucial. See

On a dual stack machine a single TransportMapping with the anylocaladdress :: should work for IPv4 and IPv6. But if that works depends on the operating system rather than on Java or SNMP4J.

Hello, Frank,

Thank you for quick answer.
With unspecified address (::slight_smile: received traps and SNMP requests for both IPv4 and IPv6 addresses.

I should deeper explain about our environment.

  1. At our system used IPv4-mapped IPv6 adresses, examples:

inet netmask broadcast
inet6 fd00:10:110:108:250:56ff:fead:aab6 prefixlen 64 scopeid 0x0

inet netmask broadcast
inet6 fd00:10:110:108:250:56ff:fead:d06 prefixlen 64 scopeid 0x0

  1. At the same station (OS CentOS 7.7) should be installed 2 co-hosted processes with dual stack
    definition. Each process should have trap listener and snmp agent on both IPv4 and IPv6 addresses.
    Such configuration requires to lookup solution how to define concrete IPs and not to use unspecified address.

Could you advice how to implement such requirement with SNMP4J?

Thank you in advance
Alex Fooks

Hello Alex,

I guess (not more), the approach using two transport mappings (one for IPv4 and one for IPv6) using the same port (162) will not work because the port is bound to TCP or UDP protocol on top of IP. Depending on the architecture of your OS, having two IP addresses (which can be bound to same transport endpoint with the dual-stack feature) with the same port will cause a port clash and only one of them (the first listening) will work.
I think you need to investigate deeply how your IP stack works and then find the a matching setup for it.

Best regards,

Hello, Frank,

I have done a lot of experiments on our dual stack system.
I understood that if I define all IPs “::” or local IPv6 as listener IP,
listener receives only traps from IPv6 clients and not receives traps from IPv4 clients.

This problem is critical for us.
May be you will recommend some solution?

Thank you
Alex Fooks

As I wrote above, with SNMP4J you can simply use two different IP addresses (regardless if IPv4 or IPv6) and use each of them for a corresponding TransportMapping. That will work if the underlying Java works with the underlying IP stack of the operating system as you expect it.

I cannot give any other advise than this, sorry. Maybe you are trying to accomplish something that cannot be done with your system architecture?