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 rtnetlink \- rtnetlink メッセージを操作するマクロ
20 .B #include <asm/types.h>
22 .B #include <linux/netlink.h>
24 .B #include <linux/rtnetlink.h>
26 .B #include <sys/socket.h>
28 .BI "rtnetlink_socket = socket(AF_NETLINK, int " socket_type \
31 .BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
33 .BI "void *RTA_DATA(struct rtattr *" rta );
35 .BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
37 .BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
38 ", unsigned int " rtabuflen );
40 .BI "unsigned int RTA_LENGTH(unsigned int " length );
42 .BI "unsigned int RTA_SPACE(unsigned int "length );
49 属性の操作は、必ずここに挙げたマクロを通して行うべきである。
51 .BI RTA_OK( rta ", " attrlen )
54 が有効なルーティング属性へのポインタであれば真を返す。
56 は属性バッファの実働時の長さ (running length) である。
60 メッセージ中にはもうそれ以上属性は無いと考えなければならない。
65 .BI RTA_PAYLOAD( rta )
68 .BI RTA_NEXT( rta ", " attrlen )
76 を使って、返されたポインタが正しいかをチェックすべきである。
81 バイトのデータ + ヘッダに必要な長さを返す。
86 バイトのデータを持つメッセージに必要とされる容量を返す。
88 これらのマクロは非標準で、Linux での拡張である。
92 .\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
93 デバイスの MTU をセットする rtnetlink メッセージを生成する
95 #include <linux/rtnetlink.h>
106 unsigned int mtu = 1000;
108 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
110 memset(&req, 0, sizeof(req));
111 req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
112 req.nh.nlmsg_flags = NLM_F_REQUEST;
113 req.nh.nlmsg_type = RTM_NEWLINK;
114 req.if.ifi_family = AF_UNSPEC;
115 req.if.ifi_index = INTERFACE_INDEX;
116 req.if.ifi_change = 0xffffffff; /* ??? */
117 rta = (struct rtattr *)(((char *) &req) +
118 NLMSG_ALIGN(req.nh.nlmsg_len));
119 rta\->rta_type = IFLA_MTU;
120 rta\->rta_len = sizeof(unsigned int);
121 req.n.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
122 RTA_LENGTH(sizeof(mtu));
123 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
124 send(rtnetlink_sk, &req, req.nh.nlmsg_len);