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.
7 .\" Modified, 2003-12-02, Michael Kerrisk, <mtk.manpages@gmail.com>
8 .\" Modified, 2003-09-23, Adam Langley
9 .\" Modified, 2004-05-27, Michael Kerrisk, <mtk.manpages@gmail.com>
10 .\" Added SOCK_SEQPACKET
11 .\" 2008-05-27, mtk, Provide a clear description of the three types of
12 .\" address that can appear in the sockaddr_un structure: pathname,
13 .\" unnamed, and abstract.
15 .\" Japanese Version Copyright (c) 1999 Shouichi Saito and
16 .\" NAKANO Takeo all rights reserved.
17 .\" Translated 1999-12-06, NAKANO Takeo <nakano@apm.seikei.ac.jp>
18 .\" based on the work by Shouichi Saito <ss236rx@ymg.urban.ne.jp>
19 .\" Updated 2003-01-07, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
20 .\" Updated 2005-02-21, Akihiro MOTOKI
21 .\" Updated 2005-12-26, Akihiro MOTOKI
22 .\" Updated 2008-08-08, Akihiro MOTOKI, LDP v3.05
24 .\"WORD abstract namespace 抽象名前空間
25 .\"WORD anonymous socket 名前無しソケット
26 .\"WORD credential 信任状
27 .\"WORD ancillary message 補助メッセージ
28 .\"WORD file descriptor ファイルディスクリプタ
30 .\" 訳注: 訳す際も Unix は capitalize しておくこと。
31 .\" LDP_man-pages 1.66→2.01 において unix → Unix の変更があり、
34 .TH UNIX 7 2008-12-01 "Linux" "Linux Programmer's Manual"
37 .\"O unix, AF_UNIX, AF_LOCAL \- Sockets for local
38 .\"O interprocess communication
39 unix, AF_UNIX, AF_LOCAL \- ローカルな
43 .B #include <sys/socket.h>
45 .B #include <sys/un.h>
47 .IB unix_socket " = socket(AF_UNIX, type, 0);"
49 .IB error " = socketpair(AF_UNIX, type, 0, int *" sv ");"
56 .\"O socket family is used to communicate between processes on the same machine
58 .\"O Traditionally, Unix sockets can be either unnamed,
59 .\"O or bound to a file system pathname (marked as being of type socket).
62 とも言われる) ソケットファミリーは、同じマシン上でプロセス同士が
64 伝統的に、Unix ソケットは、名前なしにもできるし、
65 (ソケット型であると印のついた) ファイルシステムのパス名に
67 .\"O Linux also supports an abstract namespace which is independent of the
69 さらに Linux では、ファイルシステムに依存しない
70 抽象名前空間 (abstract namespace) もサポートしている。
73 .\"O .BR SOCK_STREAM ,
74 .\"O for a stream-oriented socket and
76 .\"O for a datagram-oriented socket that preserves message boundaries
77 .\"O (as on most Unix implementations, Unix domain datagram
78 .\"O sockets are always reliable and don't reorder datagrams);
79 .\"O and (since Linux 2.6.4)
80 .\"O .BR SOCK_SEQPACKET ,
81 .\"O for a connection-oriented socket that preserves message boundaries
82 .\"O and delivers messages in the order that they were sent.
83 .\" MOTOKI: 見やすいように .TP 形式に変更
90 メッセージ境界を保存するデータグラム指向のソケット
91 (ほとんどの Unix の実装では、Unix ドメイン・データグラム・ソケットは
92 常に信頼でき、データグラムの並び替えは行わない)
95 (Linux 2.6.4 以降で利用できる)
96 メッセージ境界を保存し、送信された順序でメッセージを届ける接続指向ソケット
98 .\"O Unix sockets support passing file descriptors or process credentials
99 .\"O to other processes using ancillary data.
100 Unix ソケットでは、補助データを使って
101 ファイルディスクリプタやプロセスの信任状 (credential) を
103 .\"O .SS Address Format
105 .\"O A Unix domain socket address is represented in the following structure:
106 Unix ドメインソケットのアドレスは以下の構造体で表現される。
110 #define UNIX_PATH_MAX 108
113 sa_family_t sun_family; /* AF_UNIX */
114 char sun_path[UNIX_PATH_MAX]; /* pathname */
127 .\"O Three types of address are distinguished in this structure:
128 この構造体では 3 種類のアドレスが区別される。
131 .\"O a Unix domain socket can be bound to a null-terminated file
132 .\"O system pathname using
134 .\"O When the address of the socket is returned by
135 .\"O .BR getsockname (2),
136 .\"O .BR getpeername (2),
140 .\"O .IR "sizeof(sa_family_t) + strlen(sun_path) + 1" ,
143 .\"O contains the null-terminated pathname.
144 .IR "pathname (パス名)" :
146 を使って、Unix ドメインソケットを NULL 終端されたファイルシステム上の
153 .I "sizeof(sa_family_t) + strlen(sun_path) + 1"
156 に NULL 終端されたパス名が格納される。
159 .\"O A stream socket that has not been bound to a pathname using
162 .\"O Likewise, the two sockets created by
163 .\"O .BR socketpair (2)
165 .\"O When the address of an unnamed socket is returned by
166 .\"O .BR getsockname (2),
167 .\"O .BR getpeername (2),
171 .\"O .IR "sizeof(sa_family_t)" ,
174 .\"O should not be inspected.
175 .\"O .\" There is quite some variation across implementations: FreeBSD
176 .\"O .\" says the length is 16 bytes, HP-UX 11 says it's zero bytes.
177 .IR "unnamed (名前なし)" :
179 を使ってパス名に結び付けることができないストリーム型のソケットは
182 で作成される 2 つのソケットも名前を持たない。
186 が名前なしのソケットのアドレスを返す際には、
188 .I "sizeof(sa_family_t)"
192 .\" 実装ごとにかなりの違いが存在する。
193 .\" FreeBSD では長さは 16 バイトとなり、HP-UX では長さは 0 バイトとなる。
196 .\"O an abstract socket address is distinguished by the fact that
198 .\"O is a null byte ('\\0').
199 .\"O All of the remaining bytes in
201 .\"O define the "name" of the socket.
202 .\"O (Null bytes in the name have no special significance.)
203 .\"O The name has no connection with file system pathnames.
204 .IR "abstract (抽象)" :
207 がヌルバイト ('\\0') であることから区別できる。
209 の残りの全バイトによりソケットの「名前」が定義される
210 (名前中のヌルバイトには特別な意味はない)。
211 この名前はファイルシステムのパス名とは何の関係もない。
212 .\"O The socket's address in this namespace is given by the rest of the
215 .\"O When the address of an abstract socket is returned by
216 .\"O .BR getsockname (2),
217 .\"O .BR getpeername (2),
221 .\"O .IR "sizeof(struct sockaddr_un)" ,
224 .\"O contains the abstract name.
225 .\"O The abstract socket namespace is a nonportable Linux extension.
226 この名前空間におけるソケットのアドレスは、
232 が抽象ソケットのアドレスを返す際には、その長さは
233 .I "sizeof(struct sockaddr_un)"
237 ソケットの抽象名前空間は Linux による拡張であり、移植性はない。
238 .\"O .SS Socket Options
240 .\"O For historical reasons these socket options are specified with a
242 .\"O type even though they are
245 .\"O They can be set with
246 .\"O .BR setsockopt (2)
248 .\"O .BR getsockopt (2)
251 .\"O as the socket family.
265 .\" NAKANO added this TP
268 .\"O Enables the receiving of the credentials of the sending process
269 .\"O ancillary message.
270 .\"O When this option is set and the socket is not yet connected
271 .\"O a unique name in the abstract namespace will be generated automatically.
272 .\"O Expects an integer boolean flag.
273 送信プロセスの補助メッセージとして信任状を受信できるようにする。
274 このオプションがセットされていて、まだソケットが接続されていないと、
275 抽象名前空間に他と重ならない名前が自動的に生成される。
279 .\"O The following paragraphs describe domain-specific details and
280 .\"O unsupported features of the sockets API for Unix domain sockets on Linux.
281 この節では、Linux の Unix ドメイン・ソケットでの、
282 ドメイン固有の詳細仕様とソケット API でサポートされていない機能に
285 .\"O Unix domain sockets do not support the transmission of
286 .\"O out-of-band data (the
292 Unix ドメイン・ソケットでは、帯域外データ (out-of-band data) の
304 .\"O flag is not supported by Unix domain sockets.
307 フラグは Unix ドメイン・ソケットではサポートされていない。
315 .\"O is not supported by Unix domain sockets.
321 の使用は Unix ドメイン・ソケットではサポートされていない。
325 .\"O socket option does have an effect for Unix domain sockets, but the
327 .\"O option does not.
328 .\"O For datagram sockets, the
330 .\"O value imposes an upper limit on the size of outgoing datagrams.
331 .\"O This limit is calculated as the doubled (see
333 .\"O option value less 32 bytes used for overhead.
335 ソケットオプションは Unix ドメイン・ソケットで効果を持つが、
340 の値が出力データグラムの上限サイズとなる。
345 参照) からオーバヘッドとして使用される 32 バイトを引いた値となる。
346 .\"O .SS Ancillary Messages
348 .\"O Ancillary data is sent and received using
351 .\"O .BR recvmsg (2).
357 .\"O For historical reasons the ancillary message types listed below
358 .\"O are specified with a
360 .\"O type even though they are
363 歴史的な理由により、以下に示す補助メッセージの型は
369 .\"O To send them set the
371 .\"O field of the struct
377 .\"O field to the type.
378 .\"O For more information see
394 .\"O Send or receive a set of open file descriptors from another process.
395 .\"O The data portion contains an integer array of the file descriptors.
396 .\"O The passed file descriptors behave as though they have been created with
398 他のプロセスでオープンされたファイルディスクリプタのセットを送受信する。
399 データ部分にファイルディスクリプタの整数配列が入っている。
400 渡されたファイルディスクリプタは、あたかも
405 .\"O Send or receive Unix credentials.
406 .\"O This can be used for authentication.
407 .\"O The credentials are passed as a
409 .\"O ancillary message.
410 .\"O Thus structure is defined in
411 .\"O .I <sys/socket.h>
413 Unix 信任状を送受信する。これは認証に用いることができる。
424 pid_t pid; /* process ID of the sending process */
425 uid_t uid; /* user ID of the sending process */
426 gid_t gid; /* group ID of the sending process */
431 .\"O Since glibc 2.8, the
433 .\"O feature test macro must be defined in order to obtain the definition
434 .\"O of this structure.
435 glibc 2.8 以降では、この構造体の定義を得るためには機能検査マクロ
439 .\"O The credentials which the sender specifies are checked by the kernel.
440 .\"O A process with effective user ID 0 is allowed to specify values that do
441 .\"O not match its own.
442 送信側が指定した信任状は、カーネルがチェックする。
443 実効ユーザー ID が 0 のプロセスには、
445 .\"O The sender must specify its own process ID (unless it has the capability
446 .\"O .BR CAP_SYS_ADMIN ),
447 .\"O its user ID, effective user ID, or saved set-user-ID (unless it has
448 .\"O .BR CAP_SETUID ),
449 .\"O and its group ID, effective group ID, or saved set-group-ID
451 .\"O .BR CAP_SETGID ).
452 送信側は以下の 3 つを指定しなければならない。
456 2) 自分自身のユーザー ID あるいは実効ユーザー ID か保存 set-user-ID
459 3) 自分自身のグループ ID あるいは実行グループ ID か保存 set-group-ID
466 .\"O option must be enabled on the socket.
468 メッセージを受信するためには、ソケットに対し
475 .\"O Selected local address is already taken or file system socket
476 .\"O object already exists.
477 選択したソケットが既に用いられていた。または、
478 ファイルシステムのソケットオブジェクトが既に存在していた。
482 .\"O called with a socket object that isn't listening.
483 .\"O This can happen when
484 .\"O the remote socket does not exist or the filename is not a socket.
485 listen 状態にないソケットオブジェクトに対して
487 が呼ばれた。リモートソケットが存在していなかった、
488 ファイル名がソケットではなかった、などのときに起こる。
491 .\"O Remote socket was unexpectedly closed.
492 リモートソケットが予期しないかたちでクローズされた。
495 .\"O User memory address was not valid.
499 .\"O Invalid argument passed.
500 .\"O A common cause is the missing setting of AF_UNIX
503 .\"O field of passed addresses or the socket being in an
504 .\"O invalid state for the applied operation.
508 フィールドに AF_UNIX を設定しなかった、
509 行おうとした操作に対してソケットの状態が有効ではなかった、など。
513 .\"O called on an already connected socket or a target address was
514 .\"O specified on a connected socket.
517 が呼ばれた。または、指定したターゲットアドレスが
525 .\"O Socket operation needs a target address, but the socket is not connected.
526 ソケット操作にターゲットアドレスが必要だが、
530 .\"O Stream operation called on non-stream oriented socket or tried to
531 .\"O use the out-of-band data option.
532 ストリーム指向でないソケットに対してストリーム操作が呼び出された。
533 または帯域外データオプションを用いようとした。
536 .\"O The sender passed invalid credentials in the
537 .\"O .IR "struct ucred" .
543 .\"O Remote socket was closed on a stream socket.
546 .\"O is sent as well.
547 .\"O This can be avoided by passing the
552 .\"O .BR recvmsg (2).
553 リモートソケットがストリームソケット上でクローズされた。
565 .\"O Passed protocol is not AF_UNIX.
566 渡されたプロトコルが AF_UNIX でない。
569 .\"O Remote socket does not match the local socket type
570 .\"O .RB ( SOCK_DGRAM
572 .\"O .BR SOCK_STREAM )
573 リモートソケットとローカルソケットのタイプが一致していなかった
579 .\"O Unknown socket type.
582 .\"O Other errors can be generated by the generic socket layer or
583 .\"O by the file system while generating a file system socket object.
584 .\"O See the appropriate manual pages for more information.
585 他にも汎用のソケット層でエラーが起こったり、
586 ファイルシステム上にソケットオブジェクトを作ろうとした場合に
587 ファイルシステムのエラーが起こることがある。
588 それぞれの詳細は適切な man ページを参照すること。
591 .\"O .B SCM_CREDENTIALS
592 .\"O and the abstract namespace were introduced with Linux 2.2 and should not
593 .\"O be used in portable programs.
595 と抽象名前空間は、Linux 2.2 で導入された。
596 移植性が必要なプログラムでは使うべきではない。
597 .\"O (Some BSD-derived systems also support credential passing,
598 .\"O but the implementation details differ.)
599 (BSD 由来のシステムの中にも信任状の送受信をサポートしているものがあるが、
603 .\"O In the Linux implementation, sockets which are visible in the
604 .\"O file system honor the permissions of the directory they are in.
605 .\"O Their owner, group and their permissions can be changed.
606 .\"O Creation of a new socket will fail if the process does not have write and
607 .\"O search (execute) permission on the directory the socket is created in.
608 .\"O Connecting to the socket object requires read/write permission.
609 .\"O This behavior differs from many BSD-derived systems which
610 .\"O ignore permissions for Unix sockets.
611 .\"O Portable programs should not rely on
612 .\"O this feature for security.
613 Linux の実装では、ファイルシステム上から見えるソケットは、
614 それらが置かれているディレクトリのパーミッションに従う。
615 ソケットの所有者、グループ、パーミッションは変更できる。
616 新しいソケットを作るとき、作ろうとするディレクトリに対して
617 プロセスが書き込みと検索 (実行) 権限を持っていなければ、作成に失敗する。
618 ソケットオブジェクトに接続するには、 read/write 権限が必要である。
619 この動作は、多くの BSD 由来のシステムとは異なっている
620 (BSD では Unix ソケットに対してはパーミッションを無視する)。
622 セキュリティをこの仕様に依存してはならない。
624 .\"O Binding to a socket with a filename creates a socket
625 .\"O in the file system that must be deleted by the caller when it is no
626 .\"O longer needed (using
627 .\"O .BR unlink (2)).
628 ファイル名を指定してソケットにバインドすると、
630 これは必要なくなったときに呼びだしたユーザーが削除しなければならない
633 .\"O The usual Unix close-behind semantics apply; the socket can be unlinked
634 .\"O at any time and will be finally removed from the file system when the last
635 .\"O reference to it is closed.
636 Unix で通常使われる「背後で閉じる方式」が適用される。
637 ソケットはいつでも unlink することができ、最後の参照が
638 クローズされたときにファイルシステムから削除される。
640 .\"O To pass file descriptors or credentials over a
641 .\"O .BR SOCK_STREAM ,
643 .\"O to send or receive at least one byte of nonancillary data in the same
649 上でファイルディスクリプタや信任状を渡すためには、同じ
653 コールで補助データ以外のデータを少なくとも
656 .\"O Unix domain stream sockets do not support the notion of out-of-band data.
657 Unix ドメインのストリーム・ソケットでは、
672 .BR capabilities (7),