C++ utilities for the netint (Network Interfaces) module.
◆ GetDefaultInterface()
Get information about the default network interface.
For our purposes, the 'default' network interface is defined as the interface that is chosen for the default IP route. The default interface is given as an OS network interface index - see Network Interface Indexes for more information. Note that since network interfaces can have multiple IP addresses assigned, this index may be shared by many entries returned by etcpal_netint_get_interfaces().
- Parameters
-
[in] | type | The IP protocol for which to get the default network interface, either kEtcPalIpTypeV4 or kEtcPalIpTypeV6. A separate default interface is maintained for each. |
- Returns
- The index of the default interface on success.
-
kEtcPalErrInvalid: Invalid argument provided.
-
kEtcPalErrNotInit: Module not initialized.
-
kEtcPalErrNotFound: No default interface found for this type.
◆ GetInterfaceForDest()
Get the network interface that the system will choose when routing an IP packet to the specified destination.
- Parameters
-
[in] | dest | IP address of the destination. |
[out] | netint_index | Pointer to value to fill in with |
- Returns
- The index of the chosen interface on success.
-
kEtcPalErrInvalid: Invalid argument provided.
-
kEtcPalErrNotInit: Module not initialized.
-
kEtcPalErrNoNetints: No network interfaces found on system.
-
kEtcPalErrNotFound: No route was able to be resolved to the destination.
◆ GetInterfaces()
Get a list of network interfaces on the system.
For NICs with multiple IP addresses assigned, this module separates each address into its own entry in the netint array. Because of this, multiple array entries could have the same value for the index, mac and id parameters.
- Returns
- The array of network interfaces on success.
-
kEtcPalErrInvalid: Invalid argument provided.
-
kEtcPalErrNotInit: Module not initialized.
-
kEtcPalErrNotFound: No system interfaces were found.
◆ GetInterfacesForIndex()
◆ GetInterfaceWithIp()
Get the network interface that has the specified IP address.
- Parameters
-
[in] | ip | The IP address assigned to the desired interface. |
- Returns
- Information for the matching interface if found.
-
kEtcPalErrInvalid: Invalid argument provided.
-
kEtcPalErrNotInit: Module not initialized.
-
kEtcPalErrNotFound: No interfaces found for this IP address.
-
kEtcPalErrSys: Multiple interfaces were configured at the same IP address, which means the system is misconfigured.
◆ IsUp()
Determine whether a network interface is currently up and running.
- Note
- On Windows, cached network interface information is used to determine this, so the result for a given index will not change until etcpal::netint::RefreshInterfaces() is called.
- Parameters
-
index | Index of the interface to check. |
- Returns
- true: The interface indicated by index is up.
-
false: The interface indicated by index is down, or index is invalid.
◆ RefreshInterfaces()
Refresh the list of network interfaces.
Rebuilds the cached array of network interfaces that is returned via the etcpal::netint::GetInterfaces() function.
- Returns
- kEtcPalErrOk: Interfaces refreshed.
-
Other error codes from the underlying platform are possible here.