nl::Inet::InterfaceAddressIterator

#include <src/inet/InetInterface.h>

系统网络接口 IP 地址列表的迭代器。

摘要

使用此类的对象来迭代系统网络接口的 IP 地址列表。

此类的各个实例上的方法不是线程安全的;不过,多个线程可以同时使用单独的实例。

在多线程 LwIP 系统中,相对于访问全局 LwIP 状态的其他线程,实例是线程安全的,前提是:1) 其他线程在更改 netif 列表时持有 LwIP 核心锁;以及 2) netif 对象本身永远不会被销毁。

在基于套接字的系统上,当底层系统的接口和/或地址发生变化时,迭代始终是稳定的。

在 LwIP 系统中,迭代是稳定的,但与当前地址关联的接口被移除的情况除外,在这种情况下,迭代可能会过早结束。

构造函数和析构函数

InterfaceAddressIterator(void)
构造一个 InterfaceAddressIterator 对象。
~InterfaceAddressIterator(void)
销毁 InterfaceAddressIterator 对象。

公共函数

GetAddress(void)
获取当前的接口地址。
GetAddressWithPrefix(IPPrefix & addrWithPrefix)
void
返回包含当前地址的地址和前缀长度的 IPPrefix
GetIPv6PrefixLength(void)
uint8_t
已弃用的 GetPrefixLength(void) 别名
GetInterface(void)
InterfaceId
已弃用的 GetInterfaceId(void) 别名
GetInterfaceId(void)
InterfaceId
返回与当前接口地址关联的网络接口 ID。
GetInterfaceName(char *nameBuf, size_t nameBufSize)
获取与当前接口地址关联的网络接口的名称。
GetPrefixLength(void)
uint8_t
获取与当前接口地址关联的网络前缀。
HasBroadcastAddress(void)
bool
返回与当前接口地址关联的网络接口是否具有 IPv4 广播地址的指示值。
HasCurrent(void)
bool
IsUp(void)
bool
返回与当前接口地址关联的网络接口是否已启动。
Next(void)
bool
将迭代器前进到下一个接口地址。
SupportsMulticast(void)
bool
返回与当前接口地址关联的网络接口是否支持多播。

公共函数

GetAddress

IPAddress GetAddress(
 
void
)

获取当前的接口地址。

详细信息
返回值
当前的接口地址;如果迭代器的位置在地址列表的末尾之外,则返回 IPAddress::Any

GetAddressWithPrefix

void GetAddressWithPrefix(
 
IPPrefix & addrWithPrefix
)

返回包含当前地址的地址和前缀长度的 IPPrefix

GetIPv6PrefixLength

uint8_t GetIPv6PrefixLength(
 
void
)

已弃用的 GetPrefixLength(void) 别名

GetInterface

InterfaceId GetInterface(
 
void
)

已弃用的 GetInterfaceId(void) 别名

GetInterfaceId

InterfaceId GetInterfaceId(
 
void
)

返回与当前接口地址关联的网络接口 ID。

详细信息
返回值
接口 ID,如果迭代器的位置超出了地址列表的末尾,则为 INET_NULL_INTERFACEID

GetInterfaceName

INET_ERROR GetInterfaceName(
 
char *nameBuf,
  size_t nameBufSize
)

获取与当前接口地址关联的网络接口的名称。

Writes the name of the network interface as \c NUL terminated text string
at
\c nameBuf.

详细信息
参数
[in] nameBuf
内存区域,用于写入接口名称
[in] nameBufSize
nameBuf 表示的区域的大小
返回值
INET_NO_ERROR
结果成功,接口名称写入
INET_ERROR_NO_MEMORY
名称太大,无法写入缓冲区
INET_ERROR_INCORRECT_STATE
迭代器当前不在接口地址上
other
其他系统或平台错误

GetPrefixLength

uint8_t GetPrefixLength(
 
void
)

获取与当前接口地址关联的网络前缀。

On LwIP, this method simply returns the hard-coded constant 64.

Note Well: the standard subnet prefix on all links other than PPP
links
is 64 bits. On PPP links and some non-broadcast multipoint access
links
, the convention is either 127 bits or 128 bits, but it might be
something
else. On most platforms, the system's interface address
structure can represent arbitrary prefix lengths between 0 and 128.

详细信息
返回值
网络前缀(以位为单位),或者如果迭代器的位置超出地址列表的末尾,则为 0。

HasBroadcastAddress

bool HasBroadcastAddress(
 
void
)

返回与当前接口地址关联的网络接口是否具有 IPv4 广播地址的指示值。

详细信息
返回值
如果接口具有广播地址,则返回 true;如果没有广播地址,则返回 false;或者如果迭代器不在接口地址上,则返回此值。

HasCurrent

bool HasCurrent(
 
void
)

InterfaceAddressIterator

 InterfaceAddressIterator(
 
void
)

构造一个 InterfaceAddressIterator 对象。

在第一个网络地址处启动迭代器。在某些平台上,此构造函数可能会分配由析构函数回收的资源。

IsUp

bool IsUp(
 
void
)

返回与当前接口地址关联的网络接口是否已启动。

详细信息
返回值
如果当前网络接口已启动,则为 true;如果当前网络接口已启动,则为 false,或者如果迭代器未置于接口地址上。

下一步

bool Next(
 
void
)

将迭代器前进到下一个接口地址。

Advances the iterator to the next interface address or to a position
beyond the
end of the address list.

On LwIP, this method is thread-safe provided that: 1) other threads hold
the
LwIP core lock while mutating the netif list; and 2) netif objects
themselves are never destroyed
.  Additionally, iteration on LwIP systems
will terminate early
if the current interface is removed from the list.

详细信息
返回值
如果超过结束位置,则为 false,否则为 true

SupportsMulticast

bool SupportsMulticast(
 
void
)

返回与当前接口地址关联的网络接口是否支持多播。

详细信息
返回值
如果支持多播,则为 true;如果不支持多播,则为 false,或者如果迭代器未置于接口地址上。

~InterfaceAddressIterator

 ~InterfaceAddressIterator(
 
void
)

销毁 InterfaceAddressIterator 对象。

回收构造函数分配的所有资源。