---
name: "if_nametoindex"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/if_nametoindex"
---

# if\_nametoindex(3)

mappings between network interface names and indexes

## NAME

if\_nametoindex, if\_indextoname - mappings between network interface names and indexes

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <net/if.h>
```

**unsigned int if\_nametoindex(const char \****ifname***);** **char \*if\_indextoname(unsigned int ifindex, char \****ifname***);**

## DESCRIPTION

The **if\_nametoindex**() function returns the index of the network interface corresponding to the name *ifname*.

The **if\_indextoname**() function returns the name of the network interface corresponding to the interface index *ifindex*. The name is placed in the buffer pointed to by *ifname*. The buffer must allow for the storage of at least **IF\_NAMESIZE** bytes.

## RETURN VALUE

On success, **if\_nametoindex**() returns the index number of the network interface; on error, 0 is returned and *errno* is set to indicate the error.

On success, **if\_indextoname**() returns *ifname*; on error, NULL is returned and *errno* is set to indicate the error.

## 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.

**if\_nametoindex**() and **if\_indextoname**() may also fail for any of the errors specified for [**socket**(2)](/socket/2.md) or [**ioctl**(2)](/ioctl/2.md).

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **if\_nametoindex**(), **if\_indextoname**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008, RFC 3493.

## HISTORY

POSIX.1-2001. BSDi.

## SEE ALSO

[**getifaddrs**(3)](/getifaddrs/3.md), [**if\_nameindex**(3)](/if_nameindex/3.md), [**ifconfig**(8)](/ifconfig/8.md)
