# rtnetlink

## NAME



           rtnetlink - macros to manipulate rtnetlink messages
    


## LIBRARY



           Standard C library (_libc_ , _-lc_)
    


## SYNOPSIS



           **#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** _size_**);**
    
           **void *RTA_DATA(struct rtattr ***_rta_**);**
           **unsigned int RTA_PAYLOAD(struct rtattr ***_rta_**);**
    
           **struct rtattr *RTA_NEXT(struct rtattr ***_rta_**, unsigned int** _size_**);**
    
           **unsigned int RTA_LENGTH(unsigned int** _size_**);**
           **unsigned int RTA_SPACE(unsigned int** _size_**);**
    


## DESCRIPTION



           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_**,**_size_**)** returns true if _rta_ points to a valid routing
           attribute; _size_ is the running size of the attribute buffer.  When
           not true then you must assume there are no more attributes in the
           message, even if _size_ is nonzero.
    
           **RTA_DATA(**_rta_**)** returns a pointer to the start of this attribute's
           data.
    
           **RTA_PAYLOAD(**_rta_**)** returns the size of this attribute's data.
    
           **RTA_NEXT(**_rta_**,**_size_**)** gets the next attribute after _rta_.  Calling
           this macro will update _size_.  You should use **RTA_OK** to check the
           validity of the returned pointer.
    
           **RTA_LENGTH(**_size_**)** returns the size which is required for _size_ bytes
           of data plus the header.
    
           **RTA_SPACE(**_size_**)** returns the amount of space which will be needed
           in a message with _size_ bytes of data.
    


## STANDARDS



           Linux.
    


## BUGS



           This manual page is incomplete.
    


## EXAMPLES



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


* * *