Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does ancillary data in sendmsg() work?

sendmsg() allows sending ancillary data to another socket, I am wondering how this works.

1) Is the ancillary data packed along with the normal message?

2) If so, how would a remote receiving socket know how to parse this?

3) How would a remote receiving client retrieve this ancillary data?

Thanks.

like image 524
wei Avatar asked Jan 02 '13 19:01

wei


2 Answers

Ancillary data is not send on the wire - NEVER. For Unix Domain sockets, Ancillary data is used to send Or receive file descriptors between processes to share or load balance the tasks. Note : Unix Domain sockets transfer the information between processes running on same machine and not between processes running on different machines.

Again, in case of processes running on different machines : your packet without using any ancillary concept would be exactly same as the packet when ancillary concept is applied on sending machine (Or receiving machine). Hence, Ancillary Data is not something shipped with your packet.

Ancillary data is used to receive the EXTRA packet related services/information from the kernel to user space application, which is not available otherwise. For example, say machine B receives some packet on wire and you want to know the ingress interface the packet arrived from ? How would you know this ? Ancillary Data come to the rescue.

Ancillary data are kind of flags set in ancillary control buffer and passed to kernel when sendmsg()/recvmsg() is called, which tells the kernel that when packet is send or arrive, what extra services/information is to be provided to application invoking the calls.

Ancillary Data is the means Communication between kernel and user space application Or between processes on same machine in case of UNIX sockets. It is not something the packet on wire has.

For your reference, download code example here which runs perfectly on my ubuntu machine. Ancillary data concept is demonstrated in src/igmp_pkt_reciever.c .

like image 171
Abhishek Sagar Avatar answered Oct 15 '22 14:10

Abhishek Sagar


You can only use ancillary data in a few select ways:

  • You can use it to get the receiving interface (IPv4)
  • You can use it to specify the hop limit (for IPv6)
  • You can use it to specify traffic class (again, IPv6)
  • ....
  • You can use it to pass/receive file descriptors or user credentials (Unix domain)

The three cases are only artificial API methods of receiving control information from kernel land via recvmsg(2). The last one is the most interesting: the only case where ancillary data is actually sent is with Unix domain sockets where everything happens in the kernel so nothing actually gets on the wire.

like image 32
cnicutar Avatar answered Oct 15 '22 12:10

cnicutar