.\" Copyright (c) 2012 YOSHIFUJI Hideaki .\" and Copyright (c) 2012 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of .\" this manual under the conditions for verbatim copying, provided that .\" the entire resulting derived work is distributed under the terms of .\" a permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume .\" no responsibility for errors or omissions, or for damages resulting .\" from the use of the information contained herein. The author(s) may .\" not have taken the same level of care in the production of this .\" manual, which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .\" .\" Japanese Version Copyright (c) 2013 Akihiro MOTOKI .\" all rights reserved. .\" Translated 2013-05-22, Akihiro MOTOKI .\" .TH IF_NAMEINDEX 3 2012\-11\-21 GNU "Linux Programmer's Manual" .SH 名前 if_nameindex, if_freenameindex \- ネットワークインターフェースの名前とインデックスを取得する .SH 書式 .nf \fB#include \fP .sp \fBstruct if_nameindex *if_nameindex(void);\fP \fBvoid if_freenameindex(struct if_nameindex *\fP\fIptr\fP\fB);\fP .fi .SH 説明 \fBif_nameindex\fP() 関数は \fIif_nameindex\fP 構造体の配列を返す。 各構造体にはローカルシステムのネットワークインターフェースのいずれかの情報が入る。 \fIif_nameindex\fP 構造体には少なくとも以下のフィールドがある。 .sp .in +4n .nf unsigned int if_index; /* インターフェースのインデックス (1, 2, ...) */ char *if_name; /*ヌル終端された名前 ("eth0" など) */ .fi .in .PP \fIif_index\fP フィールドにはインターフェースのインデックスが入る。 \fIifa_name\fP フィールドはヌル終端されたインターフェース名を指す。 配列の最後は、 \fIif_index\fP が 0 で \fIifa_name\fP が NULL のエントリーで示される。 .PP \fBif_nameindex\fP() が返すデータ構造体は動的に確保される。 必要なくなった際には \fBif_freenameindex\fP() で解放すべきである。 .SH 返り値 成功した場合には \fBif_nameindex\fP() は配列へのポインターを返す。エラー時には NULL が返され、 \fIerrno\fP が適切に設定される。 .SH エラー \fBif_nameindex\fP() が失敗した場合には以下の \fIerrno\fP が設定される。 .TP \fBENOBUFS\fP 利用可能なリソースが十分にない。 .PP \fBif_nameindex\fP() は、 \fBsocket\fP(2), \fBbind\fP(2), \fBioctl\fP(2), \fBgetsockname\fP(2), \fBrecvmsg\fP(2), \fBsendto\fP(2), \fBmalloc\fP(3) に対して規定されているエラーのいずれかで失敗する場合がある。 .SH バージョン \fBif_nameindex\fP() 関数は glibc 2.1 で初めて登場したが、 glibc 2.3.4 より前のバージョンの実装では IPv4 アドレスを持つインターフェースのみをサポートしていた。 IPv4 アドレスを持たないインターフェースがサポートされているのは、 netlink をサポートするカーネルにおいてのみである。 .SH 準拠 RFC\ 3493, POSIX.1\-2001. この関数は BSDi 初めて登場した。 .SH 例 以下のプログラムはこのページで説明した関数の使い方を示している。このプログラムが生成する出力は以下のようになる。 .in +4n .nf $ \fB./a.out\fP\fI 1: lo 2: wlan0 3: em1\fP .fi .in .SS プログラムのソース .nf #include #include #include #include int main(int argc, char *argv[]) { struct if_nameindex *if_ni, *i; if_ni = if_nameindex(); if (if_ni == NULL) { perror("if_nameindex"); exit(EXIT_FAILURE); } for (i = if_ni; ! (i\->if_index == 0 && i\->if_name == NULL); i++) printf("%u: %s\en", i\->if_index, i\->if_name); if_freenameindex(if_ni); exit(EXIT_SUCCESS); } .fi .SH 関連項目 \fBgetsockopt\fP(2), \fBsetsockopt\fP(2), \fBgetifaddrs\fP(3), \fBif_indextoname\fP(3), \fBif_nametoindex\fP(3), \fBifconfig\fP(8) .SH この文書について この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部 である。プロジェクトの説明とバグ報告に関する情報は http://www.kernel.org/doc/man\-pages/ に書かれている。