0

I try to connect to my UNIX-socket server using openbsd-netcat, but have an error:

connect(): Protocol wrong type for socket

My socket type is SOCK_SEQPACKET, and it seems that nc tries to open it as SOCK_DGRAM or SOCK_STREAM. BTW, nc can't connect to anonymous UNIX-sockets (which name started with '\0').

So I wonder is there any ways to get socket type information from server to change arguments of socket() for successful connection? Or there's only one way: to look over all types while socket() will succeed?

Let me explain: what is the right thing to do in a situation where the client doesn't know the type of socket to which he needs to connect?

4
  • "what is the right thing to do in a situation where the client doesn't know the type of socket to which he needs to connect?" - try what it might be. socket name, socket type, application protocol ... are needed to contact the peer like the full email address and not just parts of it are needed to send an email. Commented Jan 19, 2022 at 8:53
  • @SteffenUllrich, let's say I know server IP and socket port, now I want to connect to socket, but don't know its type. Isn't there a way to determine this data without iterating over? Commented Jan 19, 2022 at 8:59
  • "Isn't there a way to determine this data without iterating over?" - No. The same with port or IP - if you don't know these you need to guess and try. Commented Jan 19, 2022 at 9:37
  • I don't know much about BSD (my knowledge is mostly Linux Oriented)... There should usually be some way to list open sockets on a system. Eg: sockstat cyberciti.biz/tips/… I would assume this could let you discover the socket type. Commented Jan 19, 2022 at 9:46

1 Answer 1

0

For Unix sockets, on the local machine, the output of lsof includes the type, e.g., type=SEQPACKET. Tested on debian / raspbian 12 (bookworm).

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.