Google 致力于为黑人社区推动种族平等。查看具体行动

UDP

此模块包含用于控制 UDP 通信的函数。

总结

枚举

otNetifIdentifier{
  OT_NETIF_UNSPECIFIED = 0,
  OT_NETIF_THREAD,
  OT_NETIF_BACKBONE
}
枚举
定义 OpenThread 网络接口标识符。

类型定义符

otNetifIdentifier typedef
定义 OpenThread 网络接口标识符。
otUdpHandler)(void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo) typedef
bool(*
此回调允许 OpenThread 为特定 UDP 消息提供特定处理程序。
otUdpReceive)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) typedef
void(*
此回调允许 OpenThread 向应用通知收到的 UDP 消息。
otUdpReceiver typedef
struct otUdpReceiver
表示 UDP 接收器。
otUdpSocket typedef
struct otUdpSocket
表示 UDP 套接字。

函数

otUdpAddReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
添加 UDP 接收器。
otUdpBind(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName, otNetifIdentifier aNetif)
绑定 UDP/IPv6 套接字。
otUdpClose(otInstance *aInstance, otUdpSocket *aSocket)
关闭 UDP/IPv6 套接字。
otUdpConnect(otInstance *aInstance, otUdpSocket *aSocket, const otSockAddr *aSockName)
连接 UDP/IPv6 套接字。
otUdpGetSockets(otInstance *aInstance)
获取关联 UDP 套接字列表的头部。
otUdpIsOpen(otInstance *aInstance, const otUdpSocket *aSocket)
bool
检查 UDP 套接字是否处于打开状态。
otUdpNewMessage(otInstance *aInstance, const otMessageSettings *aSettings)
分配用于发送 UDP 消息的新消息缓冲区。
otUdpOpen(otInstance *aInstance, otUdpSocket *aSocket, otUdpReceive aCallback, void *aContext)
打开 UDP/IPv6 套接字。
otUdpRemoveReceiver(otInstance *aInstance, otUdpReceiver *aUdpReceiver)
移除 UDP 接收器。
otUdpSend(otInstance *aInstance, otUdpSocket *aSocket, otMessage *aMessage, const otMessageInfo *aMessageInfo)
发送 UDP/IPv6 消息。
otUdpSendDatagram(otInstance *aInstance, otMessage *aMessage, otMessageInfo *aMessageInfo)
发送不带套接字的 UDP 消息。

结构体

otUdpReceiver

表示 UDP 接收器。

otUdpSocket

表示 UDP 套接字。

枚举

otNetifIdentifier

 otNetifIdentifier

定义 OpenThread 网络接口标识符。

属性
OT_NETIF_BACKBONE

骨干网接口。

OT_NETIF_THREAD

Thread 接口。

OT_NETIF_UNSPECIFIED

未指定的网络接口。

类型定义符

otNetifIdentifier

enum otNetifIdentifier otNetifIdentifier

定义 OpenThread 网络接口标识符。

otUdpHandler

bool(* otUdpHandler)(void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)

此回调允许 OpenThread 为特定 UDP 消息提供特定处理程序。

详情
返回值
true
消息由该接收方处理,不应再处理。
false
此消息不会由此接收器处理。

OTUdp 接收

void(* otUdpReceive)(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)

此回调允许 OpenThread 向应用通知收到的 UDP 消息。

otUdpReceiver

struct otUdpReceiver otUdpReceiver

表示 UDP 接收器。

OTUdp 套接字

struct otUdpSocket otUdpSocket

表示 UDP 套接字。

函数

otUdpAddReceiver

otError otUdpAddReceiver(
  otInstance *aInstance,
  otUdpReceiver *aUdpReceiver
)

添加 UDP 接收器。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aUdpReceiver
指向 UDP 接收器的指针。
返回值
OT_ERROR_NONE
已成功添加接收器。
OT_ERROR_ALREADY
UDP 接收器已添加。

otUdpBind

otError otUdpBind(
  otInstance *aInstance,
  otUdpSocket *aSocket,
  const otSockAddr *aSockName,
  otNetifIdentifier aNetif
)

绑定 UDP/IPv6 套接字。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
[in] aSockName
指向 IPv6 套接字地址结构的指针。
[in] aNetif
要绑定的网络接口。
返回值
OT_ERROR_NONE
绑定操作成功。
OT_ERROR_FAILED
未能绑定 UDP 套接字。

otUdpClose

otError otUdpClose(
  otInstance *aInstance,
  otUdpSocket *aSocket
)

关闭 UDP/IPv6 套接字。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
返回值
OT_ERROR_NONE
已成功关闭套接字。
OT_ERROR_FAILED
未能关闭 UDP 套接字。

OTUdp 连接

otError otUdpConnect(
  otInstance *aInstance,
  otUdpSocket *aSocket,
  const otSockAddr *aSockName
)

连接 UDP/IPv6 套接字。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
[in] aSockName
指向 IPv6 套接字地址结构的指针。
返回值
OT_ERROR_NONE
连接操作成功。
OT_ERROR_FAILED
未能连接 UDP 套接字。

otUdpGetSockets

otUdpSocket * otUdpGetSockets(
  otInstance *aInstance
)

获取关联 UDP 套接字列表的头部。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
返回
指向 UDP 套接字关联列表头的指针。

OTUdpIOpen

bool otUdpIsOpen(
  otInstance *aInstance,
  const otUdpSocket *aSocket
)

检查 UDP 套接字是否处于打开状态。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
返回
UDP 套接字是否打开。

otUdpNewMessage

otMessage * otUdpNewMessage(
  otInstance *aInstance,
  const otMessageSettings *aSettings
)

分配用于发送 UDP 消息的新消息缓冲区。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSettings
指向消息设置的指针或 NULL,以使用默认设置。
返回
在消息缓冲区不可用或参数无效时,指向消息缓冲区或 NULL 的指针。
另请参阅
otMessageFree

OTUdp 打开

otError otUdpOpen(
  otInstance *aInstance,
  otUdpSocket *aSocket,
  otUdpReceive aCallback,
  void *aContext
)

打开 UDP/IPv6 套接字。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
[in] aCallback
指向应用回调函数的指针。
[in] aContext
指向应用上下文的指针。
返回值
OT_ERROR_NONE
已成功打开套接字。
OT_ERROR_FAILED
未能打开套接字。

otUdpRemoveReceiver

otError otUdpRemoveReceiver(
  otInstance *aInstance,
  otUdpReceiver *aUdpReceiver
)

移除 UDP 接收器。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aUdpReceiver
指向 UDP 接收器的指针。
返回值
OT_ERROR_NONE
已成功移除接收器。
OT_ERROR_NOT_FOUND
尚未添加 UDP 接收器。

otUdpSend

otError otUdpSend(
  otInstance *aInstance,
  otUdpSocket *aSocket,
  otMessage *aMessage,
  const otMessageInfo *aMessageInfo
)

发送 UDP/IPv6 消息。

如果返回值为 OT_ERROR_NONE,OpenThread 会获得 aMessage 的所有权,并且调用方应该不再引用 aMessage。如果返回值不是 OT_ERROR_NONE,调用方会保留 aMessage 的所有权,包括在消息缓冲区不再需要时释放 aMessage

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aSocket
指向 UDP 套接字结构的指针。
[in] aMessage
指向消息缓冲区的指针。
[in] aMessageInfo
指向消息信息结构的指针。

详情
返回值
OT_ERROR_NONE
已成功安排发送邮件。
OT_ERROR_INVALID_ARGS
提供的参数无效。
OT_ERROR_NO_BUFS
可用缓冲区不足,无法添加 UDP 和 IPv6 标头。

otUdpSendDatagram

otError otUdpSendDatagram(
  otInstance *aInstance,
  otMessage *aMessage,
  otMessageInfo *aMessageInfo
)

发送不带套接字的 UDP 消息。

详情
参数
[in] aInstance
指向 OpenThread 实例的指针。
[in] aMessage
指向不带 UDP 标头的消息的指针。
[in] aMessageInfo
指向与 aMessage 关联的消息信息的指针。
返回值
OT_ERROR_NONE
已成功将消息加入输出接口的队列。
OT_ERROR_NO_BUFS
可用缓冲区不足,无法添加 IPv6 标头。

资源

OpenThread API 参考主题源自源代码,可在 GitHub 上获取。 如需了解详情或为我们的文档贡献内容,请参阅资源