AF_UNIX sockets

Started by
6 comments, last by spraff 15 years, 3 months ago
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.
Advertisement
The third argument to socket isn't a port, it's a protocol.
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?
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".
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?
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.
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.
Funny, you have different man pages to me! Not sure what's going on there. Thanks for being patient.

This topic is closed to new replies.

Advertisement