problem : SNMP port used when starting my java program

problem : SNMP port used when starting my java program

Post by mike_stepha.. » Fri, 27 Jun 2003 18:30:34



Quote:> I'm trying to send a TRAP PDU using a java SNMP stack
> and I got following exception:
> java.net.BindException: Address in use: Cannot bind
> it lloks like the snmpd is locking the port
> here 's the piece of code:
> ....
> static final SNMP_TRAP_PORT 162;
> dSocket = new DatagramSocket(SNMP_TRAP_PORT);

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

> dSocket.send(outPacket);

> Also, when I'm trying to run this on a Unix I got:
> java.net.BindException: permission denied

> I though I could send a SNMP packet without my program beeing root on UNIX? NO?

can I send SNMP packets using another port???

- Show quoted text -

 
 
 

problem : SNMP port used when starting my java program

Post by Rainer Temm » Sat, 28 Jun 2003 02:52:20



Quote:> > I'm trying to send a TRAP PDU using a java SNMP stack
> > and I got following exception:
> > java.net.BindException: Address in use: Cannot bind
> > it lloks like the snmpd is locking the port

> > here 's the piece of code:
> > ....
> > static final SNMP_TRAP_PORT 162;
> > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

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

> > dSocket.send(outPacket);

> > Also, when I'm trying to run this on a Unix I got:
> > java.net.BindException: permission denied

> > I though I could send a SNMP packet without my program beeing root on
UNIX? NO?

> can I send SNMP packets using another port???

Hi mike_stephanos,

to my knowledge snmp-packets can be sent from any source-port...
   port 162/udp is the (wellknown) portnumber of the receiving-progess
(usually part
   of an snmp-monitoring istallation.)
   would this not be the case (meaning if one would have to use 162/udp as
source-port as well),
   - only root-processes would be able to send traps,
   - only a single process (on a system) could send traps at a certain time,
      because not more than one process can bind to this port at a certain
time.

So, give it a go, and try with "dSocket = new DatagramSocket(0);" ...
   the system should assign this socket a portnumber from the dynamic-range
   (one that is available of corse) when you send the first packet...
   the socket will hold this portnumber until you close it.

regards ... rainer

 
 
 

problem : SNMP port used when starting my java program

Post by Sean Burk » Sat, 28 Jun 2003 03:04:33



> > I'm trying to send a TRAP PDU using a java SNMP stack
> > and I got following exception:
> > java.net.BindException: Address in use: Cannot bind
> > it lloks like the snmpd is locking the port

> > here 's the piece of code:
> > ....
> > static final SNMP_TRAP_PORT 162;
> > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

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

> > dSocket.send(outPacket);

> > Also, when I'm trying to run this on a Unix I got:
> > java.net.BindException: permission denied

> > I though I could send a SNMP packet without my program beeing root on UNIX? NO?

> can I send SNMP packets using another port???

Yes, you can. As I understand it, port 162 is the standard
port for receiving traps, but you aren't required to send
them from that port.

Check whether DatagramSocket has a constructor with no
arguments, or whether there is a "wildcard" value for
the port argument. You can let the system choose any
nonprivileged port that is available.

-SEan

 
 
 

problem : SNMP port used when starting my java program

Post by mike_stepha.. » Sat, 28 Jun 2003 22:50:02


Thanks again Sean,

That was it!
it's working without specifying the port 162 for sending (that port on
a UNIX station is a privileged port and is
already bind by 'snmpd' daemon for listening for incoming traps.

dSocket = new DatagramSocket();   is working!!

Thanks a lot for your help.

Mike



> > > I'm trying to send a TRAP PDU using a java SNMP stack
> > > and I got following exception:
> > > java.net.BindException: Address in use: Cannot bind
> > > it lloks like the snmpd is locking the port

> > > here 's the piece of code:
> > > ....
> > > static final SNMP_TRAP_PORT 162;
> > > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

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

> > > dSocket.send(outPacket);

> > > Also, when I'm trying to run this on a Unix I got:
> > > java.net.BindException: permission denied

> > > I though I could send a SNMP packet without my program beeing root on UNIX? NO?

> > can I send SNMP packets using another port???

> Yes, you can. As I understand it, port 162 is the standard
> port for receiving traps, but you aren't required to send
> them from that port.

> Check whether DatagramSocket has a constructor with no
> arguments, or whether there is a "wildcard" value for
> the port argument. You can let the system choose any
> nonprivileged port that is available.

> -SEan

 
 
 

problem : SNMP port used when starting my java program

Post by mike_stepha.. » Sat, 28 Jun 2003 22:53:02


Hi Rainer,
 yes it's if I create the socket without specifying the port.
I think port 162 was binded by snmpd running as root

Thanks a lot for your help

Mike



> > > I'm trying to send a TRAP PDU using a java SNMP stack
> > > and I got following exception:
> > > java.net.BindException: Address in use: Cannot bind
> > > it lloks like the snmpd is locking the port

> > > here 's the piece of code:
> > > ....
> > > static final SNMP_TRAP_PORT 162;
> > > dSocket = new DatagramSocket(SNMP_TRAP_PORT);

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

> > > dSocket.send(outPacket);

> > > Also, when I'm trying to run this on a Unix I got:
> > > java.net.BindException: permission denied

> > > I though I could send a SNMP packet without my program beeing root on
>  UNIX? NO?

> > can I send SNMP packets using another port???

> Hi mike_stephanos,

> to my knowledge snmp-packets can be sent from any source-port...
>    port 162/udp is the (wellknown) portnumber of the receiving-progess
> (usually part
>    of an snmp-monitoring istallation.)
>    would this not be the case (meaning if one would have to use 162/udp as
> source-port as well),
>    - only root-processes would be able to send traps,
>    - only a single process (on a system) could send traps at a certain time,
>       because not more than one process can bind to this port at a certain
> time.

> So, give it a go, and try with "dSocket = new DatagramSocket(0);" ...
>    the system should assign this socket a portnumber from the dynamic-range
>    (one that is available of corse) when you send the first packet...
>    the socket will hold this portnumber until you close it.

> regards ... rainer

 
 
 

1. java exception when running a java program sending SNMP traps

I got a java program from a JAVA SNMP Stackwhich is sending a snmp
trap pdu

it runs OK on NT but on UNIX I got: a java exception address already
in use: cannot bind

How can I make this program running?
.......................
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);

.................

2. X server for STB Nitro video card with chipset CL5446

3. Calling a java program from a C++ program using execl

4. X Setup problem...

5. Java, Java, Java, Java, Java, Java .....

6. ftp & telnet,connection refused

7. cvs commit: ports/java Makefile ports/java/forte Makefile distinfo (fwd)

8. AAAH!...HELP!...UMSDOS not working...PLEASE!!!

9. cvs commit: ports/java Makefile ports/java/forte Makefile distinfo

10. snmp agent using ucd-snmp-3.5.2

11. Programming Snmp using Unix C

12. Problem adding tty port using 128 Port Async Adapter with 16 port Async Node