if_nametoindex(3)
π if_nametoindex(3) β the bestie guide to name β index glow-ups π
okay so this is if_nametoindex(3), a Library Functions Manual page from the if_nametoindex girlies, and we're about to learn how network interface names and interface indexes find each other. it's giving matchmaker. it's giving translator. it's giving MT-Safe and unbothered. π¦
β¨ NAME β¨
if_nametoindex, if_indextoname β mappings between network interface names and indexes
like. the whole point. name goes in, index comes out. index goes in, name comes out. it's a two-way situationship and both directions ate. π
π LIBRARY π
Standard C library (libc, -lc)
yes bestie, just the standard C library, nothing exotic, no extra credit needed. π
π«Ά SYNOPSIS π«Ά
#include <net/if.h>
unsigned int if_nametoindex(const char *ifname);
char *if_indextoname(unsigned int ifindex, char *ifname);
one include, two functions, zero drama. we love a low-maintenance API. β¨
πΈ DESCRIPTION πΈ
so. if_nametoindex() returns the index of the network interface corresponding to the name ifname. you hand it a name, it hands you back a number. iconic behavior. no cap.
and if_indextoname() does the exact reverse glow-up: it returns the name of the network interface corresponding to the interface index ifindex. the name gets placed in the buffer pointed to by ifname. πͺ
β οΈ okay listen, this part is important: that buffer must allow for the storage of at leastIF_NAMESIZEbytes. bestie. do not skimp on the buffer. do not give it a tiny lil buffer and hope for the best. at leastIF_NAMESIZEbytes. that's the rule. π
π RETURN VALUE π
okay so results, we love results:
- on success,
if_nametoindex()returns the index number of the network interface. on error,0is returned anderrnois set to indicate the error. π«Ά - on success,
if_indextoname()returns ifname. on error,NULLis returned anderrnois set to indicate the error. π
so like, 0 and NULL are the "nope" signals. check them. please. for me. π
π ERRORS π
if_nametoindex() may fail and set errno if:
ENODEVβ No interface found with given name.
if_indextoname() may fail and set errno if:
ENXIOβ No interface found for the index.
and also, plot twist: if_nametoindex() and if_indextoname() may also fail for any of the errors specified for socket(2) or ioctl(2). so if you're getting a weird errno and you're like "that's not in the list??" β yeah bestie, go check socket(2) and ioctl(2), the receipts are over there. π₯
π ATTRIBUTES π
for an explanation of the terms used in this section, see attributes(7). π
- Interface:
if_nametoindex(),if_indextoname()β Attribute: Thread safety β Value:MT-Safe
translated from table-ese: both of these are MT-Safe, which is the good one. thread-safe. run them from all your threads, they will not fight. periodt. β¨
β STANDARDS β
POSIX.1-2008, RFC 3493.
certified, standardised, officially that girl. π
π°οΈ HISTORY π°οΈ
POSIX.1-2001. BSDi.
so it's been around since POSIX.1-2001 and comes from BSDi β an elder icon, honestly, and it still serves. πΈ
π¦ SEE ALSO π¦
go read those next bestie, they're in the same friend group. π
and that's the whole page!! mwah!! ππ
this little masterpiece came to you courtesy of Linux man-pages 6.20, dated 2026-02-08, and it's the if_nametoindex(3) page β go map some interfaces, hydrate, and check your errno. πβ¨π«Ά
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2012, YOSHIFUJI Hideaki/εθ€θ±ζ <hideaki.yoshifuji@miraclelinux.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms