mount_setattr.2: Minor tweaks to Christian's patch
[man-pages.git] / man3 / if_nametoindex.3
blob60f2d1df2c601666b86446aa6bae1884556fa37b
1 .\" Copyright (c) 2012 YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of
9 .\" this manual under the conditions for verbatim copying, provided that
10 .\" the entire resulting derived work is distributed under the terms of
11 .\" a permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume
15 .\" no responsibility for errors or omissions, or for damages resulting
16 .\" from the use of the information contained herein.  The author(s) may
17 .\" not have taken the same level of care in the production of this
18 .\" manual, which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH IF_NAMETOINDEX 3 2021-03-22 "GNU" "Linux Programmer's Manual"
26 .SH NAME
27 if_nametoindex, if_indextoname \- mappings between network interface
28 names and indexes
29 .SH SYNOPSIS
30 .nf
31 .B #include <net/if.h>
32 .PP
33 .BI "unsigned int if_nametoindex(const char *" "ifname" );
34 .BI "char *if_indextoname(unsigned int ifindex, char *" ifname );
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR if_nametoindex ()
39 function returns the index of the network interface
40 corresponding to the name
41 .IR ifname .
42 .PP
43 The
44 .BR if_indextoname ()
45 function returns the name of the network interface
46 corresponding to the interface index
47 .IR ifindex .
48 The name is placed in the buffer pointed to by
49 .IR ifname .
50 The buffer must allow for the storage of at least
51 .B IF_NAMESIZE
52 bytes.
53 .SH RETURN VALUE
54 On success,
55 .BR if_nametoindex ()
56 returns the index number of the network interface;
57 on error, 0 is returned and
58 .I errno
59 is set to indicate the error.
60 .PP
61 On success,
62 .BR if_indextoname ()
63 returns
64 .IR ifname ;
65 on error, NULL is returned and
66 .I errno
67 is set to indicate the error.
68 .SH ERRORS
69 .BR if_nametoindex ()
70 may fail and set
71 .I errno
72 if:
73 .TP
74 .B ENODEV
75 No interface found with given name.
76 .PP
77 .BR if_indextoname ()
78 may fail and set
79 .I errno
80 if:
81 .TP
82 .B ENXIO
83 No interface found for the index.
84 .PP
85 .BR if_nametoindex ()
86 and
87 .BR if_indextoname ()
88 may also fail for any of the errors specified for
89 .BR socket (2)
91 .BR ioctl (2).
92 .SH ATTRIBUTES
93 For an explanation of the terms used in this section, see
94 .BR attributes (7).
95 .ad l
96 .nh
97 .TS
98 allbox;
99 lbx lb lb
100 l l l.
101 Interface       Attribute       Value
103 .BR if_nametoindex (),
104 .BR if_indextoname ()
105 T}      Thread safety   MT-Safe
109 .sp 1
110 .SH CONFORMING TO
111 POSIX.1-2001, POSIX.1-2008, RFC\ 3493.
113 This function first appeared in BSDi.
114 .SH SEE ALSO
115 .BR getifaddrs (3),
116 .BR if_nameindex (3),
117 .BR ifconfig (8)