if_nametoindex

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

if_nametoindex, if_indextoname - ネットワークインターフェースの名前とインデックスのマッピングを行う  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <net/if.h>

unsigned int if_nametoindex(const char *ifname);
char *if_indextoname(unsigned int ifindex, char *ifname);
 

説明

if_nametoindex() 関数は、 名前が ifname のネットワークインターフェースのインデックスを返す。

if_indextoname() 関数は、 インターフェースのインデックスが ifindex に対応するネットワークインターフェースの名前を返す。 名前は ifname が指すバッファーに格納される。 バッファーは少なくとも IF_NAMESIZE バイトの領域が必要である。  

返り値

On success, if_nametoindex() returns the index number of the network interface; on error, 0 is returned and errno is set to indicate the error.

On success, if_indextoname() returns ifname; on error, NULL is returned and errno is set to indicate the error.  

エラー

if_nametoindex() が失敗した場合には以下の errno が設定される。
ENODEV
指定された名前を持つインターフェースがない。

if_indextoname() は以下の errno で失敗する場合がある。

ENXIO
インデックスに対応するインターフェースがない。

if_nametoindex() と if_indextoname() は、 socket(2) と ioctl(2) に対して規定されているエラーのいずれかで失敗する場合がある。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
if_nametoindex(), if_indextoname() Thread safetyMT-Safe
 

標準規格

POSIX.1-2008, RFC 3493.  

歴史

POSIX.1-2001. BSDi.  

関連項目

getifaddrs(3), if_nameindex(3), ifconfig(8)


 

Index

名前
ライブラリ
書式
説明
返り値
エラー
属性
標準規格
歴史
関連項目

This document was created by man2html, using the manual pages.