f



problem : SNMP port used when starting my java program

> 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???

>
0
mike_stephanos
6/26/2003 9:30:34 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

4 Replies
1058 Views

Similar Articles

[PageSpeed] 0

<mike_stephanos@yahoo.com>
> > 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


0
Rainer
6/26/2003 5:52:20 PM
mike_stephanos@yahoo.com (mike_stephanos@yahoo.com) writes:

> > 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

0
Sean
6/26/2003 6:04:33 PM
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

Sean Burke <burke_sp31415@pacbell.net> wrote in message news:<x7brwk67gw.fsf@bolo.xenadyne.com>...
> mike_stephanos@yahoo.com (mike_stephanos@yahoo.com) writes:
> 
> > > 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
0
mike_stephanos
6/27/2003 1:50:02 PM
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

"Rainer Temme" <Rainer.Temme@NoSpam.Siemens.Com> wrote in message news:<bdfboj$dv8$1@news.mch.sbs.de>...
> <mike_stephanos@yahoo.com>
> > > 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
0
mike_stephanos
6/27/2003 1:53:02 PM
Reply: