#include "lwip/opt.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/ip_addr.h"
#include "lwip/ip.h"
Data Structures | |
struct | udp_hdr |
struct | udp_pcb |
Macros | |
#define | udp_debug_print(udphdr) |
#define | udp_flags(pcb) ((pcb)->flags) |
#define | UDP_FLAGS_CONNECTED 0x04U |
#define | UDP_FLAGS_MULTICAST_LOOP 0x08U |
#define | UDP_FLAGS_NOCHKSUM 0x01U |
#define | UDP_FLAGS_UDPLITE 0x02U |
#define | UDP_HLEN 8 |
#define | udp_init() /* Compatibility define, not init needed. */ |
#define | udp_setflags(pcb, f) ((pcb)->flags = (f)) |
Typedefs | |
typedef void(* | udp_recv_fn )(void *arg, struct udp_pcb *pcb, struct pbuf *p, 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. More... | |
Functions | |
err_t | udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port) |
Bind an UDP PCB. More... | |
err_t | udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr, u16_t port) |
Connect an UDP PCB. More... | |
void | udp_disconnect (struct udp_pcb *pcb) |
Disconnect a UDP PCB. More... | |
void | udp_input (struct pbuf *p, struct netif *inp) |
Process an incoming UDP datagram. More... | |
struct udp_pcb * | udp_new (void) |
Create a UDP PCB. More... | |
void | udp_recv (struct udp_pcb *pcb, udp_recv_fn recv, void *recv_arg) |
Set a receive callback for a UDP PCB. More... | |
void | udp_remove (struct udp_pcb *pcb) |
Remove an UDP PCB. More... | |
err_t | udp_send (struct udp_pcb *pcb, struct pbuf *p) |
Send data using UDP. More... | |
err_t | udp_sendto (struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, u16_t dst_port) |
Send data to a specified address using UDP. More... | |
err_t | udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *dst_ip, u16_t dst_port, struct netif *netif) |
Send data to a specified address using UDP. More... | |
Variables | |
PACK_STRUCT_BEGIN struct udp_hdr | PACK_STRUCT_STRUCT |
struct udp_pcb * | udp_pcbs |
#define udp_debug_print | ( | udphdr | ) |
Referenced by udp_input().
#define udp_flags | ( | pcb | ) | ((pcb)->flags) |
Referenced by lwip_getsockopt(), lwip_getsockopt_internal(), lwip_setsockopt(), and lwip_setsockopt_internal().
#define UDP_FLAGS_CONNECTED 0x04U |
Referenced by do_getaddr(), udp_connect(), udp_disconnect(), and udp_input().
#define UDP_FLAGS_MULTICAST_LOOP 0x08U |
Referenced by lwip_getsockopt_internal(), and lwip_setsockopt_internal().
#define UDP_FLAGS_NOCHKSUM 0x01U |
Referenced by lwip_getsockopt_internal(), lwip_setsockopt_internal(), and pcb_new().
#define UDP_FLAGS_UDPLITE 0x02U |
Referenced by lwip_getsockopt(), lwip_setsockopt(), and pcb_new().
#define UDP_HLEN 8 |
Referenced by udp_input().
#define udp_init | ( | ) | /* Compatibility define, not init needed. */ |
Referenced by lwip_init().
#define udp_setflags | ( | pcb, | |
f | |||
) | ((pcb)->flags = (f)) |
Referenced by lwip_setsockopt_internal(), and pcb_new().
typedef void(* udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p, 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' points into the pbuf 'p' so freeing this pbuf makes 'addr' invalid, too.
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 |
Bind an UDP PCB.
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.
References ERR_OK, ERR_USE, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, ip_addr_cmp, ip_addr_debug_print, ip_addr_isany, ip_addr_set, udp_pcb::local_port, LWIP_ASSERT, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, udp_pcb::next, NULL, snmp_insert_udpidx_tree, SOF_REUSEADDR, UDP_DEBUG, UDP_LOCAL_PORT_RANGE_END, UDP_LOCAL_PORT_RANGE_START, and udp_pcbs.
Referenced by dhcp_inform(), dhcp_start(), do_bind(), and udp_connect().
Connect an UDP PCB.
This will associate the UDP PCB with the remote address.
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. |
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.
TODO: this functionality belongs in upper layers
References ERR_OK, ERR_RTE, udp_pcb::flags, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_isany, ip_addr_set, ip_route(), udp_pcb::local_port, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, udp_pcb::next, NULL, udp_pcb::remote_port, udp_bind(), UDP_DEBUG, UDP_FLAGS_CONNECTED, udp_pcbs, and UDP_STATS_INC.
Referenced by dhcp_start(), and do_connect().
Disconnect a UDP PCB.
pcb | the udp pcb to disconnect. |
References udp_pcb::flags, ip_addr_set_any, udp_pcb::remote_port, and UDP_FLAGS_CONNECTED.
Referenced by do_disconnect().
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.
p | pbuf to be demultiplexed to a UDP PCB. |
inp | network interface on which the datagram was received. |
References current_iphdr_dest, current_iphdr_src, netif::dhcp, DHCP_CLIENT_PORT, DHCP_SERVER_PORT, ERR_OK, udp_pcb::flags, icmp_dest_unreach(), ICMP_DUR_PORT, if(), inet_chksum_pseudo(), inet_chksum_pseudo_partial(), ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, netif::ip_addr, ip_addr_cmp, ip_addr_isany, ip_addr_isbroadcast, ip_addr_ismulticast, ip_current_dest_addr, ip_current_src_addr, IP_PROTO_UDP, IP_PROTO_UDPLITE, IP_SOF_BROADCAST_RECV, IPH_HL, IPH_PROTO, iphdr, udp_pcb::local_port, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_IGMP, udp_pcb::next, ntohs, NULL, pbuf::payload, pbuf_alloc(), pbuf_copy(), pbuf_free(), pbuf_header(), PBUF_RAM, PBUF_RAW, dhcp::pcb, PERF_START, PERF_STOP, udp_pcb::recv, udp_pcb::recv_arg, udp_pcb::remote_port, snmp_inc_udpindatagrams, snmp_inc_udpinerrors, snmp_inc_udpnoports, SOF_BROADCAST, SOF_REUSEADDR, pbuf::tot_len, U16_F, UDP_DEBUG, udp_debug_print, UDP_FLAGS_CONNECTED, UDP_HLEN, udp_pcbs, and UDP_STATS_INC.
Referenced by ip_input().
Create a UDP PCB.
References memp_malloc(), NULL, and UDP_TTL.
Referenced by dhcp_inform(), dhcp_start(), and pcb_new().
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.
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 |
References udp_pcb::recv, recv, and udp_pcb::recv_arg.
Referenced by dhcp_start(), and pcb_new().
Remove an UDP PCB.
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. |
References memp_free(), udp_pcb::next, NULL, and snmp_delete_udpidx_tree.
Referenced by dhcp_inform(), dhcp_start(), dhcp_stop(), and do_delconn().
Send data using UDP.
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.
References udp_pcb::remote_port, and udp_sendto().
Referenced by do_send().
Send data to a specified address using UDP.
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.
Referenced by do_send(), lwip_sendto(), and udp_send().
err_t udp_sendto_if | ( | struct udp_pcb * | pcb, |
struct pbuf * | p, | ||
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.
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.
Referenced by dhcp_decline(), dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_release(), dhcp_renew(), and dhcp_select().
PACK_STRUCT_BEGIN struct udp_hdr PACK_STRUCT_STRUCT |
struct udp_pcb* udp_pcbs |
Referenced by udp_bind(), udp_connect(), and udp_input().