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.3 1999/08/20 04:10:17 nakano Exp $
8 .\" Japanese Version Copyright (c) 1999 Shouichi Saito
9 .\" all rights reserved.
10 .\" Translated Mon Jul 26 12:18:39 JST 1999
11 .\" by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
12 .\" Proofed Fri Aug 20 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
14 .\"WORD: running length ¼ÂÆ°»þ¤ÎŤµ
16 .TH RTNETLINK 3 2010-01-11 "GNU" "Linux Programmer's Manual"
18 .\"O rtnetlink \- macros to manipulate rtnetlink messages
19 rtnetlink \- rtnetlink ¥á¥Ã¥»¡¼¥¸¤òÁàºî¤¹¤ë¥Þ¥¯¥í
22 .B #include <asm/types.h>
24 .B #include <linux/netlink.h>
26 .B #include <linux/rtnetlink.h>
28 .B #include <sys/socket.h>
30 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
33 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
35 .BI "void *RTA_DATA(struct rtattr *" rta );
37 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
39 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
40 ", unsigned int " rtabuflen );
42 .BI "unsigned int RTA_LENGTH(unsigned int " length );
44 .BI "unsigned int RTA_SPACE(unsigned int "length );
47 .\"O .BR rtnetlink (7)
48 .\"O messages consist of a
50 .\"O message header and appended attributes.
51 .\"O The attributes should be only
52 .\"O manipulated using the macros provided here.
57 ¥á¥Ã¥»¡¼¥¸¥Ø¥Ã¥À¤ÈÄɲðÀ¤«¤é¤Ê¤ë¡£
58 °À¤ÎÁàºî¤Ï¡¢É¬¤º¤³¤³¤Ëµó¤²¤¿¥Þ¥¯¥í¤òÄ̤·¤Æ¹Ô¤¦¤Ù¤¤Ç¤¢¤ë¡£
60 .\"O .BI RTA_OK( rta ", " attrlen )
63 .\"O points to a valid routing attribute;
65 .\"O is the running length of the attribute buffer.
66 .BI RTA_OK( rta ", " attrlen )
69 ¤¬Í¸ú¤Ê¥ë¡¼¥Æ¥£¥ó¥°Â°À¤Ø¤Î¥Ý¥¤¥ó¥¿¤Ç¤¢¤ì¤Ð¿¿¤òÊÖ¤¹¡£
71 ¤Ï°À¥Ð¥Ã¥Õ¥¡¤Î¼ÂƯ»þ¤ÎŤµ (running length) ¤Ç¤¢¤ë¡£
72 .\"O When not true then you must assume there are no more attributes in the
79 ¥á¥Ã¥»¡¼¥¸Ãæ¤Ë¤Ï¤â¤¦¤½¤ì°Ê¾å°À¤Ï̵¤¤¤È¹Í¤¨¤Ê¤±¤ì¤Ð¤Ê¤é¤Ê¤¤¡£
81 .\"O .BI RTA_DATA( rta )
82 .\"O returns a pointer to the start of this attribute's data.
84 ¤Ï¤³¤Î°À¥Ç¡¼¥¿¤ÎÀèƬ¤Ø¤Î¥Ý¥¤¥ó¥¿¤òÊÖ¤¹¡£
86 .\"O .BI RTA_PAYLOAD( rta )
87 .\"O returns the length of this attribute's data.
88 .BI RTA_PAYLOAD( rta )
89 ¤Ï¤³¤Î°À¥Ç¡¼¥¿¤ÎŤµ¤òÊÖ¤¹¡£
91 .\"O .BI RTA_NEXT( rta ", " attrlen )
92 .\"O gets the next attribute after
94 .BI RTA_NEXT( rta ", " attrlen )
97 ¤Î¼¡¤Ë¤¢¤ë°À¤ò¼èÆÀ¤¹¤ë¡£
98 .\"O Calling this macro will update
102 .\"O to check the validity of the returned pointer.
107 ¤ò»È¤Ã¤Æ¡¢ÊÖ¤µ¤ì¤¿¥Ý¥¤¥ó¥¿¤¬Àµ¤·¤¤¤«¤ò¥Á¥§¥Ã¥¯¤¹¤Ù¤¤Ç¤¢¤ë¡£
109 .\"O .BI RTA_LENGTH( len )
110 .\"O returns the length which is required for
112 .\"O bytes of data plus the header.
113 .BI RTA_LENGTH( len )
116 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿ + ¥Ø¥Ã¥À¤ËɬÍפÊŤµ¤òÊÖ¤¹¡£
118 .\"O .BI RTA_SPACE( len )
119 .\"O returns the amount of space which will be needed in a message with
125 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿¤ò»ý¤Ä¥á¥Ã¥»¡¼¥¸¤ËɬÍפȤµ¤ì¤ëÍÆÎ̤òÊÖ¤¹¡£
126 .\"O .SH CONFORMING TO
128 .\"O These macros are nonstandard Linux extensions.
129 ¤³¤ì¤é¤Î¥Þ¥¯¥í¤ÏÈóɸ½à¤Ç¡¢Linux ¤Ç¤Î³ÈÄ¥¤Ç¤¢¤ë¡£
131 .\"O This manual page is incomplete.
132 ¤³¤Î¥Þ¥Ë¥å¥¢¥ë¤Ï´°Á´¤Ç¤Ï¤Ê¤¤¡£
134 .\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
136 .\"O Creating a rtnetlink message to set the MTU of a device.
137 ¥Ç¥Ð¥¤¥¹¤Î MTU ¤ò¥»¥Ã¥È¤¹¤ë rtnetlink ¥á¥Ã¥»¡¼¥¸¤òÀ¸À®¤¹¤ë
139 #include <linux/rtnetlink.h>
150 unsigned int mtu = 1000;
152 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
154 memset(&req, 0, sizeof(req));
155 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
156 req.nh.nlmsg_flags = NLM_F_REQUEST;
157 req.nh.nlmsg_type = RTM_NEWLINK;
158 req.if.ifi_family = AF_UNSPEC;
159 req.if.ifi_index = INTERFACE_INDEX;
160 req.if.ifi_change = 0xffffffff; /* ???*/
161 rta = (struct rtattr *)(((char *) &req) +
162 NLMSG_ALIGN(req.nh.nlmsg_len));
163 rta\->rta_type = IFLA_MTU;
164 rta\->rta_len = sizeof(unsigned int);
165 req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
166 RTA_LENGTH(sizeof(mtu));
167 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
168 send(rtnetlink_sk, &req, req.nh.nlmsg_len);