1RTNETLINK(3) Linux Programmer's Manual RTNETLINK(3)
2
3
4
6 rtnetlink - Macros to manipulate rtnetlink messages
7
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(PF_NETLINK, int socket_type, NETLINK_ROUTE);
15 int RTA_OK(struct rtattr *rta, int rtabuflen);
16 void *RTA_DATA(struct rtattr *rta);
17 unsigned int RTA_PAYLOAD(struct rtattr *rta);
18 struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen);
19 unsigned int RTA_LENGTH(unsigned int length);
20 unsigned int RTA_SPACE(unsigned int length);
21
23 All rtnetlink(7) messages consist of a netlink(7) message header and
24 appended attributes. The attributes should be only manipulated using
25 the macros provided here.
26
27
28 RTA_OK(rta, attrlen) returns true if rta points to a valid routing
29 attribute; attrlen is the running length of the attribute buffer.
30 When not true then you must assume there are no more attributes in the
31 message, even if attrlen is non-zero.
32 RTA_DATA(rta) returns a pointer to the start of this attribute's data.
33 RTA_PAYLOAD(rta) returns the length of this attribute's data.
34 RTA_NEXT(rta, attrlen) gets the next attribute after rta. Calling this
35 macro will update attrlen. You should use RTA_OK to check for the
36 validity of the returned pointer.
37 RTA_LENGTH(len) returns the length which is required for len bytes of
38 data plus the header.
39 RTA_SPACE(len) returns the amount of space which will be needed in the
40 message with len bytes of data.
41
42
44 Creating a rtnetlink message to set a MTU of a device.
45 struct {
46 struct nlmsghdr nh;
47 struct ifinfomsg if;
48 char attrbuf[512];
49 } req;
50 struct rtattr *rta;
51 unsigned int mtu = 1000;
52 int rtnetlink_sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
53
54 memset(&req, 0, sizeof(req));
55 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
56 req.nh.nlmsg_flags = NLM_F_REQUEST;
57 req.nh.nlmsg_type = RTML_NEWLINK;
58 req.if.ifi_family = AF_UNSPEC;
59 req.if.ifi_index = INTERFACE_INDEX;
60 req.if.ifi_change = 0xffffffff; /* ???*/
61 rta = (struct rtattr *)(((char *) &req) +
62 NLMSG_ALIGN(n->nlmsg_len));
63 rta->rta_type = IFLA_MTU;
64 rta->rta_len = sizeof(unsigned int);
65 req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) +
66 RTA_LENGTH(sizeof(mtu));
67 memcpy(RTA_DATA(rta), &mtu, sizeof (mtu));
68 send(rtnetlink_sk, &req, req.n.nlmsg_len);
69
70
72 This manual page is lacking and incomplete.
73
74
76 netlink(3), netlink(7), rtnetlink(7)
77
78
79
80Linux Man Page 1999-05-14 RTNETLINK(3)