UDP#
This module includes functions that control UDP communication.
Modules#
Enumerations#
Defines the OpenThread network interface identifiers.
Typedefs#
Represents a callback to handle a received UDP message.
Represents a UDP receiver.
Callback function pointer to notify the application of a received UDP message on a UDP socket.
Defines the OpenThread network interface identifiers.
Represents a UDP socket.
Functions#
Adds a UDP receiver.
Removes a UDP receiver.
Sends a UDP message without socket.
Allocate a new message buffer for sending a UDP message.
Check if a UDP socket is open.
Close a UDP/IPv6 socket.
Connect a UDP/IPv6 socket.
Gets the head of linked list of UDP Sockets.
Enumeration Documentation#
otNetifIdentifier#
otNetifIdentifier
Defines the OpenThread network interface identifiers.
| Enumerator | |
|---|---|
| OT_NETIF_UNSPECIFIED | Unspecified network interface. |
| OT_NETIF_THREAD_HOST | The host Thread interface - allow use of platform UDP. |
| OT_NETIF_THREAD_INTERNAL | The internal Thread interface (within OpenThread) - do not use platform UDP. |
| OT_NETIF_BACKBONE | The Backbone interface. |
Typedef Documentation#
otUdpHandler#
typedef bool(* otUdpHandler) (void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo) )(void *aContext, const otMessage *aMessage, const otMessageInfo *aMessageInfo)
Represents a callback to handle a received UDP message.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| [in] | aContext | A pointer to the application-specific context. | |
| [in] | aMessage | A pointer to the received UDP message. | |
| [in] | aMessageInfo | A pointer to the IPv6 message info structure. |
This callback is used by a UDP receiver (see otUdpAddReceiver()) to process an incoming UDP message.
This callback does not transfer ownership of aMessage. The callback implementation must not modify the message content. The message is guaranteed to be valid only within the context of the callback.
otUdpReceive#
typedef void(* otUdpReceive) (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo) )(void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
Callback function pointer to notify the application of a received UDP message on a UDP socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| [in] | aContext | A pointer to the application-specific context. | |
| [in] | aMessage | A pointer to the received UDP message. | |
| [in] | aMessageInfo | A pointer to the IPv6 message info structure. |
This callback does not transfer ownership of aMessage. The callback implementation must not modify the message content. The message is guaranteed to be valid only within the context of the callback.
otNetifIdentifier#
typedef enum otNetifIdentifier otNetifIdentifier
Defines the OpenThread network interface identifiers.
Function Documentation#
otUdpAddReceiver#
otError otUdpAddReceiver (otInstance * aInstance, otUdpReceiver * aUdpReceiver)
Adds a UDP receiver.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpReceiver * | [in] | aUdpReceiver | A pointer to the UDP receiver. |
otUdpRemoveReceiver#
otError otUdpRemoveReceiver (otInstance * aInstance, otUdpReceiver * aUdpReceiver)
Removes a UDP receiver.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpReceiver * | [in] | aUdpReceiver | A pointer to the UDP receiver. |
otUdpSendDatagram#
otError otUdpSendDatagram (otInstance * aInstance, otMessage * aMessage, otMessageInfo * aMessageInfo)
Sends a UDP message without socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otMessage * | [in] | aMessage | A pointer to a message without UDP header. |
| otMessageInfo * | [in] | aMessageInfo | A pointer to a message info associated with |
otUdpNewMessage#
otMessage * otUdpNewMessage (otInstance * aInstance, const otMessageSettings * aSettings)
Allocate a new message buffer for sending a UDP message.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| const otMessageSettings * | [in] | aSettings | A pointer to the message settings or NULL to use default settings. |
Note
If
aSettingsis 'NULL', the link layer security is enabled and the message priority is set to OT_MESSAGE_PRIORITY_NORMAL by default.
Returns
A pointer to the message buffer or NULL if no message buffers are available or parameters are invalid.
See Also
otUdpOpen#
otError otUdpOpen (otInstance * aInstance, otUdpSocket * aSocket, otUdpReceive aCallback, void * aContext)
Open a UDP/IPv6 socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
| otUdpReceive | [in] | aCallback | A pointer to the application callback function. |
| void * | [in] | aContext | A pointer to application-specific context. |
otUdpIsOpen#
bool otUdpIsOpen (otInstance * aInstance, const otUdpSocket * aSocket)
Check if a UDP socket is open.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| const otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
Returns
Whether the UDP socket is open.
otUdpClose#
otError otUdpClose (otInstance * aInstance, otUdpSocket * aSocket)
Close a UDP/IPv6 socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
otUdpBind#
otError otUdpBind (otInstance * aInstance, otUdpSocket * aSocket, const otSockAddr * aSockName, otNetifIdentifier aNetif)
Bind a UDP/IPv6 socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
| const otSockAddr * | [in] | aSockName | A pointer to an IPv6 socket address structure. |
| otNetifIdentifier | [in] | aNetif | The network interface to bind. |
otUdpConnect#
otError otUdpConnect (otInstance * aInstance, otUdpSocket * aSocket, const otSockAddr * aSockName)
Connect a UDP/IPv6 socket.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
| const otSockAddr * | [in] | aSockName | A pointer to an IPv6 socket address structure. |
otUdpSend#
otError otUdpSend (otInstance * aInstance, otUdpSocket * aSocket, otMessage * aMessage, const otMessageInfo * aMessageInfo)
Send a UDP/IPv6 message.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
| otUdpSocket * | [in] | aSocket | A pointer to a UDP socket structure. |
| otMessage * | [in] | aMessage | A pointer to a message buffer. |
| const otMessageInfo * | [in] | aMessageInfo | A pointer to a message info structure. |
If the return value is OT_ERROR_NONE, OpenThread takes ownership of aMessage, and the caller should no longer reference aMessage. If the return value is not OT_ERROR_NONE, the caller retains ownership of aMessage, including freeing aMessage if the message buffer is no longer needed.
otUdpGetSockets#
otUdpSocket * otUdpGetSockets (otInstance * aInstance)
Gets the head of linked list of UDP Sockets.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| otInstance * | [in] | aInstance | A pointer to an OpenThread instance. |
Returns
A pointer to the head of UDP Socket linked list.