OSDN Git Service

05576d07d126ece57d5cd29eef31e71eec4a42e3
[linuxjm/LDP_man-pages.git] / draft / man3 / if_nameindex.3
1 .\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
2 .\" and Copyright (c) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of
10 .\" this manual under the conditions for verbatim copying, provided that
11 .\" the entire resulting derived work is distributed under the terms of
12 .\" a permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume
16 .\" no responsibility for errors or omissions, or for damages resulting
17 .\" from the use of the information contained herein.  The author(s) may
18 .\" not have taken the same level of care in the production of this
19 .\" manual, which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\"*******************************************************************
27 .\"
28 .\" This file was generated with po4a. Translate the source file.
29 .\"
30 .\"*******************************************************************
31 .TH IF_NAMEINDEX 3 2012\-11\-21 GNU "Linux Programmer's Manual"
32 .SH 名前
33 if_nameindex, if_freenameindex \- ネットワークインターフェースの名前とインデックスを取得する
34 .SH 書式
35 .nf
36 \fB#include <net/if.h>\fP
37 .sp
38 \fBstruct if_nameindex *if_nameindex(void);\fP
39 \fBvoid if_freenameindex(struct if_nameindex *\fP\fIptr\fP\fB);\fP
40 .fi
41 .SH 説明
42 \fBif_nameindex\fP() 関数は \fIif_nameindex\fP 構造体の配列を返す。
43 各構造体にはローカルシステムのネットワークインターフェースのいずれかの情報が入る。 \fIif_nameindex\fP
44 構造体には少なくとも以下のフィールドがある。
45 .sp
46 .in +4n
47 .nf
48     unsigned int if_index; /* インターフェースのインデックス (1, 2, ...) */
49     char        *if_name;  /* NULL 終端された名前 ("eth0" など) */
50 .fi
51 .in
52 .PP
53 \fIif_index\fP フィールドにはインターフェースのインデックスが入る。 \fIifa_name\fP フィールドは NULL
54 終端されたインターフェース名を指す。 配列の最後は、 \fIif_index\fP が 0 で \fIifa_name\fP が NULL のエントリで示される。
55 .PP
56 \fBif_nameindex\fP() が返すデータ構造体は動的に確保される。 必要なくなった際には \fBif_freenameindex\fP()
57 で解放すべきである。
58 .SH 返り値
59 成功した場合には \fBif_nameindex\fP() は配列へのポインタを返す。エラー時には NULL ポインタが返され、 \fIerrno\fP
60 が適切に設定される。
61 .SH エラー
62 \fBif_nameindex\fP() が失敗した場合には以下の \fIerrno\fP が設定される。
63 .TP 
64 \fBENOBUFS\fP
65 利用可能なリソースが十分にない。
66 .PP
67 \fBif_nameindex\fP() は、 \fBsocket\fP(2), \fBbind\fP(2), \fBioctl\fP(2),
68 \fBgetsockname\fP(2), \fBrecvmsg\fP(2), \fBsendto\fP(2), \fBmalloc\fP(3)
69 に対して規定されているエラーのいずれかで失敗する場合がある。
70 .SH バージョン
71 \fBif_nameindex\fP() 関数は glibc 2.1 で初めて登場したが、 glibc 2.3.4 より前のバージョンの実装では IPv4
72 アドレスを持つインターフェースのみをサポートしていた。 IPv4 アドレスを持たないインターフェースがサポートされているのは、 netlink
73 をサポートするカーネルにおいてのみである。
74 .SH 準拠
75 RFC\ 3493, POSIX.1\-2001.
76
77 この関数は BSDi 初めて登場した。
78 .SH 例
79 以下のプログラムはこのページで説明した関数の使い方を示している。このプログラムが生成する出力は以下のようになる。
80 .in +4n
81 .nf
82 $ \fB./a.out\fP\fI
83 1: lo
84 2: wlan0
85 3: em1\fP
86 .fi
87 .in
88 .SS プログラムのソース
89 .nf
90 #include <net/if.h>
91 #include <stdio.h>
92 #include <stdlib.h>
93 #include <unistd.h>
94
95 int
96 main(int argc, char *argv[])
97 {
98     struct if_nameindex *if_ni, *i;
99
100     if_ni = if_nameindex();
101     if (if_ni == NULL) {
102         perror("if_nameindex");
103         exit(EXIT_FAILURE);
104     }
105
106     for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++)
107         printf("%u: %s\en", i\->if_index, i\->if_name);
108
109     if_freenameindex(if_ni);
110
111     exit(EXIT_SUCCESS);
112 }
113 .fi
114 .SH 関連項目
115 \fBgetsockopt\fP(2), \fBsetsockopt\fP(2), \fBgetifaddrs\fP(3), \fBif_indextoname\fP(3),
116 \fBif_nametoindex\fP(3), \fBifconfig\fP(8)
117 .SH この文書について
118 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
119 である。プロジェクトの説明とバグ報告に関する情報は
120 http://www.kernel.org/doc/man\-pages/ に書かれている。