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: cmsg.3,v 1.3 2001/01/14 05:30:39 hanataka Exp $
8 .\" Japanese Version Copyright (c) 1999 Shouichi Saito
9 .\" all rights reserved.
10 .\" Translated Mon Jul 26 21:58:26 JST 1999
11 .\" by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
12 .\" Proofed Tue Aug 17 1999 by NAKANO Takeo <nakano@apm.seikei.ac.jp>
14 .TH CMSG 3 2008-11-20 "Linux" "Linux Programmer's Manual"
16 .\"O CMSG_ALIGN, CMSG_SPACE, CMSG_NXTHDR, CMSG_FIRSTHDR \- Access ancillary data
17 CMSG_ALIGN, CMSG_SPACE, CMSG_NXTHDR, CMSG_FIRSTHDR \- 補助データにアクセスする。
19 .B #include <sys/socket.h>
21 .BI "struct cmsghdr *CMSG_FIRSTHDR(struct msghdr *" msgh );
23 .BI "struct cmsghdr *CMSG_NXTHDR(struct msghdr *" msgh ", struct cmsghdr *" cmsg );
25 .BI "size_t CMSG_ALIGN(size_t " length );
27 .BI "size_t CMSG_SPACE(size_t " length );
29 .BI "size_t CMSG_LEN(size_t " length );
31 .BI "unsigned char *CMSG_DATA(struct cmsghdr *" cmsg );
35 socklen_t cmsg_len; /* data byte count, including header */
36 int cmsg_level; /* originating protocol */
37 int cmsg_type; /* protocol-specific type */
38 /* followed by unsigned char cmsg_data[]; */
42 .\"O These macros are used to create and access control messages (also called
43 .\"O ancillary data) that are not a part of the socket payload.
45 (補助データ (ancillary data) とも呼ばれる) を作り、
47 制御メッセージはソケットにのるデータではない。
48 .\"O This control information may
49 .\"O include the interface the packet was received on, various rarely used header
50 .\"O fields, an extended error description, a set of file descriptors or UNIX
52 .\"O For instance, control messages can be used to send
53 .\"O additional header fields such as IP options.
54 この制御情報は、到着したパケットへのインターフェイス、様々なあまり
55 使われないヘッダーフィールド、エラー記述の拡張、ファイルデスクリ
56 プタの集合や、UNIXにおける信頼情報 (credential) を含んでいる。
57 制御メッセージは、例えば IP オプションのような追加ヘッダーフィールドを
59 .\"O Ancillary data is sent by calling
61 .\"O and received by calling
63 .\"O See their manual pages for more information.
71 .\"O Ancillary data is a sequence of
72 .\"O .I struct cmsghdr
73 .\"O structures with appended data.
74 .\"O This sequence should only be accessed
75 .\"O using the macros described in this manual page and never directly.
78 構造体のシーケンスに追加データが付加されたものである。
79 このシーケンスにはこのマニュアルページに書かれている
80 マクロを使ってアクセスすべきで、直接アクセスすべきではない。
81 .\"O See the specific protocol man pages for the available control message types.
82 使用可能な制御メッセージのタイプについては、
83 それぞれのプロトコルのマニュアルページを参照のこと。
84 .\"O The maximum ancillary buffer size allowed per socket can be set using
85 .\"O .IR /proc/sys/net/core/optmem_max ;
89 .I /proc/sys/net/core/optmem_max
94 .\"O .BR CMSG_FIRSTHDR ()
95 .\"O returns a pointer to the first
98 .\"O data buffer associated with the passed
107 .\"O .BR CMSG_NXTHDR ()
108 .\"O returns the next valid
110 .\"O after the passed
118 .\"O It returns NULL when there isn't enough space left in the buffer.
119 バッファに十分な空きが無い場合、NULL を返す。
121 .\"O .BR CMSG_ALIGN (),
122 .\"O given a length, returns it including the required alignment.
124 .\"O constant expression.
126 に長さを与えると、必要なアラインメントを加味した長さを返してくる。
129 .\"O .BR CMSG_SPACE ()
130 .\"O returns the number of bytes an ancillary element with payload of the
131 .\"O passed data length occupies.
132 .\"O This is a constant expression.
134 は、与えたデータ長が占めるのに必要な補助要素 (ancillary element) の
137 .\"O .BR CMSG_DATA ()
138 .\"O returns a pointer to the data portion of a
146 .\"O returns the value to store in the
150 .\"O structure, taking into account any necessary
152 .\"O It takes the data length as an argument.
153 .\"O This is a constant
160 メンバにデータを格納する際に必要な値を返す。アラインメントも考慮に入れ
162 引数としてデータ長をとる。これは定数式である。
164 .\"O To create ancillary data, first initialize the
165 .\"O .I msg_controllen
168 .\"O with the length of the control message buffer.
170 .\"O .BR CMSG_FIRSTHDR ()
173 .\"O to get the first control message and
174 .\"O .BR CMSG_NXTHDR ()
175 .\"O to get all subsequent ones.
180 を、制御メッセージバッファの長さで初期化する。
187 .\"O In each control message, initialize
190 .\"O .BR CMSG_LEN ()),
193 .\"O header fields, and the data portion using
194 .\"O .BR CMSG_DATA ().
202 ヘッダーフィールド、そしてデータ部分に対しても
206 .\"O .I msg_controllen
209 .\"O should be set to the sum of the
210 .\"O .BR CMSG_SPACE ()
211 .\"O of the length of
212 .\"O all control messages in the buffer.
213 .\"O For more information on the
216 .\"O .BR recvmsg (2).
221 フィールドに、バッファ中の制御メッセージの長さの
229 .\"O When the control message buffer is too short to store all messages, the
231 .\"O flag is set in the
235 制御メッセージバッファが全てのメッセージを納めるのには短すぎる場合、
242 .\"O .SH "CONFORMING TO"
244 .\"O This ancillary data model conforms to the POSIX.1g draft, 4.4BSD-Lite,
245 .\"O the IPv6 advanced API described in RFC\ 2292 and the SUSv2.
246 .\"O .BR CMSG_ALIGN ()
247 .\"O is a Linux extension.
248 この補助データモデルは、POSIX.1g draft, 4.4BSD-Lite, RFC\ 2292 に
249 記述されている IPv6 advanced API, そして SUSv2
254 .\"O For portability, ancillary data should be accessed only using the macros
256 移植性のために、補助データへのアクセスには、
257 ここで述べられているマクロを使うだけにすべきである。
259 .\"O is a Linux extension and should be not used in portable programs.
260 は Linux での拡張であり、移植性を考えたプログラムでは使うべきではない。
263 .\"O .BR CMSG_LEN (),
264 .\"O .BR CMSG_DATA (),
266 .\"O .BR CMSG_ALIGN ()
267 .\"O are constant expressions (assuming their argument is constant);
268 .\"O this could be used to declare the size of global
270 .\"O This may be not portable, however.
275 は定数式である (それらの引数が定数とみなされる)。
276 このことは、大域変数のサイズを宣言するのに使える。
279 .\"O This code looks for the
281 .\"O option in a received ancillary buffer:
289 struct cmsghdr *cmsg;
293 /* Receive auxiliary data in msgh */
294 for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
295 cmsg = CMSG_NXTHDR(&msgh,cmsg)) {
296 if (cmsg\->cmsg_level == IPPROTO_IP
297 && cmsg\->cmsg_type == IP_TTL) {
298 ttlptr = (int *) CMSG_DATA(cmsg);
299 received_ttl = *ttlptr;
305 * Error: IP_TTL not enabled or small buffer
312 .\"O The code below passes an array of file descriptors over a
313 .\"O UNIX domain socket using
314 .\"O .BR SCM_RIGHTS :
318 UNIX ドメインソケットを通して送るものである。
322 struct msghdr msg = {0};
323 struct cmsghdr *cmsg;
324 int myfds[NUM_FD]; /* Contains the file descriptors to pass. */
325 char buf[CMSG_SPACE(sizeof myfds)]; /* ancillary data buffer */
328 msg.msg_control = buf;
329 msg.msg_controllen = sizeof buf;
330 cmsg = CMSG_FIRSTHDR(&msg);
331 cmsg\->cmsg_level = SOL_SOCKET;
332 cmsg\->cmsg_type = SCM_RIGHTS;
333 cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
334 /* Initialize the payload: */
335 fdptr = (int *) CMSG_DATA(cmsg);
336 memcpy(fdptr, myfds, NUM_FD * sizeof(int));
337 /* Sum of the length of all control messages in the buffer: */
338 msg.msg_controllen = cmsg\->cmsg_len;