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?
a source to share
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.
a source to share