]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/rtnetlink.3
accept.2, execve.2, futimesat.2, getresuid.2, getrlimit.2, madvise.2, mq_getsetattr...
[thirdparty/man-pages.git] / man3 / rtnetlink.3
1 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2 .\" Permission is granted to distribute possibly modified copies
3 .\" of this page provided the header is included verbatim,
4 .\" and in case of nontrivial modification author and date
5 .\" of the modification is added to the header.
6 .\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
7 .TH RTNETLINK 3 2010-01-11 "GNU" "Linux Programmer's Manual"
8 .SH NAME
9 rtnetlink \- macros to manipulate rtnetlink messages
10 .SH SYNOPSIS
11 .B #include <asm/types.h>
12 .br
13 .B #include <linux/netlink.h>
14 .br
15 .B #include <linux/rtnetlink.h>
16 .br
17 .B #include <sys/socket.h>
18
19 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
20 ", NETLINK_ROUTE);"
21 .sp
22 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
23 .sp
24 .BI "void *RTA_DATA(struct rtattr *" rta );
25 .sp
26 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
27 .sp
28 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
29 ", unsigned int " rtabuflen );
30 .sp
31 .BI "unsigned int RTA_LENGTH(unsigned int " length );
32 .sp
33 .BI "unsigned int RTA_SPACE(unsigned int "length );
34 .SH DESCRIPTION
35 All
36 .BR rtnetlink (7)
37 messages consist of a
38 .BR netlink (7)
39 message header and appended attributes.
40 The attributes should be only
41 manipulated using the macros provided here.
42 .PP
43 .BI RTA_OK( rta ", " attrlen )
44 returns true if
45 .I rta
46 points to a valid routing attribute;
47 .I attrlen
48 is the running length of the attribute buffer.
49 When not true then you must assume there are no more attributes in the
50 message, even if
51 .I attrlen
52 is non-zero.
53 .PP
54 .BI RTA_DATA( rta )
55 returns a pointer to the start of this attribute's data.
56 .PP
57 .BI RTA_PAYLOAD( rta )
58 returns the length of this attribute's data.
59 .PP
60 .BI RTA_NEXT( rta ", " attrlen )
61 gets the next attribute after
62 .IR rta .
63 Calling this macro will update
64 .IR attrlen .
65 You should use
66 .B RTA_OK
67 to check the validity of the returned pointer.
68 .PP
69 .BI RTA_LENGTH( len )
70 returns the length which is required for
71 .I len
72 bytes of data plus the header.
73 .PP
74 .BI RTA_SPACE( len )
75 returns the amount of space which will be needed in a message with
76 .I len
77 bytes of data.
78 .SH CONFORMING TO
79 These macros are nonstandard Linux extensions.
80 .SH BUGS
81 This manual page is incomplete.
82 .SH EXAMPLE
83 .\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
84
85 Creating a rtnetlink message to set the MTU of a device:
86 .nf
87 #include <linux/rtnetlink.h>
88
89 ...
90
91 struct {
92 struct nlmsghdr nh;
93 struct ifinfomsg if;
94 char attrbuf[512];
95 } req;
96
97 struct rtattr *rta;
98 unsigned int mtu = 1000;
99
100 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
101
102 memset(&req, 0, sizeof(req));
103 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
104 req.nh.nlmsg_flags = NLM_F_REQUEST;
105 req.nh.nlmsg_type = RTM_NEWLINK;
106 req.if.ifi_family = AF_UNSPEC;
107 req.if.ifi_index = INTERFACE_INDEX;
108 req.if.ifi_change = 0xffffffff; /* ???*/
109 rta = (struct rtattr *)(((char *) &req) +
110 NLMSG_ALIGN(req.nh.nlmsg_len));
111 rta\->rta_type = IFLA_MTU;
112 rta\->rta_len = sizeof(unsigned int);
113 req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
114 RTA_LENGTH(sizeof(mtu));
115 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
116 send(rtnetlink_sk, &req, req.nh.nlmsg_len);
117 .fi
118 .SH "SEE ALSO"
119 .BR netlink (3),
120 .BR netlink (7),
121 .BR rtnetlink (7)