Common macro definitions in Netlink

Source: Internet
Author: User

In linux/netlink. h, some macros are defined to facilitate message processing. These macros include:

# Define NLMSG_ALIGNTO 4 # define NLMSG_ALIGN (len) + NLMSG_ALIGNTO-1 )&~ (NLMSG_ALIGNTO-1 ))


 

The macro NLMSG_ALIGN (len) is used to obtain the minimum value not smaller than len and the byte align.

# Define NLMSG_LENGTH (len) + NLMSG_ALIGN (sizeof (struct nlmsghdr )))


 

The macro NLMSG_LENGTH (len) is used to calculate the actual message length when the data part length is len. It is generally used to allocate message cache.

# Define nlmsg_space (LEN) nlmsg_align (nlmsg_length (LEN ))


 

The macro NLMSG_SPACE (len) returns the minimum value not less than NLMSG_LENGTH (len) and the byte alignment. It is also used to allocate message cache.

# Define nlmsg_data (NLH) (void *) (char *) NLH) + nlmsg_length (0 )))


 

The macro NLMSG_DATA (nlh) is used to obtain the first address of the Data part of the message. This macro is used to set and read the data part of the message.

# Define nlmsg_next (NLH, Len) (LEN)-= nlmsg_align (NLH)-> nlmsg_len),/(struct nlmsghdr *) (char *) (NLH )) + nlmsg_align (NLH)-> nlmsg_len )))


 

Macro NLMSG_NEXT (nlh, len) is used to obtain the first address of the next message, and len is also reduced to the total length of the remaining message, this macro is generally used when a message is divided into several parts for sending or receiving.

# Define nlmsg_ OK (NLH, Len) (LEN)> = (INT) sizeof (struct nlmsghdr) &/(NLH)-> nlmsg_len> = sizeof (struct nlmsghdr) &/(NLH)-> nlmsg_len <= (LEN ))


 

The macro NLMSG_ OK (nlh, len) is used to determine whether the message has the length of len.

# Define nlmsg_payload (NLH, Len) (NLH)-> nlmsg_len-nlmsg_space (LEN )))


 

Macro NLMSG_PAYLOAD (nlh, len) is used to return the length of payload.

Function close is used to close the opened netlink socket.

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.