[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: locating blocked port




> On Jan 31, 2023, at 8:05 AM, Haines Brown <haines@histomat.net> wrote:
> 
> I have an  application that refuses to start because  its port is 
> blocked. But I have difficulty knowing what port it is

I would try strace, which shows you all system calls being made.  In this case, it is probably bind() that is returning an error.

strace -e trace=%net java -jar /usr/local/share/JabRef/JabRef-3.2.jar

Or

strace -e trace=%net java -jar /usr/local/share/JabRef/JabRef-3.2.jar 2>&1 | grep bind

For example:

$ cat test.py 
#!/usr/bin/env python3

import socket
s = socket.socket()
try:
   s.bind(('0.0.0.0', 56))
except:
   pass
$ python3 test.py # doesn't print any output
$ strace -e trace=%net python3 test.py 2>&1 | grep bind
bind(3, {sa_family=AF_INET, sin_port=htons(56), sin_addr=inet_addr("0.0.0.0")}, 16) = -1 EACCES (Permission denied)

The value of sin_port is what you are looking for.

> How do I know from this what port the java application tried to use?
> 
> I try:
> 
> $ strings $(which jabref) | wc -l
>   56
> 

strings might be helpful (maybe?), but in this case, you are piping it to wc -l, which is simply counting the number of printable character sequences that were found in jabref.  If that also happens to be the port number, then it is coincidental.

> So I try:
> 
>   $ sudo ss -pt state listening 'sport = :56'
>   Recv-Q   Send-Q    Local Address:Port   Peer Address:Port Process
> 
> This seems a null return. Dores this mean jabref is not using port 
> 56?

Well, it tells you that nothing (including jabref) is listening on TCP port 56, but it won't tell you about why something *failed* to listen.  See strace above.

Casey

Reply to: