Is it possible to connect the socket before using sendmsg ()?

I am trying to pass fd between process and I found some example code like portlisten . In the sample, a recvmsg()

can take a bound socket as a parameter (and leave msghdr.msg_name as NULL), but sendmsg()

cannot — it must take sockaddr*

in msghdr.msg_name.

I tried to change the program by plugging in first, but couldn't, and found a comment how /* doesn't do anything at the moment

, but I don't understand why.

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

0


a source to share


2 answers


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



+1


a source


on the sendmsg messages page:

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



So this means that if you are using a TCP connection, the destination address in msghdr is ignored.

+1


a source







All Articles