1 .\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
2 .\" and Copyright (c) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
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.
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.
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
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
26 .\"*******************************************************************
28 .\" This file was generated with po4a. Translate the source file.
30 .\"*******************************************************************
32 .\" Japanese Version Copyright (c) 2013 Akihiro MOTOKI
33 .\" all rights reserved.
34 .\" Translated 2013-05-22, Akihiro MOTOKI <amotoki@gmail.com>
36 .TH IF_NAMEINDEX 3 2012\-11\-21 GNU "Linux Programmer's Manual"
38 if_nameindex, if_freenameindex \- ネットワークインターフェースの名前とインデックスを取得する
41 \fB#include <net/if.h>\fP
43 \fBstruct if_nameindex *if_nameindex(void);\fP
44 \fBvoid if_freenameindex(struct if_nameindex *\fP\fIptr\fP\fB);\fP
47 \fBif_nameindex\fP() 関数は \fIif_nameindex\fP 構造体の配列を返す。
48 各構造体にはローカルシステムのネットワークインターフェースのいずれかの情報が入る。 \fIif_nameindex\fP
49 構造体には少なくとも以下のフィールドがある。
53 unsigned int if_index; /* インターフェースのインデックス (1, 2, ...) */
54 char *if_name; /*ヌル終端された名前 ("eth0" など) */
58 \fIif_index\fP フィールドにはインターフェースのインデックスが入る。 \fIifa_name\fP
59 フィールドはヌル終端されたインターフェース名を指す。 配列の最後は、 \fIif_index\fP が 0 で \fIifa_name\fP が NULL
62 \fBif_nameindex\fP() が返すデータ構造体は動的に確保される。 必要なくなった際には \fBif_freenameindex\fP()
65 成功した場合には \fBif_nameindex\fP() は配列へのポインタを返す。エラー時には NULL が返され、 \fIerrno\fP
68 \fBif_nameindex\fP() が失敗した場合には以下の \fIerrno\fP が設定される。
73 \fBif_nameindex\fP() は、 \fBsocket\fP(2), \fBbind\fP(2), \fBioctl\fP(2),
74 \fBgetsockname\fP(2), \fBrecvmsg\fP(2), \fBsendto\fP(2), \fBmalloc\fP(3)
75 に対して規定されているエラーのいずれかで失敗する場合がある。
77 \fBif_nameindex\fP() 関数は glibc 2.1 で初めて登場したが、 glibc 2.3.4 より前のバージョンの実装では IPv4
78 アドレスを持つインターフェースのみをサポートしていた。 IPv4 アドレスを持たないインターフェースがサポートされているのは、 netlink
81 RFC\ 3493, POSIX.1\-2001.
85 以下のプログラムはこのページで説明した関数の使い方を示している。このプログラムが生成する出力は以下のようになる。
103 main(int argc, char *argv[])
105 struct if_nameindex *if_ni, *i;
107 if_ni = if_nameindex();
109 perror("if_nameindex");
113 for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++)
114 printf("%u: %s\en", i\->if_index, i\->if_name);
116 if_freenameindex(if_ni);
122 \fBgetsockopt\fP(2), \fBsetsockopt\fP(2), \fBgetifaddrs\fP(3), \fBif_indextoname\fP(3),
123 \fBif_nametoindex\fP(3), \fBifconfig\fP(8)
125 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.68 の一部
126 である。プロジェクトの説明とバグ報告に関する情報は
127 http://www.kernel.org/doc/man\-pages/ に書かれている。