Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

UDP

User Datagram Protocol module
. More...

Functions

err_t udp_send (struct udp_pcb *pcb, struct pbuf *p)
 Sends the pbuf p using UDP.
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 (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_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_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_bind (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
 Bind an UDP PCB.
void udp_bind_netif (struct udp_pcb *pcb, const struct netif *netif)
 Bind an UDP PCB to a specific netif.
err_t udp_connect (struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port)
 Sets the remote end of the pcb.
void udp_disconnect (struct udp_pcb *pcb)
 Remove the remote end of the pcb.
void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg)
 Set a receive callback for a UDP PCB.
void udp_remove (struct udp_pcb *pcb)
 Removes and deallocates the pcb.
struct udp_pcbudp_new (void)
 Creates a new UDP pcb which can be used for UDP communication.
struct udp_pcbudp_new_ip_type (u8_t type)
 Create a UDP PCB for specific IP type.

Detailed Description

User Datagram Protocol module
.

See also:
APIs

Function Documentation

err_t udp_bind ( struct udp_pcb pcb,
const ip_addr_t ipaddr,
u16_t  port 
)

Bind an UDP PCB.

Parameters:
pcbUDP PCB to be bound with a local address ipaddr and port.
ipaddrlocal IP address to bind with. Use IP_ANY_TYPE to bind to all local interfaces.
portlocal 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 occurred.
  • ERR_USE. The specified ipaddr and port are already bound to by another UDP PCB.
See also:
udp_disconnect()

Definition at line 932 of file lwip_udp.c.

void udp_bind_netif ( struct udp_pcb pcb,
const struct netif netif 
)

Bind an UDP PCB to a specific netif.

After calling this function, all packets received via this PCB are guaranteed to have come in via the specified netif, and all outgoing packets will go out via the specified netif.

Parameters:
pcbUDP PCB to be bound.
netifnetif to bind udp pcb to. Can be NULL.
See also:
udp_disconnect()

Definition at line 1042 of file lwip_udp.c.

err_t udp_connect ( struct udp_pcb pcb,
const ip_addr_t ipaddr,
u16_t  port 
)

Sets the remote end of the pcb.

This function does not generate any network traffic, but only sets the remote address of the pcb.

Parameters:
pcbUDP PCB to be connected with remote address ipaddr and port.
ipaddrremote IP address to connect with.
portremote 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()

Definition at line 1071 of file lwip_udp.c.

void udp_disconnect ( struct udp_pcb pcb )

Remove the remote end of the pcb.

This function does not generate any network traffic, but only removes the remote address of the pcb.

Parameters:
pcbthe udp pcb to disconnect.

Definition at line 1126 of file lwip_udp.c.

struct udp_pcb* udp_new ( void   ) [read]

Creates a new UDP pcb which can be used for UDP communication.

The pcb is not active until it has either been bound to a local address or connected to a remote address.

Returns:
The UDP PCB which was created. NULL if the PCB data structure could not be allocated.
See also:
udp_remove()

Definition at line 1218 of file lwip_udp.c.

struct udp_pcb* udp_new_ip_type ( u8_t  type ) [read]

Create a UDP PCB for specific IP type.

The pcb is not active until it has either been bound to a local address or connected to a remote address.

Parameters:
typeIP address type, see lwip_ip_addr_type definitions. If you want to listen to IPv4 and IPv6 (dual-stack) packets, supply IPADDR_TYPE_ANY as argument and bind to IP_ANY_TYPE.
Returns:
The UDP PCB which was created. NULL if the PCB data structure could not be allocated.
See also:
udp_remove()

Definition at line 1255 of file lwip_udp.c.

void udp_recv ( struct udp_pcb pcb,
udp_recv_fn  recv,
void *  recv_arg 
)

Set a receive callback for a UDP PCB.

This callback will be called when receiving a datagram for the pcb.

Parameters:
pcbthe pcb for which to set the recv callback
recvfunction pointer of the callback function
recv_argadditional argument to pass to the callback function

Definition at line 1158 of file lwip_udp.c.

void udp_remove ( struct udp_pcb pcb )

Removes and deallocates the pcb.

Parameters:
pcbUDP 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()

Definition at line 1179 of file lwip_udp.c.

err_t udp_send ( struct udp_pcb pcb,
struct pbuf p 
)

Sends the pbuf p using UDP.

The pbuf is not deallocated.

Parameters:
pcbUDP PCB used to send the data.
pchain 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 occurred.
  • ERR_MEM. Out of memory.
  • ERR_RTE. Could not find route to destination address.
  • ERR_VAL. No PCB or PCB is dual-stack
  • More errors could be returned by lower protocol layers.
See also:
udp_disconnect() udp_sendto()

Definition at line 467 of file lwip_udp.c.

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.

Definition at line 485 of file lwip_udp.c.

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.

Parameters:
pcbUDP PCB used to send the data.
pchain of pbuf's to be sent.
dst_ipDestination IP address.
dst_portDestination 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()

Definition at line 520 of file lwip_udp.c.

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.

Definition at line 530 of file lwip_udp.c.

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.

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:
pcbUDP PCB used to send the data.
pchain of pbuf's to be sent.
dst_ipDestination IP address.
dst_portDestination UDP port.
netifthe 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()

Definition at line 624 of file lwip_udp.c.

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.

Definition at line 699 of file lwip_udp.c.