]> git.ipfire.org Git - thirdparty/man-pages.git/blobdiff - man3/rtnetlink.3
All pages: Replace the 4th argument to .TH by "Linux man-pages (unreleased)"
[thirdparty/man-pages.git] / man3 / rtnetlink.3
index 9a6a2ec5ef864d7a04fb37d41c3610c09f64bbc8..3ad1b72003d1543519fbe921e61a1a332fc0a5b3 100644 (file)
@@ -1,61 +1,66 @@
 .\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
+.\"
+.\" %%%LICENSE_START(VERBATIM_ONE_PARA)
 .\" Permission is granted to distribute possibly modified copies
 .\" of this page provided the header is included verbatim,
 .\" and in case of nontrivial modification author and date
 .\" of the modification is added to the header.
+.\" %%%LICENSE_END
+.\"
 .\" $Id: rtnetlink.3,v 1.2 1999/05/18 10:35:10 freitag Exp $
-.TH RTNETLINK 3 1999-05-14 "Linux Man Page" "Linux Programmer's Manual"
+.\"
+.TH RTNETLINK 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
 .SH NAME
-rtnetlink \- Macros to manipuate rtnetlink messages
+rtnetlink \- macros to manipulate rtnetlink messages
+.SH LIBRARY
+Standard C library
+.RI ( libc ", " \-lc )
 .SH SYNOPSIS
+.nf
 .B #include <asm/types.h>
-.br
 .B #include <linux/netlink.h>
-.br
 .B #include <linux/rtnetlink.h>
-.br
 .B #include <sys/socket.h>
-
-.BI "rtnetlink_socket = socket(PF_NETLINK, int " socket_type ", NETLINK_ROUTE);"
-.br
-.B int RTA_OK(struct rtattr *rta, int rtabuflen); 
-.br
-.B void *RTA_DATA(struct rtattr *rta); 
-.br
-.B unsigned int RTA_PAYLOAD(struct rtattr *rta); 
-.br
-.B struct rtattr *RTA_NEXT(struct rtattr *rta, unsigned int rtabuflen); 
-.br
-.B unsigned int RTA_LENGTH(unsigned int length); 
-.br
-.B unsigned int RTA_SPACE(unsigned int length); 
-.br
+.PP
+.BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
+", NETLINK_ROUTE);"
+.PP
+.BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
+.PP
+.BI "void *RTA_DATA(struct rtattr *" rta );
+.BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
+.PP
+.BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
+", unsigned int " rtabuflen );
+.PP
+.BI "unsigned int RTA_LENGTH(unsigned int " length );
+.BI "unsigned int RTA_SPACE(unsigned int "length );
+.fi
 .SH DESCRIPTION
-All 
+All
 .BR rtnetlink (7)
-messages consist of a 
+messages consist of a
 .BR netlink (7)
-message header and appended attributes. The attributes should be only
-manipulated using the macros provided here.
-
+message header and appended attributes.
+The attributes should be manipulated only using the macros provided here.
 .PP
 .BI RTA_OK( rta ", " attrlen )
 returns true if
 .I rta
 points to a valid routing attribute;
 .I attrlen
-is the  running length of the attribute buffer.
+is the running length of the attribute buffer.
 When not true then you must assume there are no more attributes in the
 message, even if
 .I attrlen
-is non-zero.
-.br
+is nonzero.
+.PP
 .BI RTA_DATA( rta )
 returns a pointer to the start of this attribute's data.
-.br
+.PP
 .BI RTA_PAYLOAD( rta )
 returns the length of this attribute's data.
-.br
+.PP
 .BI RTA_NEXT( rta ", " attrlen )
 gets the next attribute after
 .IR rta .
@@ -63,53 +68,60 @@ Calling this macro will update
 .IR attrlen .
 You should use
 .B RTA_OK
-to check for the validity of the returned pointer.
-.br
+to check the validity of the returned pointer.
+.PP
 .BI RTA_LENGTH( len )
 returns the length which is required for
 .I len
 bytes of data plus the header.
-.br
+.PP
 .BI RTA_SPACE( len )
-returns the amount of space which will be needed in the message with
+returns the amount of space which will be needed in a message with
 .I len
 bytes of data.
+.SH STANDARDS
+These macros are nonstandard Linux extensions.
+.SH BUGS
+This manual page is incomplete.
+.SH EXAMPLES
+.\" FIXME . ? would be better to use libnetlink in the EXAMPLE code here
+Creating a rtnetlink message to set the MTU of a device:
+.PP
+.in +4n
+.EX
+#include <linux/rtnetlink.h>
 
-.SH EXAMPLE
-.\" FIXME would be better to use libnetlink n the EXAMPLE code here
+\&...
 
-Creating a rtnetlink message to set a MTU of a device.
-.nf
-       struct {
-              struct nlmsghdr nh;
-              struct ifinfomsg   if;
-              char            attrbuf[512];
-       } req;
-       struct rtattr *rta;
-       unsigned int mtu = 1000; 
-       int rtnetlink_sk = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); 
+struct {
+    struct nlmsghdr  nh;
+    struct ifinfomsg if;
+    char             attrbuf[512];
+} req;
 
-       memset(&req, 0, sizeof(req));
-       req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)); 
-       req.nh.nlmsg_flags = NLM_F_REQUEST; 
-       req.nh.nlmsg_type = RTML_NEWLINK;
-       req.if.ifi_family = AF_UNSPEC;
-       req.if.ifi_index = INTERFACE_INDEX; 
-       req.if.ifi_change = 0xffffffff; /* ???*/
-       rta = (struct rtattr *)(((char *) &req) + 
-                       NLMSG_ALIGN(n->nlmsg_len));
-       rta->rta_type = IFLA_MTU;
-       rta->rta_len = sizeof(unsigned int);
-       req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + 
-                       RTA_LENGTH(sizeof(mtu)); 
-       memcpy(RTA_DATA(rta), &mtu, sizeof (mtu));
-       send(rtnetlink_sk, &req, req.n.nlmsg_len); 
-.fi
+struct rtattr *rta;
+unsigned int mtu = 1000;
 
-.SH BUGS
-This manual page is lacking and incomplete.
+int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
 
-.SH "SEE ALSO"
+memset(&req, 0, sizeof(req));
+req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
+req.nh.nlmsg_flags = NLM_F_REQUEST;
+req.nh.nlmsg_type = RTM_NEWLINK;
+req.if.ifi_family = AF_UNSPEC;
+req.if.ifi_index = INTERFACE_INDEX;
+req.if.ifi_change = 0xffffffff; /* ??? */
+rta = (struct rtattr *)(((char *) &req) +
+                         NLMSG_ALIGN(req.nh.nlmsg_len));
+rta\->rta_type = IFLA_MTU;
+rta\->rta_len = RTA_LENGTH(sizeof(mtu));
+req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
+                              RTA_LENGTH(sizeof(mtu));
+memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
+send(rtnetlink_sk, &req, req.nh.nlmsg_len, 0);
+.EE
+.in
+.SH SEE ALSO
 .BR netlink (3),
 .BR netlink (7),
 .BR rtnetlink (7)