1rtnetlink(3)               Library Functions Manual               rtnetlink(3)
2
3
4

NAME

6       rtnetlink - macros to manipulate rtnetlink messages
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

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

STANDARDS

54       Linux.
55

BUGS

57       This manual page is incomplete.
58

EXAMPLES

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

SEE ALSO

94       netlink(3), netlink(7), rtnetlink(7)
95
96
97
98Linux man-pages 6.05              2023-07-15                      rtnetlink(3)
Impressum