]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/rtnetlink.3
dlopen.3: Note that symbol use might keep a dlclose'd object in memory
[thirdparty/man-pages.git] / man3 / rtnetlink.3
CommitLineData
77117f4f 1.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
2297bf0e 2.\"
00acdba1 3.\" %%%LICENSE_START(VERBATIM_ONE_PARA)
77117f4f
MK
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.
8ff7380d 8.\" %%%LICENSE_END
a5e73dd4 9.\"
77117f4f 10.\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
a5e73dd4 11.\"
62c76ace 12.TH RTNETLINK 3 2014-09-06 "GNU" "Linux Programmer's Manual"
77117f4f
MK
13.SH NAME
14rtnetlink \- macros to manipulate rtnetlink messages
15.SH SYNOPSIS
16.B #include <asm/types.h>
17.br
18.B #include <linux/netlink.h>
19.br
20.B #include <linux/rtnetlink.h>
21.br
22.B #include <sys/socket.h>
f90f031e 23.PP
d4c8c97c 24.BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
77117f4f 25", NETLINK_ROUTE);"
68e4db0a 26.PP
77117f4f 27.BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
68e4db0a 28.PP
77117f4f 29.BI "void *RTA_DATA(struct rtattr *" rta );
68e4db0a 30.PP
77117f4f 31.BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
68e4db0a 32.PP
77117f4f
MK
33.BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
34", unsigned int " rtabuflen );
68e4db0a 35.PP
77117f4f 36.BI "unsigned int RTA_LENGTH(unsigned int " length );
68e4db0a 37.PP
77117f4f
MK
38.BI "unsigned int RTA_SPACE(unsigned int "length );
39.SH DESCRIPTION
40All
41.BR rtnetlink (7)
42messages consist of a
43.BR netlink (7)
44message header and appended attributes.
33a0ccb2 45The attributes should be manipulated only using the macros provided here.
77117f4f
MK
46.PP
47.BI RTA_OK( rta ", " attrlen )
48returns true if
49.I rta
50points to a valid routing attribute;
51.I attrlen
52is the running length of the attribute buffer.
53When not true then you must assume there are no more attributes in the
54message, even if
55.I attrlen
c7094399 56is nonzero.
77117f4f
MK
57.PP
58.BI RTA_DATA( rta )
59returns a pointer to the start of this attribute's data.
60.PP
61.BI RTA_PAYLOAD( rta )
62returns the length of this attribute's data.
63.PP
64.BI RTA_NEXT( rta ", " attrlen )
65gets the next attribute after
66.IR rta .
67Calling this macro will update
68.IR attrlen .
69You should use
70.B RTA_OK
71to check the validity of the returned pointer.
72.PP
73.BI RTA_LENGTH( len )
74returns the length which is required for
75.I len
76bytes of data plus the header.
77.PP
78.BI RTA_SPACE( len )
79returns the amount of space which will be needed in a message with
80.I len
81bytes of data.
82.SH CONFORMING TO
c8f2dd47 83These macros are nonstandard Linux extensions.
77117f4f
MK
84.SH BUGS
85This manual page is incomplete.
86.SH EXAMPLE
bea08fec 87.\" FIXME . ? would be better to use libnetlink in the EXAMPLE code here
77117f4f 88Creating a rtnetlink message to set the MTU of a device:
207050fa
MK
89.PP
90.in +4n
91.EX
92#include <linux/rtnetlink.h>
509718c0 93
207050fa 94\&...
77117f4f 95
207050fa
MK
96struct {
97 struct nlmsghdr nh;
98 struct ifinfomsg if;
99 char attrbuf[512];
100} req;
77117f4f 101
207050fa
MK
102struct rtattr *rta;
103unsigned int mtu = 1000;
77117f4f 104
207050fa 105int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
77117f4f 106
207050fa
MK
107memset(&req, 0, sizeof(req));
108req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
109req.nh.nlmsg_flags = NLM_F_REQUEST;
110req.nh.nlmsg_type = RTM_NEWLINK;
111req.if.ifi_family = AF_UNSPEC;
112req.if.ifi_index = INTERFACE_INDEX;
113req.if.ifi_change = 0xffffffff; /* ??? */
114rta = (struct rtattr *)(((char *) &req) +
115 NLMSG_ALIGN(req.nh.nlmsg_len));
116rta\->rta_type = IFLA_MTU;
117rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
118req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
119 RTA_LENGTH(sizeof(mtu));
120memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
121send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);
b9c93deb 122.EE
207050fa 123.in
47297adb 124.SH SEE ALSO
77117f4f
MK
125.BR netlink (3),
126.BR netlink (7),
127.BR rtnetlink (7)