1if_nametoindex(3) Library Functions Manual if_nametoindex(3)
2
3
4
6 if_nametoindex, if_indextoname - mappings between network interface
7 names and indexes
8
10 Standard C library (libc, -lc)
11
13 #include <net/if.h>
14
15 unsigned int if_nametoindex(const char *ifname);
16 char *if_indextoname(unsigned int ifindex, char *ifname);
17
19 The if_nametoindex() function returns the index of the network inter‐
20 face corresponding to the name ifname.
21
22 The if_indextoname() function returns the name of the network interface
23 corresponding to the interface index ifindex. The name is placed in
24 the buffer pointed to by ifname. The buffer must allow for the storage
25 of at least IF_NAMESIZE bytes.
26
28 On success, if_nametoindex() returns the index number of the network
29 interface; on error, 0 is returned and errno is set to indicate the er‐
30 ror.
31
32 On success, if_indextoname() returns ifname; on error, NULL is returned
33 and errno is set to indicate the error.
34
36 if_nametoindex() may fail and set errno if:
37
38 ENODEV No interface found with given name.
39
40 if_indextoname() may fail and set errno if:
41
42 ENXIO No interface found for the index.
43
44 if_nametoindex() and if_indextoname() may also fail for any of the er‐
45 rors specified for socket(2) or ioctl(2).
46
48 For an explanation of the terms used in this section, see at‐
49 tributes(7).
50
51 ┌────────────────────────────────────────────┬───────────────┬─────────┐
52 │Interface │ Attribute │ Value │
53 ├────────────────────────────────────────────┼───────────────┼─────────┤
54 │if_nametoindex(), if_indextoname() │ Thread safety │ MT-Safe │
55 └────────────────────────────────────────────┴───────────────┴─────────┘
56
58 POSIX.1-2008, RFC 3493.
59
61 POSIX.1-2001. BSDi.
62
64 getifaddrs(3), if_nameindex(3), ifconfig(8)
65
66
67
68Linux man-pages 6.05 2023-07-20 if_nametoindex(3)