File: if_nameindex.3

package info (click to toggle)
manpages-ja 0.5.0.0.20180315%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 28,516 kB
  • sloc: perl: 161; makefile: 101
file content (127 lines) | stat: -rw-r--r-- 5,171 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
.\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
.\" and Copyright (c) 2012 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" %%%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 <amotoki@gmail.com>
.\"
.TH IF_NAMEINDEX 3 2012\-11\-21 GNU "Linux Programmer's Manual"
.SH 名前
if_nameindex, if_freenameindex \- ネットワークインターフェースの名前とインデックスを取得する
.SH 書式
.nf
\fB#include <net/if.h>\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 <net/if.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

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/ に書かれている。