• Advertisement
Sign in to follow this  

AF_UNIX sockets

This topic is 3342 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there. This is the first time I've tried to use Unix sockets. My code to create the server daemon is roughly this:
int socket_id = socket (AF_UNIX, SOCK_STREAM, MY_PORT);

If MY_PORT is 0, this works fine. "ss -lx" shows that the subsequent bind worked. If MY_PORT is some fixed value, say 12321, socket() fails with errno==93, which isn't a defined error. What's going on? I'm running Ubuntu 8.04.

Share this post


Link to post
Share on other sites
Advertisement
The third argument to socket isn't a port, it's a protocol.

Share this post


Link to post
Share on other sites
Oh right. Well thanks for pointing that out. Any chance you could point me to an example of binding a unix socket to a port? And what are legal values of the protocol paramater?

Share this post


Link to post
Share on other sites
You might try checking out the documentation for functions before asking questions on a message board. For a linux box, if you want to find information for a given function, you could try the man page first. In this case try typing "man socket" at the command line. And after that you might want to try "man bind".

Share this post


Link to post
Share on other sites
Comparing the IP socket data structures, there is no port for unix sockets. If unix sockets are referred to by file name only, why does "ss -lx" list port numbers?

Share this post


Link to post
Share on other sites
Sorry for posting what seems like an uninformed question, SiCrane, but I have been reading sockts documentation for a couple of hours. It's almost entirely geared to IP sockets, so I'm having a hard time finding the Unix Socket interpretation -- I blame the API, the arguments are overloaded, it's pretty shoddy design. I came here hoping someone with hands-on experience could comment.

Share this post


Link to post
Share on other sites
Let's see here: online, man socket tells me that man unix should be used to find out more information about local sockets. man unix in turn shows that the protocol must be 0.

man bind in turn shows an example of calling bind with unix sockets.

Share this post


Link to post
Share on other sites
Funny, you have different man pages to me! Not sure what's going on there. Thanks for being patient.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement