1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
3 .\" %%%LICENSE_START(VERBATIM_ONE_PARA)
4 .\" Permission is granted to distribute possibly modified copies
5 .\" of this page provided the header is included verbatim,
6 .\" and in case of nontrivial modification author and date
7 .\" of the modification is added to the header.
10 .\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
12 .TH RTNETLINK 3 2014-09-06 "GNU" "Linux Programmer's Manual"
14 rtnetlink \- macros to manipulate rtnetlink messages
16 .B #include <asm/types.h>
18 .B #include <linux/netlink.h>
20 .B #include <linux/rtnetlink.h>
22 .B #include <sys/socket.h>
24 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
27 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
29 .BI "void *RTA_DATA(struct rtattr *" rta );
31 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
33 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
34 ", unsigned int " rtabuflen );
36 .BI "unsigned int RTA_LENGTH(unsigned int " length );
38 .BI "unsigned int RTA_SPACE(unsigned int "length );
44 message header and appended attributes.
45 The attributes should be manipulated only using the macros provided here.
47 .BI RTA_OK( rta ", " attrlen )
50 points to a valid routing attribute;
52 is the running length of the attribute buffer.
53 When not true then you must assume there are no more attributes in the
59 returns a pointer to the start of this attribute's data.
61 .BI RTA_PAYLOAD( rta )
62 returns the length of this attribute's data.
64 .BI RTA_NEXT( rta ", " attrlen )
65 gets the next attribute after
67 Calling this macro will update
71 to check the validity of the returned pointer.
74 returns the length which is required for
76 bytes of data plus the header.
79 returns the amount of space which will be needed in a message with
83 These macros are nonstandard Linux extensions.
85 This manual page is incomplete.
87 .\" FIXME . ? would be better to use libnetlink in the EXAMPLE code here
88 Creating a rtnetlink message to set the MTU of a device:
90 #include <linux/rtnetlink.h>
101 unsigned int mtu = 1000;
103 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
105 memset(&req, 0, sizeof(req));
106 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
107 req.nh.nlmsg_flags = NLM_F_REQUEST;
108 req.nh.nlmsg_type = RTM_NEWLINK;
109 req.if.ifi_family = AF_UNSPEC;
110 req.if.ifi_index = INTERFACE_INDEX;
111 req.if.ifi_change = 0xffffffff; /* ??? */
112 rta = (struct rtattr *)(((char *) &req) +
113 NLMSG_ALIGN(req.nh.nlmsg_len));
114 rta\->rta_type = IFLA_MTU;
115 rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
116 req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
117 RTA_LENGTH(sizeof(mtu));
118 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
119 send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);