# UDP Forward

# UDP Forward

This module includes functions for UDP forward feature.

## Summary

The functions in this module are available when udp-forward feature (`OPENTHREAD_CONFIG_UDP_FORWARD_ENABLE`) is enabled.

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-udp-forward#group__api-udp-forward_1ga38f70e4b45b9f85519fb4e9c5ba9e0e5)(otMessage *aMessage, uint16_t aPeerPort, otIp6Address *aPeerAddr, uint16_t aSockPort, void *aContext)` | typedef `void(*` Pointer delivers the UDP packet to host and host should send the packet through its own network stack. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-udp-forward#group__api-udp-forward_1ga52995fb53265e320d10f7545eb8ae4aa(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-message#group__api-message_1ga42d128a0a9ad58de0eb79673843c2955 *aMessage, uint16_t aPeerPort, const https://openthread.io/reference/struct/ot-ip6-address *aPeerAddr, uint16_t aSockPort)` | `void` Handle a UDP packet received from host. |
| `https://openthread.io/reference/group/api-udp-forward#group__api-udp-forward_1ga9c8af485751d4cf1de0fb9396241fa4d(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-udp-forward#group__api-udp-forward_1ga38f70e4b45b9f85519fb4e9c5ba9e0e5 aForwarder, void *aContext)` | `void` Set UDP forward callback to deliver UDP packets to host. |
| `https://openthread.io/reference/group/api-udp-forward#group__api-udp-forward_1ga5a15b0096685e0514ebcb7fa54c03ef2(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, uint16_t port)` | `bool` Determines if the given UDP port is exclusively opened by OpenThread API. |

## Typedefs

### otUdpForwarder

```
void(* otUdpForwarder)(otMessage *aMessage, uint16_t aPeerPort, otIp6Address *aPeerAddr, uint16_t aSockPort, void *aContext)
```
Pointer delivers the UDP packet to host and host should send the packet through its own network stack.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aMessage` | A pointer to the UDP Message. | | `[in] aPeerPort` | The destination UDP port. | | `[in] aPeerAddr` | A pointer to the destination IPv6 address. | | `[in] aSockPort` | The source UDP port. | | `[in] aContext` | A pointer to application-specific context. | |

## Functions

### otUdpForwardReceive

```
void otUdpForwardReceive(
  otInstance *aInstance,
  otMessage *aMessage,
  uint16_t aPeerPort,
  const otIp6Address *aPeerAddr,
  uint16_t aSockPort
)
```
Handle a UDP packet received from host.

No matter the call success or fail, the message is freed.

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aMessage` | A pointer to the UDP Message. | | `[in] aPeerPort` | The source UDP port. | | `[in] aPeerAddr` | A pointer to the source address. | | `[in] aSockPort` | The destination UDP port. | |

### otUdpForwardSetForwarder

```
void otUdpForwardSetForwarder(
  otInstance *aInstance,
  otUdpForwarder aForwarder,
  void *aContext
)
```
Set UDP forward callback to deliver UDP packets to host.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] aForwarder` | A pointer to a function called to forward UDP packet to host. | | `[in] aContext` | A pointer to application-specific context. | |

### otUdpIsPortInUse

```
bool otUdpIsPortInUse(
  otInstance *aInstance,
  uint16_t port
)
```
Determines if the given UDP port is exclusively opened by OpenThread API.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | A pointer to an OpenThread instance. | | `[in] port` | UDP port number to verify. | |
| Return Values | |---|---| | `true` | The port is being used exclusively by OpenThread. | | `false` | The port is not used by any of the OpenThread API or is shared (e.g. is Backbone socket). | |

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).