nl::Inet::InterfaceIterator

#include <src/inet/InetInterface.h>

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

摘要

使用此类的对象可迭代系统网络接口列表。

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

在多线程 LwIP 系统上,相对于访问全局 LwIP 状态的其他线程而言,实例是线程安全的,前提是其他线程在更改 netif 列表时持有 LwIP 核心锁,并且该 netif 对象本身永远不会被销毁。

在基于套接字的系统上,面对底层系统的接口更改,迭代操作始终保持稳定。

在 LwIP 系统上,除非当前选定的接口已从列表中移除,否则迭代将立即结束。

构造函数和析构函数

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

受保护的属性

mCurIntf
size_t
mCurNetif
struct netif *
mIntfArray
struct if_nameindex *
mIntfFlags
short
mIntfFlagsCached
bool

公共函数

GetInterface(void)
InterfaceId
已弃用 GetInterfaceId(void) 的别名
GetInterfaceId(void)
InterfaceId
返回当前迭代器位置的网络接口 ID。
GetInterfaceName(char *nameBuf, size_t nameBufSize)
获取当前网络接口的名称。
HasBroadcastAddress(void)
bool
返回当前网络接口是否具有广播地址的指示值。
HasCurrent(void)
bool
测试迭代器是否位于接口上。
IsUp(void)
bool
返回当前网络接口是否已启动。
Next(void)
bool
让迭代器进入下一个网络接口。
SupportsMulticast(void)
bool
返回当前网络接口是否支持多播。

受保护的函数

GetFlags(void)
short
返回当前接口的 ifr_flags 值。

受保护的属性

mCurIntf

size_t mCurIntf

mCurNetif

struct netif * mCurNetif

mIntfArray

struct if_nameindex * mIntfArray

mIntfFlags

short mIntfFlags

mIntfFlagsCached

bool mIntfFlagsCached

公共函数

GetInterface

InterfaceId GetInterface(
  void
)

已弃用 GetInterfaceId(void) 的别名

GetInterfaceId

InterfaceId GetInterfaceId(
  void
)

返回当前迭代器位置的网络接口 ID。

具体说明
返回值
INET_NULL_INTERFACEID
如果超过了列表末尾
id
当前网络接口 ID。

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_INCORRECT_STATE
迭代器的位置超出了列表末尾
INET_ERROR_NO_MEMORY
名称太大,无法写入缓冲区
other
其他系统或平台错误

HasBroadcastAddress

bool HasBroadcastAddress(
  void
)

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

具体说明
返回值
如果当前网络接口具有广播地址,则为 true;如果没有广播地址,或者迭代器的位置超出了列表末尾,则为 false

HasCurrent

bool HasCurrent(
  void
)

测试迭代器是否位于接口上。

测试迭代器是否位于接口地址上。

具体说明
返回值
如果迭代器位于接口上,则为 true;如果位置超出接口列表末尾,则为 false
返回值
如果迭代器位于接口地址上,则为 true;如果位置超出地址列表末尾,则为 false

InterfaceIterator

 InterfaceIterator(
  void
)

构造一个 InterfaceIterator 对象。

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

IsUp

bool IsUp(
  void
)

返回当前网络接口是否已启动。

具体说明
返回值
如果当前网络接口已启动,则为 true;如果未启用或迭代器位置在列表末尾之外,则为 false

下一个

bool Next(
  void
)

让迭代器进入下一个网络接口。

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

On multi-threaded LwIP systems, this method is thread-safe relative to other
threads accessing the global LwIP state provided that: 1) the other threads
hold the LwIP core lock while mutating the list of netifs; and 2) netif objects
themselves are never destroyed.

Iteration is stable in the face of changes to the underlying system's
interfaces, *except* in the case of LwIP systems when the currently selected
interface is removed from the list, which causes iteration to end immediately.

具体说明
返回值
如果推进到末尾,则为 false,否则为 true

SupportsMulticast

bool SupportsMulticast(
  void
)

返回当前网络接口是否支持多播。

具体说明
返回值
如果当前网络接口支持多播,则为 true;如果不支持多播,或者迭代器的位置超出了列表末尾,则为 false

~InterfaceIterator

 ~InterfaceIterator(
  void
)

销毁 InterfaceIterator 对象。

回收由构造函数分配的任何资源。

受保护的函数

GetFlags

short GetFlags(
  void
)

返回当前接口的 ifr_flags 值。