Invalid argument (sendto failed). Not able to send V3 Trap

Hi Frank,

I am not able to send traps using org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification. I am getting following error stacktrace

org.snmp4j.MessageException: Invalid argument (sendto failed)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:545)
        at org.snmp4j.Snmp.sendMessage(Snmp.java:1087)
        at org.snmp4j.Snmp.send(Snmp.java:968)
        at org.snmp4j.Snmp.send(Snmp.java:961)
        at org.snmp4j.Snmp.send(Snmp.java:926)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.sendNotification(NotificationOriginatorImpl.java:272)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:378)
        at org.snmp4j.agent.mo.snmp.NotificationOriginatorImpl.notify(NotificationOriginatorImpl.java:140)
        at com.ericsson.vil.pms.snmp.NodeAgent.sendTrap(NodeAgent.java:463)
        at com.ericsson.vil.pms.watcher.filesystem.LogWatcher.detectTrap(LogWatcher.java:87)
        at com.ericsson.vil.pms.watcher.filesystem.FileMonitor$1.onFileChange(FileMonitor.java:72)
        at org.apache.commons.io.monitor.FileAlterationObserver.doMatch(FileAlterationObserver.java:410)
        at org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:333)
        at org.apache.commons.io.monitor.FileAlterationObserver.checkAndNotify(FileAlterationObserver.java:303)
        at org.apache.commons.io.monitor.FileAlterationMonitor.run(FileAlterationMonitor.java:182)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Invalid argument (sendto failed)
        at java.net.PlainDatagramSocketImpl.send(Native Method)
        at java.net.DatagramSocket.send(DatagramSocket.java:693)
        at org.snmp4j.transport.DefaultUdpTransportMapping.sendMessage(DefaultUdpTransportMapping.java:117)
        at org.snmp4j.transport.DefaultUdpTransportMapping.sendMessage(DefaultUdpTransportMapping.java:42)
        at org.snmp4j.MessageDispatcherImpl.sendMessage(MessageDispatcherImpl.java:203)
        at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:522)

I am Using following dependencies:

org.snmp4j snmp4j 2.8.2 org.snmp4j snmp4j-agent 2.7.9

Can you please help here? What could be the possible reasons?

I have few observations:

  1. I am able to send trap using net snmp sendtrapd utility. But the NoficationOriginatorImpl.sendNotification fails with the above error
  2. I am able to connect to remote host:port using a small java program written by me. That Java program uses DatagramPacket to connect.
  3. I am able to send trap using snmp4j when the address is localhost
  4. I have the ports enabled in firewall. (net-snmp works)

Please help. I had faced it 2 years back. But somehow dodged it then. But now I need help.

–Anirban

Hi Anirban,

Please enable debug logging to see the source stack trace of this exception.
Most likely your target address is wrongly specified, but that is just a guess.
With the stack trace of the root exception we will know it.

Best regards,
Frank

HI Frank,

Please help.

–Anirban

Hi Frank,

The target address is as below.

snmp4j.agent.cfg.index.1.3.6.1.6.3.12.1.2.1.2={o}‘notify3’
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.0={o}1.3.6.1.2.1.100.1.14
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.1={s}<IP_V4>:162
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.2={i}250
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.3={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.4={s}notify
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.5={s}SNMPv3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.6={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.7={i}1

I have uploaded the log file please take a look.
log.txt (801.1 KB)

In the log file these statements are coming:
025-07-24 02:15:42:876 | DEBUG [Thread-5] | Matching view found for group name ‘v3group’ is ‘trapRestrictedNotifyView’
2025-07-24 02:15:42:876 | DEBUG [Thread-5] | Access allowed for view ‘trapRestrictedNotifyView’ by subtree 1.3.6.1.4.1.5683 for OID 1.3.6.1.4.1.5683.2601.1.1.7
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | getUser(engineID=80:00:13:70:01:0a:fd:f1:67:f1:9f:a1:cc, securityName=PPNative)
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | RFC3414 §3.1.4.a Outgoing message needs to be encrypted
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | initVect is 00:00:00:0f:00:00:00:19:10:90:57:cf:9e:4f:c0:b4
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | aes encrypt: Data to encrypt 30:82:01:68:04:0d:80:00:13:70:01:0a:fd:f1:67:f1:9f:a1:cc:04:00:a7:82:01:53:02:04:48:d9:ec:90:02:01:00:02:01:00:30:82:01:43:30:0e:06:08:2b:06:01:02:01:01:03:00:43:02:0a:0d:30:15:06:0a:2b:06:01:06:03:01:01:04:01:00:06:07:2b:06:01:04:01:81:41:30:15:06:0c:2b:06:01:04:01:81:41:94:29:01:01:01:04:05:31:32:30:32:33:30:81:9d:06:0c:2b:06:01:04:01:81:41:94:29:01:01:03:04:81:8c:50:6f:73:74:67:72:65:73:71:6c:44:6f:77:6e:20:41:6c:65:72:74:3a:20:5b:4a:75:6c:20:32:33:20:32:30:3a:30:37:3a:32:35:20:50:4c:4f:4c:50:52:53:41:50:49:44:42:30:31:20:74:72:61:70:2d:6d:6f:6e:69:74:6f:72:5b:32:35:36:34:5d:3a:20:64:65:73:63:3a:20:22:50:6f:73:74:67:72:65:73:71:6c:20:53:65:72:76:69:63:65:20:44:6f:77:6e:22:20:61:6c:61:72:6d:3a:20:50:6f:73:74:67:72:65:73:71:6c:44:6f:77:6e:20:73:65:76:65:72:69:74:79:3a:20:33:5d:30:11:06:0c:2b:06:01:04:01:81:41:94:29:01:01:04:04:01:33:30:1d:06:0c:2b:06:01:04:01:81:41:94:29:01:01:05:04:0d:31:30:2e:32:35:33:2e:32:34:31:2e:37:31:30:1a:06:0c:2b:06:01:04:01:81:41:94:29:01:01:06:04:0a:70:65:72:73:69:73:74:65:6e:74:30:15:06:0c:2b:06:01:04:01:81:41:94:29:01:01:07:04:05:31:32:30:32:34
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | aes encrypt: used key f4:e8:28:ef:f3:20:95:fc:d8:28:6e:9c:13:03:e2:ae
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | aes encrypt: created privacy_params 10:90:57:cf:9e:4f:c0:b4
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | aes encrypt: encrypted Data 89:35:be:3b:ee:80:cc:24:7f:bd:89:c6:6e:92:a2:97:2f:81:3b:e4:97:e3:33:89:97:b7:ff:06:11:71:fd:43:4b:49:b7:ed:3d:da:d5:16:38:f5:4d:2b:8a:fb:12:84:ca:89:a2:ce:72:96:ce:82:cc:c3:23:b3:4f:4e:b4:11:38:a9:ba:f1:a9:09:70:98:c1:8f:f9:73:a1:c7:db:c2:f8:6c:ad:be:5c:4e:29:b2:20:a9:4e:de:12:72:7e:8a:5c:f8:c3:3f:fe:d5:c7:df:2e:3d:b9:14:ee:ac:9e:f6:f9:8d:76:01:4e:47:8d:94:74:94:af:40:6b:31:7b:43:50:c0:88:89:76:08:e5:5b:d1:ea:84:3a:25:c6:d6:e6:db:3a:4a:73:9a:47:41:7d:3b:a3:fb:04:b1:b9:0e:40:13:54:e8:fb:13:25:17:b7:26:ce:d7:45:83:cf:b5:e1:56:75:47:bd:47:88:1d:45:24:34:48:a2:ef:c3:7a:8e:df:3c:ee:a3:d7:8a:52:88:13:b5:3d:9f:7f:ec:5b:1a:a5:a7:51:b1:1f:5a:df:8a:5d:f2:6e:77:13:0d:59:f1:3e:02:e1:f6:12:b2:ad:ef:45:6c:14:4a:12:5a:8c:8e:05:19:7d:bc:46:6d:c3:3b:eb:2d:28:46:b2:9b:a2:ed:ce:a7:83:52:d8:74:18:94:66:12:b4:08:26:6b:74:e3:40:63:6b:f8:f2:b1:69:72:d5:c4:5d:90:5e:5d:0a:5f:57:78:3b:84:f8:4f:72:91:b2:2b:84:cf:39:59:94:14:45:f1:ca:8c:87:e6:64:25:eb:57:af:f6:36:96:4f:e1:6f:75:a0:a8:35:4b:dd:98:6e:31:08:b0:0e:04:26:e6:bc:a4:bb:78:5d:1c:2d:c8:94:ea:e0:37:9c:59:ea:07:71:50:d1:8c:a6:82:84:c1:b1:a5:17:ca
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | Adding cache entry: StateReference[msgID=1044634,pduHandle=PduHandle[1222241424],securityEngineID=80:00:13:70:01:0a:fd:f1:67:f1:9f:a1:cc,securityModel=org.snmp4j.security.USM@64543bad,securityName=PPNative,securityLevel=3,contextEngineID=80:00:13:70:01:0a:fd:f1:67:f1:9f:a1:cc,contextName=,retryMsgIDs=null]
2025-07-24 02:15:42:877 | DEBUG [Thread-5] | Sending message to 10.253.241.72/162 with length 452: 30:82:01:c0:02:01:03:30:10:02:03:0f:f0:9a:02:03:00:ff:ff:04:01:03:02:01:03:04:39:30:37:04:0d:80:00:13:70:01:0a:fd:f1:67:f1:9f:a1:cc:02:01:0f:02:01:19:04:08:50:50:4e:61:74:69:76:65:04:0c:46:3c:69:fe:57:6c:b3:13:cc:36:1c:17:04:08:10:90:57:cf:9e:4f:c0:b4:04:82:01:6c:89:35:be:3b:ee:80:cc:24:7f:bd:89:c6:6e:92:a2:97:2f:81:3b:e4:97:e3:33:89:97:b7:ff:06:11:71:fd:43:4b:49:b7:ed:3d:da:d5:16:38:f5:4d:2b:8a:fb:12:84:ca:89:a2:ce:72:96:ce:82:cc:c3:23:b3:4f:4e:b4:11:38:a9:ba:f1:a9:09:70:98:c1:8f:f9:73:a1:c7:db:c2:f8:6c:ad:be:5c:4e:29:b2:20:a9:4e:de:12:72:7e:8a:5c:f8:c3:3f:fe:d5:c7:df:2e:3d:b9:14:ee:ac:9e:f6:f9:8d:76:01:4e:47:8d:94:74:94:af:40:6b:31:7b:43:50:c0:88:89:76:08:e5:5b:d1:ea:84:3a:25:c6:d6:e6:db:3a:4a:73:9a:47:41:7d:3b:a3:fb:04:b1:b9:0e:40:13:54:e8:fb:13:25:17:b7:26:ce:d7:45:83:cf:b5:e1:56:75:47:bd:47:88:1d:45:24:34:48:a2:ef:c3:7a:8e:df:3c:ee:a3:d7:8a:52:88:13:b5:3d:9f:7f:ec:5b:1a:a5:a7:51:b1:1f:5a:df:8a:5d:f2:6e:77:13:0d:59:f1:3e:02:e1:f6:12:b2:ad:ef:45:6c:14:4a:12:5a:8c:8e:05:19:7d:bc:46:6d:c3:3b:eb:2d:28:46:b2:9b:a2:ed:ce:a7:83:52:d8:74:18:94:66:12:b4:08:26:6b:74:e3:40:63:6b:f8:f2:b1:69:72:d5:c4:5d:90:5e:5d:0a:5f:57:78:3b:84:f8:4f:72:91:b2:2b:84:cf:39:59:94:14:45:f1:ca:8c:87:e6:64:25:eb:57:af:f6:36:96:4f:e1:6f:75:a0:a8:35:4b:dd:98:6e:31:08:b0:0e:04:26:e6:bc:a4:bb:78:5d:1c:2d:c8:94:ea:e0:37:9c:59:ea:07:71:50:d1:8c:a6:82:84:c1:b1:a5:17:ca

And after the exception stack trace that I mentioned.

I am totally at my wit;s end. PLease help.

–Anirban

Here is the problem. This not a valid transport address as required. See the MIB description for this object for more details.

Hi Frank,

That <IP_V4> part was for example. Actua; confuguration is like this:

snmp4j.agent.cfg.index.1.3.6.1.6.3.12.1.2.1.2={o}‘notify3’

snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.0={o}1.3.6.1.2.1.100.1.14
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.1={s}10.253.241.72:162
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.2={i}250
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.3={i}1
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.4={s}notify
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.5={s}SNMPv3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.6={i}3
snmp4j.agent.cfg.value.1.3.6.1.6.3.12.1.2.1.2.7={i}1

Ip address is correct.
Can you please take a look at the log?

–Anirban

Please read the MIB description! The “IP address format” you are using is not supported!

Hi Frank,

Can you please point me towards where I can read the" IP Address Format"? The format with “127.0.0.1:162” works fine.

For Ip address=10.253.241.72, and port=162, what should be the format?

–Anirban

The format you have chosen is TransportAddressDns but is in fact an IPv4 address and port. Thus, I would use the format identifier 1.3.6.1.2.1.100.1.1 (transportDomainUdpIpv4) which requires a 6 byte octet string (4 bytes IPv4 and 2 bytes port).
The TransportAddressDns (transportDomainUdpDns identifier) could be used too, but then a InetAddress.getByName will be called on the IP string which could result in some error. Most likely, the IP address could not be resolved by DNS in this case.