A version of LWIP, provided for backwards compatibility.

Dependents:   AA_DemoBoard DemoBoard HelloServerDemo DemoBoard_RangeIndicator ... more

Embed: (wiki syntax)

« Back to documentation index

udp.c File Reference

udp.c File Reference

User Datagram Protocol module. More...

Go to the source code of this file.

Functions

void udp_input (struct pbuf *p, struct netif *inp)
 Process an incoming UDP datagram.
err_t udp_send (struct udp_pcb *pcb, struct pbuf *p)
 Send data using UDP.
err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port)
 Send data to a specified address using UDP.
err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *dst_ip, u16_t dst_port, struct netif *netif)
 Send data to a specified address using UDP.
err_t udp_bind (struct udp_pcb *pcb, struct ip_addr *ipaddr, u16_t port)
 Bind an UDP PCB.
err_t udp_connect (struct udp_pcb *pcb, struct ip_addr *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, void(*recv)(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port), void *recv_arg)
 Set a receive callback for a UDP PCB.
void udp_remove (struct udp_pcb *pcb)
 Remove an UDP PCB.
struct udp_pcb * udp_new (void)
 Create a UDP PCB.
void udp_debug_print (struct udp_hdr *udphdr)
 Print UDP header information for debug purposes.

Detailed Description

User Datagram Protocol module.

Definition in file tag/0.5/lwIP/core/udp.c.


Function Documentation

err_t udp_bind ( struct udp_pcb *  pcb,
struct ip_addr *  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_ADDR_ANY 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 occured.
  • ERR_USE. The specified ipaddr and port are already bound to by another UDP PCB.
See also:
udp_disconnect()

Definition at line 564 of file tag/0.5/lwIP/core/udp.c.

err_t udp_connect ( struct udp_pcb *  pcb,
struct ip_addr *  ipaddr,
u16_t  port 
)

Connect an UDP PCB.

This will associate the UDP PCB with the remote address.

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()

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!

Definition at line 664 of file tag/0.5/lwIP/core/udp.c.

void udp_debug_print ( struct udp_hdr *  udphdr )

Print UDP header information for debug purposes.

Parameters:
udphdrpointer to the udp header in memory.

Definition at line 813 of file tag/0.5/lwIP/core/udp.c.

void udp_disconnect ( struct udp_pcb *  pcb )

Disconnect a UDP PCB.

Parameters:
pcbthe udp pcb to disconnect.

Definition at line 722 of file tag/0.5/lwIP/core/udp.c.

void udp_input ( struct pbuf *  p,
struct netif inp 
)

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:
ppbuf to be demultiplexed to a UDP PCB.
inpnetwork interface on which the datagram was received.

Definition at line 85 of file tag/0.5/lwIP/core/udp.c.

struct udp_pcb* udp_new ( void   ) [read]

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()

Definition at line 790 of file tag/0.5/lwIP/core/udp.c.

void udp_recv ( struct udp_pcb *  pcb,
void(*)(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port)  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 wich to set the recv callback
recvfunction pointer of the callback function
recv_argadditional argument to pass to the callback function

Definition at line 741 of file tag/0.5/lwIP/core/udp.c.

void udp_remove ( struct udp_pcb *  pcb )

Remove an UDP 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 760 of file tag/0.5/lwIP/core/udp.c.

err_t udp_send ( struct udp_pcb *  pcb,
struct pbuf *  p 
)

Send data using UDP.

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 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()

Definition at line 330 of file tag/0.5/lwIP/core/udp.c.

err_t udp_sendto ( struct udp_pcb *  pcb,
struct pbuf *  p,
struct ip_addr *  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 354 of file tag/0.5/lwIP/core/udp.c.

err_t udp_sendto_if ( struct udp_pcb *  pcb,
struct pbuf *  p,
struct ip_addr *  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 397 of file tag/0.5/lwIP/core/udp.c.