Function nameToIndex
Converts the name of a network interface to its index.
uint nameToIndex(R)
(
R name
) @trusted
if (isInputRange!R && is(Unqual!(ElementType!R) == char) && hasLength!R);
If an interface with the name name cannot be found or another error occurres, returns 0.
Parameters
Name | Description |
---|---|
name | Interface name. |
Returns
Returns interface index or 0.
Example
version (linux)
{
assert(nameToIndex("lo") == 1);
}
else version (Windows)
{
assert(nameToIndex("loopback_0") == 1);
}
else
{
assert(nameToIndex("lo0") == 1);
}
assert(nameToIndex("ecafretni") == 0);