share/mk/: Remove unused variable
[man-pages.git] / man3 / rtnetlink.3
blob6be783eaf5438a019a816692e7b9a5e89c861fbf
1 .\" SPDX-License-Identifier: Linux-man-pages-1-para
2 .\"
3 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
4 .\"
5 .\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
6 .\"
7 .TH rtnetlink 3 (date) "Linux man-pages (unreleased)"
8 .SH NAME
9 rtnetlink \- macros to manipulate rtnetlink messages
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ", " \-lc )
13 .SH SYNOPSIS
14 .nf
15 .B #include <asm/types.h>
16 .B #include <linux/netlink.h>
17 .B #include <linux/rtnetlink.h>
18 .B #include <sys/socket.h>
20 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
21 ", NETLINK_ROUTE);"
23 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
25 .BI "void *RTA_DATA(struct rtattr *" rta );
26 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
28 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
29 ", unsigned int " rtabuflen );
31 .BI "unsigned int RTA_LENGTH(unsigned int " length );
32 .BI "unsigned int RTA_SPACE(unsigned int "length );
33 .fi
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 manipulated only using the macros provided here.
42 .BI RTA_OK( rta ", " attrlen )
43 returns true if
44 .I rta
45 points to a valid routing attribute;
46 .I attrlen
47 is the running length of the attribute buffer.
48 When not true then you must assume there are no more attributes in the
49 message, even if
50 .I attrlen
51 is nonzero.
53 .BI RTA_DATA( rta )
54 returns a pointer to the start of this attribute's data.
56 .BI RTA_PAYLOAD( rta )
57 returns the length of this attribute's data.
59 .BI RTA_NEXT( rta ", " attrlen )
60 gets the next attribute after
61 .IR rta .
62 Calling this macro will update
63 .IR attrlen .
64 You should use
65 .B RTA_OK
66 to check the validity of the returned pointer.
68 .BI RTA_LENGTH( len )
69 returns the length which is required for
70 .I len
71 bytes of data plus the header.
73 .BI RTA_SPACE( len )
74 returns the amount of space which will be needed in a message with
75 .I len
76 bytes of data.
77 .SH STANDARDS
78 Linux.
79 .SH BUGS
80 This manual page is incomplete.
81 .SH EXAMPLES
82 .\" FIXME . ? would be better to use libnetlink in the EXAMPLE code here
83 Creating a rtnetlink message to set the MTU of a device:
85 .in +4n
86 .EX
87 #include <linux/rtnetlink.h>
89 \&...
91 struct {
92     struct nlmsghdr  nh;
93     struct ifinfomsg if;
94     char             attrbuf[512];
95 } req;
97 struct rtattr *rta;
98 unsigned int mtu = 1000;
100 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
102 memset(&req, 0, sizeof(req));
103 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
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 = RTA_LENGTH(sizeof(mtu));
113 req.nh.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, 0);
119 .SH SEE ALSO
120 .BR netlink (3),
121 .BR netlink (7),
122 .BR rtnetlink (7)