snmp port

snmp port

Post by mike_stepha.. » Fri, 27 Jun 2003 01:51:06



I got a java program from a JAVA SNMP Stack I'm trying to use
to send basic SNMP traps:
............
static DatagramSocket dSocket;
static final int SNMP_TRAP_PORT = 162;
dSocket = new DatagramSocket(SNMP_TRAP_PORT);

SNMPMessage message = new SNMPMessage(version, community, pdu);

DatagramPacket outPacket = new DatagramPacket(messageEncoding,
messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
dSocket.send(outPacket);
................

when I run it from a NT it works
but from a UNIX I got: java.net.BindException: Address in use: Cannot
bind

how can I make my program running OK on Unix

static DatagramSocket dSocket;
static final int SNMP_TRAP_PORT = 162;
dSocket = new DatagramSocket(SNMP_TRAP_PORT);

SNMPMessage message = new SNMPMessage(version, community, pdu);

.........
DatagramPacket outPacket = new DatagramPacket(messageEncoding,
messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
dSocket.send(outPacket);

 
 
 

snmp port

Post by Sean Burk » Fri, 27 Jun 2003 06:23:37



> I got a java program from a JAVA SNMP Stack I'm trying to use
> to send basic SNMP traps:
> ............
> static DatagramSocket dSocket;
> static final int SNMP_TRAP_PORT = 162;
> dSocket = new DatagramSocket(SNMP_TRAP_PORT);

> SNMPMessage message = new SNMPMessage(version, community, pdu);

> DatagramPacket outPacket = new DatagramPacket(messageEncoding,
> messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
> dSocket.send(outPacket);
> ................

> when I run it from a NT it works
> but from a UNIX I got: java.net.BindException: Address in use: Cannot
> bind

> how can I make my program running OK on Unix

> static DatagramSocket dSocket;
> static final int SNMP_TRAP_PORT = 162;
> dSocket = new DatagramSocket(SNMP_TRAP_PORT);

> SNMPMessage message = new SNMPMessage(version, community, pdu);

> .........
> DatagramPacket outPacket = new DatagramPacket(messageEncoding,
> messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
> dSocket.send(outPacket);

The error message says that some other process already
is using the address. I assume that the exception is
being thrown from

  dSocket = new DatagramSocket(SNMP_TRAP_PORT);

but you might want to "focus" your catch more tightly
so you can be sure. If that DatagramSocket() constructor
is creating a socket whose local address is bound to port
162, then there are two potential problems:

1. Some other process already has that port allocated.
   Use netstat to check.

2. You can't bind to it because the process doesn't have
   root privilege, which is needed to bind to ports 0-1023.

The error message implies that 1. is the problem.

-SEan

 
 
 

snmp port

Post by mike_stepha.. » Sat, 28 Jun 2003 22:43:09


Hi Sean,

Your're right!!

I've tried :

dSocket = new DatagramSocket();
instead, so now it's allocating a free random port for sending

and now it's working!!

The problem I think was coming from 'snmpd' daemon running which is
started as
root and binds already to privileged port 162 for listening to
incoming traps

and my user java application could also not bind to that privileged
port as it was not started as root and the port was already used by
snmpd

Thanks a lot for your help,

Mike



> > I got a java program from a JAVA SNMP Stack I'm trying to use
> > to send basic SNMP traps:
> > ............
> > static DatagramSocket dSocket;
> > static final int SNMP_TRAP_PORT = 162;
> > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

> > SNMPMessage message = new SNMPMessage(version, community, pdu);

> > DatagramPacket outPacket = new DatagramPacket(messageEncoding,
> > messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
> > dSocket.send(outPacket);
> > ................

> > when I run it from a NT it works
> > but from a UNIX I got: java.net.BindException: Address in use: Cannot
> > bind

> > how can I make my program running OK on Unix

> > static DatagramSocket dSocket;
> > static final int SNMP_TRAP_PORT = 162;
> > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

> > SNMPMessage message = new SNMPMessage(version, community, pdu);

> > .........
> > DatagramPacket outPacket = new DatagramPacket(messageEncoding,
> > messageEncoding.length, hostAddress, SNMP_TRAP_PORT);
> > dSocket.send(outPacket);

> The error message says that some other process already
> is using the address. I assume that the exception is
> being thrown from

>   dSocket = new DatagramSocket(SNMP_TRAP_PORT);

> but you might want to "focus" your catch more tightly
> so you can be sure. If that DatagramSocket() constructor
> is creating a socket whose local address is bound to port
> 162, then there are two potential problems:

> 1. Some other process already has that port allocated.
>    Use netstat to check.

> 2. You can't bind to it because the process doesn't have
>    root privilege, which is needed to bind to ports 0-1023.

> The error message implies that 1. is the problem.

> -SEan