File: rtnetlink.3

package info (click to toggle)
manpages-ja 0.5.0.0.20100315-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 21,156 kB
  • ctags: 1
  • sloc: sh: 13,935; perl: 157; makefile: 114
file content (126 lines) | stat: -rw-r--r-- 3,520 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
.\" This man page is Copyright (C) 1999 Andi Kleen <ak@muc.de>.
.\" 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.
.\" $Id: rtnetlink.3,v 1.3 1999/08/20 04:10:17 nakano Exp $
.\"
.\" Japanese Version Copyright (c) 1999 Shouichi Saito
.\"	all rights reserved.
.\" Translated Mon Jul 26 12:18:39 JST 1999
.\"	by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
.\" Proofed Fri Aug 20 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
.\"
.\"WORD:	running length	ưĹ
.\"
.TH RTNETLINK 3 2008-08-08 "GNU" "Linux Programmer's Manual"
.SH ̾
rtnetlink \- rtnetlink åޥ
.SH 
.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(AF_NETLINK, int " socket_type \
", NETLINK_ROUTE);"
.sp
.BI "int RTA_OK(struct rtattr *" rta ", int " rtabuflen );
.sp
.BI "void *RTA_DATA(struct rtattr *" rta );
.sp
.BI "unsigned int RTA_PAYLOAD(struct rtattr *" rta );
.sp
.BI "struct rtattr *RTA_NEXT(struct rtattr *" rta \
", unsigned int " rtabuflen );
.sp
.BI "unsigned int RTA_LENGTH(unsigned int " length );
.sp
.BI "unsigned int RTA_SPACE(unsigned int "length );
.SH 
Ƥ
.BR rtnetlink (7)
å
.BR netlink (7)
åإåɲ°ʤ롣
°ϡɬ˵󤲤ޥ̤ƹԤ٤Ǥ롣
.PP
.BI RTA_OK( rta ", " attrlen )

.I rta
ͭʥ롼ƥ°ؤΥݥ󥿤Ǥп֤
.I attrlen
°ХåեμƯĹ (running length) Ǥ롣
ǤʤС㤨
.I attrlen
ǤʤƤ⡢
åˤϤ⤦ʾ°̵ȹͤʤФʤʤ
.PP
.BI RTA_DATA( rta )
Ϥ°ǡƬؤΥݥ󥿤֤
.PP
.BI RTA_PAYLOAD( rta )
Ϥ°ǡĹ֤
.PP
.BI RTA_NEXT( rta ", " attrlen )

.I rta
μˤ°롣
ΥޥƤ֤
.I attrlen
.B RTA_OK
Ȥäơ֤줿ݥ󥿤å٤Ǥ롣
.PP
.BI RTA_LENGTH( len )

.I len
ХȤΥǡ + إåɬפĹ֤
.PP
.BI RTA_SPACE( len )

.I len
ХȤΥǡĥåɬפȤ̤֤
.SH 
ΥޥɸǡLinux ǤγĥǤ롣
.SH Х
Υޥ˥奢ϴǤϤʤ
.SH 
.\" FIXME ? would be better to use libnetlink in the EXAMPLE code here
ǥХ MTU 򥻥åȤ rtnetlink å
.nf

    struct {
        struct nlmsghdr  nh;
        struct ifinfomsg if;
        char             attrbuf[512];
    } req;

    struct rtattr *rta;
    unsigned int mtu = 1000;

    int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);

    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
.SH Ϣ
.BR netlink (3),
.BR netlink (7),
.BR rtnetlink (7)