java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

Post by mike_steph » Fri, 27 Jun 2003 00:48:47


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

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 packet on without beeing root on UNIX? NO?

what can I do to see which program is using the port?

thanks in advance

Mike
 
 
 

java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

Post by Shripathi » Fri, 27 Jun 2003 02:22:20


You need to be root unless you take special measures to use Port 162 (and
also other ports).



Use netstat.




HTH,

--
Shripathi Kamath
NETAPHOR SOFTWARE INC.
http://www.yqcomputer.com/

 
 
 

java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

Post by Alan J. Mc » Fri, 27 Jun 2003 21:07:02


Someone correct me if I'm wrong, but there is no need to use port 162 as the
source port when sending traps. You only need to have the destination port
as 162. So in your code, change the constructor of the DatagramSocket to
not specify a source port i.e to "new DatagramSocket()". The OS will
allocate a free local port.
[...]
But as noted above there is no need to use a 'priviledged' port.


But it won't matter now as the OS is now allocating a free port for you.
--
Alan J. McFarlane
http://www.yqcomputer.com/
Please follow-up in the newsgroup for the benefit of all.
 
 
 

java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

Post by Daniel FUC » Fri, 27 Jun 2003 22:55:23


And furthermore the process that uses port 162 is probably
the one you want to send the trap to (you want to send trap *to* port
162, you don't want to send them *from* port 162).

Hope this helps,

-- daniel
+------------------------------------------------------------------+
| D a n i e l F u c h s |
| Sun Microsystems http://www.yqcomputer.com/ : XXXX@XXXXX.COM |
+------------------------------------------------------------------+
 
 
 

java.net.BindException: permission denied and java.net.BindException: cannot bind address already in use

Post by Shripathi » Sat, 28 Jun 2003 03:47:45


the
port


You are correct. I incorrectly assumed that he meant receiving a trap. I
was addressing his question from a standpoint of the issue he posed from a
port number usage perspective.