CINXE.COM

rtnetlink

<html> <head> <title>rtnetlink</title> <META NAME="KEYWORDS" CONTENT="rtnetlink"> </head> <body BGCOLOR="#ffffff" LINK="#0000ff" VLINK="#0000ff" ALINK="#0000ff" TEXT="#000000"> <center> <h1><b>rtnetlink</b></h1></center> <PRE> <STRONG><A HREF="/man3/RTNETLINK">RTNETLINK(3)</A></STRONG> Linux Programmer's Manual <STRONG><A HREF="/man3/RTNETLINK">RTNETLINK(3)</A></STRONG> NAME rtnetlink - macros to manipulate rtnetlink messages SYNOPSIS #include &lt;asm/types.h&gt; #include &lt;linux/netlink.h&gt; #include &lt;linux/rtnetlink.h&gt; #include &lt;sys/socket.h&gt; rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE); int RTA_OK(struct rtattr *rta, int rtabuflen); void *RTA_DATA(struct rtattr *rta); unsigned int RTA_PAYLOAD(struct rtattr *rta); struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen); unsigned int RTA_LENGTH(unsigned int length); unsigned int RTA_SPACE(unsigned int length); DESCRIPTION All <STRONG><A HREF="/man7/rtnetlink">rtnetlink(7)</A></STRONG> messages consist of a <STRONG><A HREF="/man7/netlink">netlink(7)</A></STRONG> message header and appended attributes. The attributes should be manipulated only using the macros provided here. RTA_OK(rta, attrlen) returns true if rta points to a valid routing at- tribute; attrlen is the running length of the attribute buffer. When not true then you must assume there are no more attributes in the mes- sage, even if attrlen is nonzero. RTA_DATA(rta) returns a pointer to the start of this attribute's data. RTA_PAYLOAD(rta) returns the length of this attribute's data. RTA_NEXT(rta, attrlen) gets the next attribute after rta. Calling this macro will update attrlen. You should use RTA_OK to check the validity of the returned pointer. RTA_LENGTH(len) returns the length which is required for len bytes of data plus the header. RTA_SPACE(len) returns the amount of space which will be needed in a message with len bytes of data. CONFORMING TO These macros are nonstandard Linux extensions. BUGS This manual page is incomplete. EXAMPLE Creating a rtnetlink message to set the MTU of a device: #include &lt;linux/rtnetlink.h&gt; ... struct { struct nlmsghdr nh; struct ifinfomsg if; char attrbuf[512]; } req; struct rtattr *rta; unsigned int mtu = 1000; int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); memset(&amp;req, 0, sizeof(req)); req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); req.nh.nlmsg_flags = NLM_F_REQUEST; req.nh.nlmsg_type = RTM_NEWLINK; req.if.ifi_family = AF_UNSPEC; req.if.ifi_index = INTERFACE_INDEX; req.if.ifi_change = 0xffffffff; /* ??? */ rta = (struct rtattr *)(((char *) &amp;req) + NLMSG_ALIGN(req.nh.nlmsg_len)); rta-&gt;rta_type = IFLA_MTU; rta-&gt;rta_len = RTA_LENGTH(sizeof(unsigned int)); req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) + RTA_LENGTH(sizeof(mtu)); memcpy(RTA_DATA(rta), &amp;mtu, sizeof(mtu)); send(rtnetlink_sk, &amp;req, req.nh.nlmsg_len, 0); SEE ALSO <STRONG><A HREF="/man3/netlink">netlink(3)</A></STRONG>, <STRONG><A HREF="/man7/netlink">netlink(7)</A></STRONG>, <STRONG><A HREF="/man7/rtnetlink">rtnetlink(7)</A></STRONG> COLOPHON This page is part of release 5.05 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. GNU 2014-09-06 <STRONG><A HREF="/man3/RTNETLINK">RTNETLINK(3)</A></STRONG></PRE> <center> <h6>Man Pages Copyright Respective Owners. Site Copyright (C) 1994 - 2025 <a href="http://www.he.net">Hurricane Electric</a>. All Rights Reserved.</h6></center> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10