1RTNETLINK(3)               Linux Programmer's Manual              RTNETLINK(3)
2
3
4

NAME

6       rtnetlink - macros to manipulate rtnetlink messages
7

SYNOPSIS

9       #include <asm/types.h>
10       #include <linux/netlink.h>
11       #include <linux/rtnetlink.h>
12       #include <sys/socket.h>
13
14       rtnetlink_socket = socket(AF_NETLINK, int socket_type, NETLINK_ROUTE);
15
16       int RTA_OK(struct rtattr *rta, int rtabuflen);
17
18       void *RTA_DATA(struct rtattr *rta);
19
20       unsigned int RTA_PAYLOAD(struct rtattr *rta);
21
22       struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
23
24       unsigned int RTA_LENGTH(unsigned int length);
25
26       unsigned int RTA_SPACE(unsigned int length);
27

DESCRIPTION

29       All  rtnetlink(7)  messages  consist of a netlink(7) message header and
30       appended attributes.  The attributes should be only  manipulated  using
31       the macros provided here.
32
33       RTA_OK(rta,  attrlen)  returns  true  if  rta points to a valid routing
34       attribute; attrlen is the running length of the attribute buffer.  When
35       not  true then you must assume there are no more attributes in the mes‐
36       sage, even if attrlen is non-zero.
37
38       RTA_DATA(rta) returns a pointer to the start of this attribute's data.
39
40       RTA_PAYLOAD(rta) returns the length of this attribute's data.
41
42       RTA_NEXT(rta, attrlen) gets the next attribute after rta.  Calling this
43       macro will update attrlen.  You should use RTA_OK to check the validity
44       of the returned pointer.
45
46       RTA_LENGTH(len) returns the length which is required for len  bytes  of
47       data plus the header.
48
49       RTA_SPACE(len)  returns  the  amount of space which will be needed in a
50       message with len bytes of data.
51

CONFORMING TO

53       These macros are non-standard Linux extensions.
54

BUGS

56       This manual page is incomplete.
57

EXAMPLE

59       Creating a rtnetlink message to set the MTU of a device:
60
61           struct {
62               struct nlmsghdr  nh;
63               struct ifinfomsg if;
64               char             attrbuf[512];
65           } req;
66
67           struct rtattr *rta;
68           unsigned int mtu = 1000;
69
70           int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
71
72           memset(&req, 0, sizeof(req));
73           req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
74           req.nh.nlmsg_flags = NLM_F_REQUEST;
75           req.nh.nlmsg_type = RTML_NEWLINK;
76           req.if.ifi_family = AF_UNSPEC;
77           req.if.ifi_index = INTERFACE_INDEX;
78           req.if.ifi_change = 0xffffffff; /* ???*/
79           rta = (struct rtattr *)(((char *) &req) +
80                                         NLMSG_ALIGN(n->nlmsg_len));
81           rta->rta_type = IFLA_MTU;
82           rta->rta_len = sizeof(unsigned int);
83           req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) +
84                                         RTA_LENGTH(sizeof(mtu));
85           memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
86           send(rtnetlink_sk, &req, req.n.nlmsg_len);
87

SEE ALSO

89       netlink(3), netlink(7), rtnetlink(7)
90

COLOPHON

92       This page is part of release 3.22 of the Linux  man-pages  project.   A
93       description  of  the project, and information about reporting bugs, can
94       be found at http://www.kernel.org/doc/man-pages/.
95
96
97
98GNU                               2008-08-08                      RTNETLINK(3)
Impressum