Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
udp.h File Reference
UDP API (to be used from TCPIP thread)
See also UDP.
More...
Go to the source code of this file.
Data Structures | |
struct | udp_pcb |
the UDP protocol control block More... | |
Typedefs | |
typedef void(* | udp_recv_fn )(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) |
Function prototype for udp pcb receive callback functions addr and port are in same byte order as in the pcb The callback is responsible for freeing the pbuf if it's not used any more. | |
Functions | |
struct udp_pcb * | udp_new (void) |
Create a UDP PCB. | |
struct udp_pcb * | udp_new_ip_type (u8_t type) |
Create a UDP PCB for specific IP type. | |
void | udp_remove (struct udp_pcb *pcb) |
Remove an UDP PCB. | |
err_t | udp_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) |
Bind an UDP PCB. | |
err_t | udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) |
Connect an UDP PCB. | |
void | udp_disconnect (struct udp_pcb *pcb) |
Disconnect a UDP PCB. | |
void | udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg) |
Set a receive callback for a UDP PCB. | |
err_t | udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif) |
Send data to a specified address using UDP. | |
err_t | udp_sendto_if_src (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, const ip_addr_t *src_ip) |
Same as udp_sendto_if, but with source address. | |
err_t | udp_sendto (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port) |
Send data to a specified address using UDP. | |
err_t | udp_send (struct udp_pcb *pcb, struct pbuf *p) |
Send data using UDP. | |
err_t | udp_sendto_if_chksum (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, u8_t have_chksum, u16_t chksum) |
Same as udp_sendto_if(), but with checksum. | |
err_t | udp_sendto_chksum (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port, u8_t have_chksum, u16_t chksum) |
Same as udp_sendto(), but with checksum. | |
err_t | udp_send_chksum (struct udp_pcb *pcb, struct pbuf *p, u8_t have_chksum, u16_t chksum) |
Same as udp_send() but with checksum. | |
err_t | udp_sendto_if_src_chksum (struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif, u8_t have_chksum, u16_t chksum, const ip_addr_t *src_ip) |
Same as udp_sendto_if_src(), but with checksum. | |
void | udp_input (struct pbuf *p, struct netif *inp) |
Process an incoming UDP datagram. | |
void | udp_init (void) |
Initialize this module. | |
void | udp_debug_print (struct udp_hdr *udphdr) |
Print UDP header information for debug purposes. | |
void | udp_netif_ipv4_addr_changed (const ip4_addr_t *old_addr, const ip4_addr_t *new_addr) |
This function is called from netif.c when address is changed. |
Detailed Description
UDP API (to be used from TCPIP thread)
See also UDP.
Definition in file FEATURE_LWIP/lwip-interface/lwip/src/include/lwip/udp.h.
Typedef Documentation
typedef void(* udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port) |
Function prototype for udp pcb receive callback functions addr and port are in same byte order as in the pcb The callback is responsible for freeing the pbuf if it's not used any more.
ATTENTION: Be aware that 'addr' might point into the pbuf 'p' so freeing this pbuf can make 'addr' invalid, too.
- Parameters:
-
arg user supplied argument (udp_pcb.recv_arg) pcb the udp_pcb which received data p the packet buffer that was received addr the remote IP address from which the packet was received port the remote port from which the packet was received
Definition at line 94 of file FEATURE_LWIP/lwip-interface/lwip/src/include/lwip/udp.h.
Function Documentation
void udp_debug_print | ( | struct udp_hdr * | udphdr ) |
Print UDP header information for debug purposes.
- Parameters:
-
udphdr pointer to the udp header in memory.
Definition at line 1210 of file lwip_udp.c.
void udp_init | ( | void | ) |
Initialize this module.
Definition at line 95 of file lwip_udp.c.
Process an incoming UDP datagram.
Given an incoming UDP datagram (as a chain of pbufs) this function finds a corresponding UDP PCB and hands over the pbuf to the pcbs recv function. If no pcb is found or the datagram is incorrect, the pbuf is freed.
- Parameters:
-
p pbuf to be demultiplexed to a UDP PCB (p->payload pointing to the UDP header) inp network interface on which the datagram was received.
Given an incoming UDP datagram (as a chain of pbufs) this function finds a corresponding UDP PCB and hands over the pbuf to the pcbs recv function. If no pcb is found or the datagram is incorrect, the pbuf is freed.
- Parameters:
-
p pbuf to be demultiplexed to a UDP PCB. inp network interface on which the datagram was received.
Send data using UDP.
- Parameters:
-
pcb UDP PCB used to send the data. p chain of pbuf's to be sent.
The datagram will be sent to the current remote_ip & remote_port stored in pcb. If the pcb is not bound to a port, it will automatically be bound to a random port.
- Returns:
- lwIP error code.
- ERR_OK. Successful. No error occured.
- ERR_MEM. Out of memory.
- ERR_RTE. Could not find route to destination address.
- More errors could be returned by lower protocol layers.
- See also:
- udp_disconnect() udp_sendto()
Same as udp_send() but with checksum
Send data to a specified address using UDP.
- Parameters:
-
pcb UDP PCB used to send the data. p chain of pbuf's to be sent. dst_ip Destination IP address. dst_port Destination UDP port.
dst_ip & dst_port are expected to be in the same byte order as in the pcb.
If the PCB already has a remote address association, it will be restored after the data is sent.
- Returns:
- lwIP error code (
- See also:
- udp_send for possible error codes)
- udp_disconnect() udp_send()
Same as udp_sendto(), but with checksum
Send data to a specified address using UDP. The netif used for sending can be specified.
This function exists mainly for DHCP, to be able to send UDP packets on a netif that is still down.
- Parameters:
-
pcb UDP PCB used to send the data. p chain of pbuf's to be sent. dst_ip Destination IP address. dst_port Destination UDP port. netif the netif used for sending.
dst_ip & dst_port are expected to be in the same byte order as in the pcb.
- Returns:
- lwIP error code (
- See also:
- udp_send for possible error codes)
- udp_disconnect() udp_send()
Same as udp_sendto_if(), but with checksum
Bind an UDP PCB.
- Parameters:
-
pcb UDP PCB to be bound with a local address ipaddr and port. ipaddr local IP address to bind with. Use IP_ADDR_ANY to bind to all local interfaces. port local UDP port to bind with. Use 0 to automatically bind to a random port between UDP_LOCAL_PORT_RANGE_START and UDP_LOCAL_PORT_RANGE_END.
ipaddr & port are expected to be in the same byte order as in the pcb.
- Returns:
- lwIP error code.
- ERR_OK. Successful. No error occured.
- ERR_USE. The specified ipaddr and port are already bound to by another UDP PCB.
- See also:
- udp_disconnect()
Connect an UDP PCB.
This will associate the UDP PCB with the remote address.
- Parameters:
-
pcb UDP PCB to be connected with remote address ipaddr and port. ipaddr remote IP address to connect with. port remote UDP port to connect with.
- Returns:
- lwIP error code
ipaddr & port are expected to be in the same byte order as in the pcb.
The udp pcb is bound to a random local port if not already bound.
- See also:
- udp_disconnect()
TODO: this functionality belongs in upper layers
TODO: this will bind the udp pcb locally, to the interface which is used to route output packets to the remote address. However, we might want to accept incoming packets on any interface!
Disconnect a UDP PCB
- Parameters:
-
pcb the udp pcb to disconnect.
Set a receive callback for a UDP PCB
This callback will be called when receiving a datagram for the pcb.
- Parameters:
-
pcb the pcb for wich to set the recv callback recv function pointer of the callback function recv_arg additional argument to pass to the callback function
Remove an UDP PCB.
- Parameters:
-
pcb UDP PCB to be removed. The PCB is removed from the list of UDP PCB's and the data structure is freed from memory.
- See also:
- udp_new()
Create a UDP PCB.
- Returns:
- The UDP PCB which was created. NULL if the PCB data structure could not be allocated.
- See also:
- udp_remove()
Print UDP header information for debug purposes.
- Parameters:
-
udphdr pointer to the udp header in memory.
Definition at line 218 of file lwip_udp.c.
void udp_netif_ipv4_addr_changed | ( | const ip4_addr_t * | old_addr, |
const ip4_addr_t * | new_addr | ||
) |
This function is called from netif.c when address is changed.
- Parameters:
-
old_addr IPv4 address of the netif before change new_addr IPv4 address of the netif after change
Definition at line 1182 of file lwip_udp.c.
err_t udp_sendto_if_chksum | ( | struct udp_pcb * | pcb, |
struct pbuf * | p, | ||
const ip_addr_t * | dst_ip, | ||
u16_t | dst_port, | ||
struct netif * | netif, | ||
u8_t | have_chksum, | ||
u16_t | chksum | ||
) |
Same as udp_sendto_if(), but with checksum.
Definition at line 629 of file lwip_udp.c.
err_t udp_sendto_if_src_chksum | ( | struct udp_pcb * | pcb, |
struct pbuf * | p, | ||
const ip_addr_t * | dst_ip, | ||
u16_t | dst_port, | ||
struct netif * | netif, | ||
u8_t | have_chksum, | ||
u16_t | chksum, | ||
const ip_addr_t * | src_ip | ||
) |
Same as udp_sendto_if_src(), but with checksum.
Definition at line 698 of file lwip_udp.c.
Generated on Tue Jul 12 2022 17:35:05 by
