00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __LWIP_UDP_H__
00033 #define __LWIP_UDP_H__
00034
00035 #include "lwip/opt.h"
00036
00037 #if LWIP_UDP
00038
00039 #include "lwip/pbuf.h"
00040 #include "lwip/netif.h"
00041 #include "lwip/ip_addr.h"
00042 #include "lwip/ip.h"
00043
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047
00048 #define UDP_HLEN 8
00049
00050
00051 #ifdef PACK_STRUCT_USE_INCLUDES
00052 # include "arch/bpstruct.h"
00053 #endif
00054 PACK_STRUCT_BEGIN
00055 struct udp_hdr {
00056 PACK_STRUCT_FIELD(u16_t src);
00057 PACK_STRUCT_FIELD(u16_t dest);
00058 PACK_STRUCT_FIELD(u16_t len);
00059 PACK_STRUCT_FIELD(u16_t chksum);
00060 } PACK_STRUCT_STRUCT;
00061 PACK_STRUCT_END
00062 #ifdef PACK_STRUCT_USE_INCLUDES
00063 # include "arch/epstruct.h"
00064 #endif
00065
00066 #define UDP_FLAGS_NOCHKSUM 0x01U
00067 #define UDP_FLAGS_UDPLITE 0x02U
00068 #define UDP_FLAGS_CONNECTED 0x04U
00069 #define UDP_FLAGS_MULTICAST_LOOP 0x08U
00070
00071 struct udp_pcb;
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 typedef void (*udp_recv_fn)(void *arg, struct udp_pcb *pcb, struct pbuf *p,
00088 ip_addr_t *addr, u16_t port);
00089
00090
00091 struct udp_pcb {
00092
00093 IP_PCB;
00094
00095
00096
00097 struct udp_pcb *next;
00098
00099 u8_t flags;
00100
00101 u16_t local_port, remote_port;
00102
00103 #if LWIP_IGMP
00104
00105 ip_addr_t multicast_ip;
00106 #endif
00107
00108 #if LWIP_UDPLITE
00109
00110 u16_t chksum_len_rx, chksum_len_tx;
00111 #endif
00112
00113
00114 udp_recv_fn recv;
00115
00116 void *recv_arg;
00117 };
00118
00119 extern struct udp_pcb *udp_pcbs;
00120
00121
00122
00123 struct udp_pcb * udp_new (void);
00124 void udp_remove (struct udp_pcb *pcb);
00125 err_t udp_bind (struct udp_pcb *pcb, ip_addr_t *ipaddr,
00126 u16_t port);
00127 err_t udp_connect (struct udp_pcb *pcb, ip_addr_t *ipaddr,
00128 u16_t port);
00129 void udp_disconnect (struct udp_pcb *pcb);
00130 void udp_recv (struct udp_pcb *pcb, udp_recv_fn recv,
00131 void *recv_arg);
00132 err_t udp_sendto_if (struct udp_pcb *pcb, struct pbuf *p,
00133 ip_addr_t *dst_ip, u16_t dst_port,
00134 struct netif *netif);
00135 err_t udp_sendto (struct udp_pcb *pcb, struct pbuf *p,
00136 ip_addr_t *dst_ip, u16_t dst_port);
00137 err_t udp_send (struct udp_pcb *pcb, struct pbuf *p);
00138
00139 #if LWIP_CHECKSUM_ON_COPY
00140 err_t udp_sendto_if_chksum(struct udp_pcb *pcb, struct pbuf *p,
00141 ip_addr_t *dst_ip, u16_t dst_port,
00142 struct netif *netif, u8_t have_chksum,
00143 u16_t chksum);
00144 err_t udp_sendto_chksum(struct udp_pcb *pcb, struct pbuf *p,
00145 ip_addr_t *dst_ip, u16_t dst_port,
00146 u8_t have_chksum, u16_t chksum);
00147 err_t udp_send_chksum(struct udp_pcb *pcb, struct pbuf *p,
00148 u8_t have_chksum, u16_t chksum);
00149 #endif
00150
00151 #define udp_flags(pcb) ((pcb)->flags)
00152 #define udp_setflags(pcb, f) ((pcb)->flags = (f))
00153
00154
00155 void udp_input (struct pbuf *p, struct netif *inp);
00156
00157 void udp_init (void);
00158
00159 #if UDP_DEBUG
00160 void udp_debug_print(struct udp_hdr *udphdr);
00161 #else
00162 #define udp_debug_print(udphdr)
00163 #endif
00164
00165 #ifdef __cplusplus
00166 }
00167 #endif
00168
00169 #endif
00170
00171 #endif