Debian Codegraph @

upstream/debian-unstable/man3/if_nametoindex.3

raw
1 '\" t
2 .\" Copyright 2012, YOSHIFUJI Hideaki/吉藤英明 <[email protected]>
3 .\" Copyright, the authors of the Linux man-pages project
4 .\"
5 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\"
7 .TH if_nametoindex 3 2026-02-08 "Linux man-pages 6.18"
8 .SH NAME
9 if_nametoindex, if_indextoname \- mappings between network interface
10 names and indexes
11 .SH LIBRARY
12 Standard C library
13 .RI ( libc ,\~ \-lc )
14 .SH SYNOPSIS
15 .nf
16 .B #include <net/if.h>
17 .P
18 .BI "unsigned int if_nametoindex(const char *" "ifname" );
19 .BI "char *if_indextoname(unsigned int ifindex, char *" ifname );
20 .fi
21 .SH DESCRIPTION
22 The
23 .BR if_nametoindex ()
24 function returns the index of the network interface
25 corresponding to the name
26 .IR ifname .
27 .P
28 The
29 .BR if_indextoname ()
30 function returns the name of the network interface
31 corresponding to the interface index
32 .IR ifindex .
33 The name is placed in the buffer pointed to by
34 .IR ifname .
35 The buffer must allow for the storage of at least
36 .B IF_NAMESIZE
37 bytes.
38 .SH RETURN VALUE
39 On success,
40 .BR if_nametoindex ()
41 returns the index number of the network interface;
42 on error, 0 is returned and
43 .I errno
44 is set to indicate the error.
45 .P
46 On success,
47 .BR if_indextoname ()
48 returns
49 .IR ifname ;
50 on error, NULL is returned and
51 .I errno
52 is set to indicate the error.
53 .SH ERRORS
54 .BR if_nametoindex ()
55 may fail and set
56 .I errno
57 if:
58 .TP
59 .B ENODEV
60 No interface found with given name.
61 .P
62 .BR if_indextoname ()
63 may fail and set
64 .I errno
65 if:
66 .TP
67 .B ENXIO
68 No interface found for the index.
69 .P
70 .BR if_nametoindex ()
71 and
72 .BR if_indextoname ()
73 may also fail for any of the errors specified for
74 .BR socket (2)
75 or
76 .BR ioctl (2).
77 .SH ATTRIBUTES
78 For an explanation of the terms used in this section, see
79 .BR attributes (7).
80 .TS
81 allbox;
82 lbx lb lb
83 l l l.
84 Interface Attribute Value
85 T{
86 .na
87 .nh
88 .BR if_nametoindex (),
89 .BR if_indextoname ()
90 T} Thread safety MT-Safe
91 .TE
92 .SH STANDARDS
93 POSIX.1-2008, RFC\ 3493.
94 .SH HISTORY
95 POSIX.1-2001.
96 BSDi.
97 .SH SEE ALSO
98 .BR getifaddrs (3),
99 .BR if_nameindex (3),
100 .BR ifconfig (8)