UNIX Network Programming Reading Notes: Auxiliary Data

Source: Internet
Author: User

Auxiliary data (ancillary data)You can call the sendmsg and recvmsg functions to send and receive messages using the msg_control and msg_controllen members in the msghdr structure.

Another name for auxiliary data isControl information).

Cmsg_level; cmsg_type;

Secondary data directed by msg_control must be properly aligned for each cmsghdr structure, as shown below:

               control[CMSG_SPACE((

Shows an example of two secondary data objects in a Control Buffer:

<Sys/param. h> cmsghdr * numeric (msghdr * mhdrptr, cmsghdr ** CMSG_DATA (cmsghdr * CMSG_LEN (unsigned CMSG_SPACE (unsigned

These macros can be used in the following pseudo-code format:

 cmsghdr    *(cmsgptr = CMSG_FIRSTHDR(&msg); cmsgptr != NULL; cmsgptr = CMSG_NXTHDR(&(cmsgptr->cmsg_level == ... && cmsgptr->cmsg_type ==*=

CMSG_FIRSTHDR returns a pointer to the first secondary data object. However, if no secondary data exists in the msghdr structure (or msg_control is a null pointer, or cmsg_len is smaller than the size of a cmsghdr structure ), then a null pointer is returned. When no secondary data object exists in the Control Buffer, CMSG_NXTHDR returns a null pointer.

The difference between CMSG_LEN and CMSG_SPACE is that the former does not include the possible Padding Bytes after the data part of the auxiliary data object, and therefore the returned value is used to store the value in the cmsg_len member, the latter is counted as possible filling bytes at the end of the top, so the returned value is the size value used to dynamically allocate space for the auxiliary object.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.