nameToIndex

Converts the name of a network interface to its index.

If an interface with the name name cannot be found or another error occurres, returns 0.

@trusted
uint
nameToIndex
(
R
)
()
if (
isInputRange!R &&
is(Unqual!(ElementType!R) == char)
&&
hasLength!R
)

Parameters

name R

Interface name.

Return Value

Type: uint

Returns interface index or 0.

Examples

version (linux)
{
    assert(nameToIndex("lo") == 1);
}
else version (Windows)
{
    assert(nameToIndex("loopback_0") == 1);
}
else
{
    assert(nameToIndex("lo0") == 1);
}
assert(nameToIndex("ecafretni") == 0);

Meta