Discussion:
[SNMP4J] Controlling which local address to use
Gil Steiner
2005-10-26 08:40:25 UTC
Permalink
Hi,



I would like to use a different (pre-defined) IP address as a local address
when sending SNMP requests. In other words, I would like to bind the socket
to a given address instead of using the 'default' IP address.

I know that the 'bind' method supports such an option (by supplying an
address that is not null) but my question is how I can control this from
within SNMP4J. The bind method is not used directly from SNMP4J.



+gil



______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
Deon van der Merwe
2005-10-26 12:16:07 UTC
Permalink
Hi Gil,

Here is a bit of code that we use for this. We normally either bind
on "localhost" or all interfaces. Should work for as well (I think)...

...
protected java.lang.String mAddress = null;
protected int mPort = 0;
protected org.snmp4j.TransportMapping mServerSocket = null;
protected org.snmp4j.Snmp mSNMP = null;

...
// read my configuration (like assign "mAddress" and "mPort")
...

if (mAddress == null) {
mServerSocket = new
org.snmp4j.transport.DefaultUdpTransportMapping(new
org.snmp4j.smi.UdpAddress(mPort));
} else {
mServerSocket = new
org.snmp4j.transport.DefaultUdpTransportMapping(new
org.snmp4j.smi.UdpAddress(java.net.InetAddress.getByName(mAddress), mPort));
}
mSNMP = new org.snmp4j.Snmp(mServerSocket);
mSNMP.addCommandResponder(this);
mServerSocket.listen();
Post by Gil Steiner
Hi,
I would like to use a different (pre-defined) IP address as a local address
when sending SNMP requests. In other words, I would like to bind the socket
to a given address instead of using the 'default' IP address.
I know that the 'bind' method supports such an option (by supplying an
address that is not null) but my question is how I can control this from
within SNMP4J. The bind method is not used directly from SNMP4J.
+gil
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________
_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j
-Deon
_____________________________________________________
TruTeq Wireless (Pty) Ltd. | Tel: +27 (0)12 667 1530
http://www.truteq.co.za | Fax: +27 (0)12 667 1531
Wireless communications for remote machine management

Continue reading on narkive:
Loading...