[SNMP4J] Sending SNMP traps with a different source IP Address

Jeff Gehlbach jeffg at opennms.org
Fri Jan 2 15:41:21 CET 2009


On Jan 2, 2009, at 8:56 AM, German Silva wrote:

> currently I can send traps, but the source IP Address is always my
> computer's IP Address, I wonder if it is possible to send a trap  
> from my
> computer with a different IP Address. This can be done with net-snmp.

I think you're confusing the notion of sending IP address (which is a  
function of the underlying operating system's IP stack) with the  
notion of AgentAddress in the context of SNMPv1 TRAP PDUs.  Presumably  
your reference to Net-SNMP supporting this is a reference to the  
syntax for sending a v1 trap using the "snmptrap" tool:

   -v 1 TRAP-PARAMETERS:
	 enterprise-oid agent trap-type specific-type uptime [OID TYPE  
VALUE]...

This is possible only with v1 traps, because the v1 TRAP PDU is unique  
in that it contains an AgentAddress field that carries the IP address  
of the sending agent.  The IP address in the header of the IP packet  
is still the address determined by the IP stack.  The AgentAddress  
field was removed from the v2 TRAP PDU in order to give all v2 PDUs  
the same fields.

You can set the AgentAddress of a v1 TRAP PDU in SNMP4J by calling the  
setAgentAddress(IpAddress) method of the PDUv1 class, but be sure  
you're doing this for the right reason.  Here's a link to the JavaDoc:

http://www.snmp4j.org/doc/org/snmp4j/PDUv1.html#setAgentAddress(org.snmp4j.smi.IpAddress)

public void setAgentAddress(IpAddress agentAddress)
Sets the IP address of the originator system of this SNMPv1 trap. The  
default value is 0.0.0.0, which should be only overriden in special  
cases, for example when forwarding SNMPv1 traps through a SNMP proxy.

Parameters:agentAddress - a IpAddress  
instance.Throws:java.lang.UnsupportedOperationException - if the type  
of this PDU is not PDU.V1TRAP.

-jeff



More information about the SNMP4J mailing list