tags:

views:

163

answers:

2

I'm trying to pass fd between process and I found the sample code like portlisten. In the sample, a recvmsg() can take a bound socket as parameter (and leave msghdr.msg_name as NULL) but the sendmsg() cannot - it must take a sockaddr* in the msghdr.msg_name.

I tried to modify the program by connecting first but failed, and found the comment as /* doesn't do anything at the moment but I don't understand why.

Is this a limitation of sendmsg() that it cannot take an already connected socket as parameter?

A: 

from the sendmsg man page:

The sendmsg() function shall send a message through a connection-mode or connectionless-mode socket. If the socket is connectionless-mode, the message shall be sent to the address specified by msghdr. If the socket is connection-mode, the destination address in msghdr shall be ignored.

So that means that if you use a TCP connection the destination address in msghdr is ignored.

lothar
So what about UNIX domain sockets? Can I use them in connected mode?
Francis
+1  A: 

Look at the source code of libancillary. I can't post a link because I'm a new user, but you'll find it on Google.

acd
that looks nice!
Francis