rtnetlink - macros to manipulate rtnetlink messages


   #include <asm/types.h>
   #include <linux/netlink.h>
   #include <linux/rtnetlink.h>
   #include <sys/socket.h>

   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);


   All  rtnetlink(7)  messages  consist of a netlink(7) 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
   attribute; attrlen is the running length of the attribute buffer.  When
   not  true  then  you  must  assume  there are no more attributes in the
   message, 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.


   These macros are nonstandard Linux extensions.


   This manual page is incomplete.


   Creating a rtnetlink message to set the MTU of a device:
       #include <linux/rtnetlink.h>


       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(&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 *) &req) +
       rta->rta_type = IFLA_MTU;
       rta->rta_len = RTA_LENGTH(sizeof(unsigned int));
       req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
       memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
       send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);


   netlink(3), netlink(7), rtnetlink(7)


   This page is part of release 4.09 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

More Linux Commands

tee(2) - duplicating pipe content - Linux manual page.......
tee() duplicates up to len bytes of data from the pipe referred to by the file descriptor fd_in to the pipe referred to by the file descriptor fd_out. It does n

rpcdebug(8) - set and clear NFS and RPC kernel debug flags
The rpcdebug command allows an administrator to set and clear the Linux kernels NFS client and server debug flags. Setting these flags causes the kernel to emit

XCompositeVersion(3) - X Composite Extension library........
The composite extension provides several related mechanisms: Per-hierarchy storage The rendering of an entire hierarchy of windows is redirected to off-screen s

TAP::Formatter::Console(3pm) - Harness output delegate for d
TAP::Formatter::Console.3pm - This provides console orientated output formatting for TAP::Harness. SYNOPSIS use TAP::Formatter::Console; my $harness = TAP::Form

pnmtoddif(1) - Convert a PNM image to DDIF format (ManPage)
This program is part of Netpbm(1) pnmtoddif takes a PNM image and converts it into a DDIF image file. pnmtoddif writes PBM format (bitmap) data as a 1 bit DDIF,

newusers(8) update and create new users in batch (Man Page)
The newusers command reads a file (or the standard input by default) and uses this information to update a set of existing users or to create new users. Each li

git-stripspace(1) - Filter out empty lines - Linux man page
Clean the input in the manner used by Git for text such as commit messages, notes, tags and branch descriptions. With no arguments, this will: * remove trailing

readcd(1) - read or write data Compact Discs (Man Page).....
Readom is used to read or write Compact Discs. The device refers to a device location similar to the one used in the wodim command. Refer to its manpage for det

pam_unix2(8) - Standard PAM module for traditional password
The pam_unix2 PAM module is for traditional password authentication. It uses standard calls from the glibc NSS libraries to retrieve and set account information

rename(1) - rename files (Commands - Linux manual page).....
rename will rename the specified files by replacing the first occurrence of expression in their name by replacement. OPTIONS -v, --verbose Give visual feedback

xlyap(6x) - display an array of Lyapunov exponents graphical
xlyap generates and graphically displays an array of Lyapunov exponents for a variety of iterated periodically forced non-linear maps of the unit interval. OPTI

XNextEvent(3) - select events by type - Linux manual page...
The XNextEvent function copies the first event from the event queue into the specified XEvent structure and then removes it from the queue. If the event queue i

We can't live, work or learn in freedom unless the software we use is free.