1IF_NAMETOINDEX(3)          Linux Programmer's Manual         IF_NAMETOINDEX(3)
2
3
4

NAME

6       if_nametoindex,  if_indextoname  -  mappings  between network interface
7       names and indexes
8

SYNOPSIS

10       #include <net/if.h>
11
12       unsigned int if_nametoindex(const char *ifname);
13       char *if_indextoname(unsigned int ifindex, char *ifname);
14

DESCRIPTION

16       The if_nametoindex() function returns the index of the  network  inter‐
17       face corresponding to the name ifname.
18
19       The if_indextoname() function returns the name of the network interface
20       corresponding to the interface index ifindex.  The name  is  placed  in
21       the buffer pointed to by ifname.  The buffer must allow for the storage
22       of at least IF_NAMESIZE bytes.
23

RETURN VALUE

25       On success, if_nametoindex() returns the index number  of  the  network
26       interface; on error, 0 is returned and errno is set to indicate the er‐
27       ror.
28
29       On success, if_indextoname() returns ifname; on error, NULL is returned
30       and errno is set to indicate the error.
31

ERRORS

33       if_nametoindex() may fail and set errno if:
34
35       ENODEV No interface found with given name.
36
37       if_indextoname() may fail and set errno if:
38
39       ENXIO  No interface found for the index.
40
41       if_nametoindex()  and if_indextoname() may also fail for any of the er‐
42       rors specified for socket(2) or ioctl(2).
43

ATTRIBUTES

45       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
46       tributes(7).
47
48       ┌────────────────────────────────────────────┬───────────────┬─────────┐
49Interface                                   Attribute     Value   
50       ├────────────────────────────────────────────┼───────────────┼─────────┤
51if_nametoindex(), if_indextoname()          │ Thread safety │ MT-Safe │
52       └────────────────────────────────────────────┴───────────────┴─────────┘
53

CONFORMING TO

55       POSIX.1-2001, POSIX.1-2008, RFC 3493.
56
57       This function first appeared in BSDi.
58

SEE ALSO

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

COLOPHON

63       This  page  is  part of release 5.12 of the Linux man-pages project.  A
64       description of the project, information about reporting bugs,  and  the
65       latest     version     of     this    page,    can    be    found    at
66       https://www.kernel.org/doc/man-pages/.
67
68
69
70GNU                               2021-03-22                 IF_NAMETOINDEX(3)
Impressum