73 struct udp_pcb *udp_pcbs;
88 udp_input(
struct pbuf *p,
struct netif *inp)
90 struct udp_hdr *udphdr;
91 struct udp_pcb *pcb, *prev;
92 struct udp_pcb *uncon_pcb;
109 (
"udp_input: short UDP datagram (%"U16_F" bytes) discarded\n", p->
tot_len));
117 udphdr = (
struct udp_hdr *)p->
payload;
125 src =
ntohs(udphdr->src);
126 dest =
ntohs(udphdr->dest);
128 udp_debug_print(udphdr);
143 if (dest == DHCP_CLIENT_PORT) {
145 if (src == DHCP_SERVER_PORT) {
146 if ((inp->dhcp !=
NULL) && (inp->dhcp->pcb !=
NULL)) {
152 pcb = inp->dhcp->pcb;
155 }
else if (dest == DHCP_SERVER_PORT) {
156 if (src == DHCP_CLIENT_PORT) {
157 if ( inp->dhcps_pcb !=
NULL ) {
160 pcb = inp->dhcps_pcb;
175 for (pcb = udp_pcbs; pcb !=
NULL; pcb = pcb->next) {
179 (
"pcb (%"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
", %"U16_F
") --- " 180 "(%"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
", %"U16_F
")\n",
187 if ((pcb->local_port == dest) &&
199 if ((uncon_pcb ==
NULL) &&
200 ((pcb->flags & UDP_FLAGS_CONNECTED) == 0)) {
206 if ((local_match != 0) &&
207 (pcb->remote_port == src) &&
214 prev->next = pcb->next;
215 pcb->next = udp_pcbs;
236 #if CHECKSUM_CHECK_UDP 238 if (chklen <
sizeof(
struct udp_hdr)) {
256 (
"udp_input: UDP Lite datagram discarded due to failing checksum\n"));
267 #if CHECKSUM_CHECK_UDP 268 if (udphdr->chksum != 0) {
272 (
"udp_input: UDP datagram discarded due to failing checksum\n"));
292 #if SO_REUSE && SO_REUSE_RXTOALL 297 struct udp_pcb *mpcb;
298 u8_t p_header_changed = 0;
299 for (mpcb = udp_pcbs; mpcb !=
NULL; mpcb = mpcb->next) {
302 if ((mpcb->local_port == dest) &&
314 if (mpcb->recv !=
NULL) {
317 if (p_header_changed == 0) {
319 p_header_changed = 1;
334 if (p_header_changed) {
341 if (pcb->recv !=
NULL) {
394 udp_send(
struct udp_pcb *pcb,
struct pbuf *p)
397 return udp_sendto(pcb, p, &pcb->remote_ip, pcb->remote_port);
400 #if LWIP_CHECKSUM_ON_COPY 404 udp_send_chksum(
struct udp_pcb *pcb,
struct pbuf *p,
408 return udp_sendto_chksum(pcb, p, &pcb->remote_ip, pcb->remote_port,
409 have_chksum, chksum);
431 udp_sendto(
struct udp_pcb *pcb,
struct pbuf *p,
434 #if LWIP_CHECKSUM_ON_COPY 435 return udp_sendto_chksum(pcb, p, dst_ip, dst_port, 0, 0);
440 udp_sendto_chksum(
struct udp_pcb *pcb,
struct pbuf *p,
ip_addr_t *dst_ip,
462 #if LWIP_CHECKSUM_ON_COPY 463 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, have_chksum, chksum);
465 return udp_sendto_if(pcb, p, dst_ip, dst_port, netif);
489 udp_sendto_if(
struct udp_pcb *pcb,
struct pbuf *p,
492 #if LWIP_CHECKSUM_ON_COPY 493 return udp_sendto_if_chksum(pcb, p, dst_ip, dst_port, netif, 0, 0);
498 udp_sendto_if_chksum(
struct udp_pcb *pcb,
struct pbuf *p,
ip_addr_t *dst_ip,
499 u16_t dst_port,
struct netif *netif,
u8_t have_chksum,
503 struct udp_hdr *udphdr;
512 (
"udp_sendto_if: SOF_BROADCAST not enabled on pcb %p\n", (
void *)pcb));
518 if (pcb->local_port == 0) {
520 err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
542 (
"udp_send: added header pbuf %p before given pbuf %p\n", (
void *)q, (
void *)p));
549 LWIP_ASSERT(
"check that first pbuf can hold struct udp_hdr",
550 (q->
len >=
sizeof(
struct udp_hdr)));
552 udphdr = (
struct udp_hdr *)q->
payload;
553 udphdr->src =
htons(pcb->local_port);
554 udphdr->dest =
htons(dst_port);
556 udphdr->chksum = 0x0000;
584 src_ip = &(pcb->local_ip);
591 if (pcb->flags & UDP_FLAGS_UDPLITE) {
592 u16_t chklen, chklen_hdr;
595 chklen_hdr = chklen = pcb->chksum_len_tx;
596 if ((chklen <
sizeof(
struct udp_hdr)) || (chklen > q->
tot_len)) {
609 udphdr->len =
htons(chklen_hdr);
617 (have_chksum ? UDP_HLEN : chklen));
620 acc = udphdr->chksum + (
u16_t)~(chksum);
626 if (udphdr->chksum == 0x0000) {
627 udphdr->chksum = 0xffff;
632 #if LWIP_NETIF_HWADDRHINT 633 netif->addr_hint = &(pcb->addr_hint);
636 #if LWIP_NETIF_HWADDRHINT 637 netif->addr_hint =
NULL;
646 if ((pcb->flags & UDP_FLAGS_NOCHKSUM) == 0) {
648 #if LWIP_CHECKSUM_ON_COPY 653 acc = udpchksum + (
u16_t)~(chksum);
662 if (udpchksum == 0x0000) {
665 udphdr->chksum = udpchksum;
671 #if LWIP_NETIF_HWADDRHINT 672 netif->addr_hint = &(pcb->addr_hint);
675 #if LWIP_NETIF_HWADDRHINT 676 netif->addr_hint =
NULL;
716 struct udp_pcb *ipcb;
725 for (ipcb = udp_pcbs; ipcb !=
NULL; ipcb = ipcb->next) {
744 if ((ipcb->local_port == port) &&
751 (
"udp_bind: local port %"U16_F
" already bound by another pcb\n", port));
761 #ifndef UDP_LOCAL_PORT_RANGE_START 762 #define UDP_LOCAL_PORT_RANGE_START 4096 763 #define UDP_LOCAL_PORT_RANGE_END 0x7fff 765 port = UDP_LOCAL_PORT_RANGE_START;
767 while ((ipcb !=
NULL) && (port != UDP_LOCAL_PORT_RANGE_END)) {
768 if (ipcb->local_port == port) {
784 pcb->local_port = port;
789 pcb->next = udp_pcbs;
793 (
"udp_bind: bound to %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
", port %"U16_F
"\n",
819 struct udp_pcb *ipcb;
821 if (pcb->local_port == 0) {
822 err_t err = udp_bind(pcb, &pcb->local_ip, pcb->local_port);
829 pcb->remote_port = port;
830 pcb->flags |= UDP_FLAGS_CONNECTED;
845 pcb->local_ip = netif->
ip_addr;
847 pcb->local_ip.addr = 0;
851 (
"udp_connect: connected to %"U16_F
".%"U16_F
".%"U16_F
".%"U16_F
",port %"U16_F
"\n",
857 for (ipcb = udp_pcbs; ipcb !=
NULL; ipcb = ipcb->next) {
864 pcb->next = udp_pcbs;
875 udp_disconnect(
struct udp_pcb *pcb)
879 pcb->remote_port = 0;
881 pcb->flags &= ~UDP_FLAGS_CONNECTED;
894 udp_recv(
struct udp_pcb *pcb, udp_recv_fn recv,
void *recv_arg)
898 pcb->recv_arg = recv_arg;
910 udp_remove(
struct udp_pcb *pcb)
912 struct udp_pcb *pcb2;
916 if (udp_pcbs == pcb) {
918 udp_pcbs = udp_pcbs->next;
921 for (pcb2 = udp_pcbs; pcb2 !=
NULL; pcb2 = pcb2->next) {
923 if (pcb2->next !=
NULL && pcb2->next == pcb) {
925 pcb2->next = pcb->next;
951 os_memset(pcb, 0,
sizeof(
struct udp_pcb));
964 udp_debug_print(
struct udp_hdr *udphdr)
#define ip4_addr3_16(ipaddr)
void memp_free(memp_t type, void *mem) ICACHE_FLASH_ATTR
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from) ICACHE_FLASH_ATTR
#define IP_SOF_BROADCAST_RECV
#define ip_current_src_addr()
#define ip_addr_set(dest, src)
#define snmp_inc_udpindatagrams()
ip_addr_t current_iphdr_dest
#define ip_addr_debug_print(debug, ipaddr)
const ip_addr_t ip_addr_any ICACHE_RODATA_ATTR
#define ICACHE_FLASH_ATTR
void * memp_malloc(memp_t type) ICACHE_FLASH_ATTR
#define ip_current_dest_addr()
struct netif * ip_route(ip_addr_t *dest) ICACHE_FLASH_ATTR
#define PBUF_FLAG_MCASTLOOP
#define snmp_inc_udpnoports()
#define LWIP_DEBUGF(debug, message)
#define ip_addr_cmp(addr1, addr2)
#define LWIP_DBG_LEVEL_SERIOUS
#define snmp_inc_udpoutdatagrams()
err_t ip_output_if(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t ttl, u8_t tos, u8_t proto, struct netif *netif) ICACHE_FLASH_ATTR
#define ip_addr_set_any(ipaddr)
typedefPACK_STRUCT_END struct ip_addr ip_addr_t
ip_addr_t current_iphdr_src
#define ip4_addr4_16(ipaddr)
void pbuf_chain(struct pbuf *head, struct pbuf *tail) ICACHE_FLASH_ATTR
#define ip_addr_isany(addr1)
u8_t pbuf_free(struct pbuf *p) ICACHE_FLASH_ATTR
u16_t inet_chksum_pseudo(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len) ICACHE_FLASH_ATTR
u16_t inet_chksum_pseudo_partial(struct pbuf *p, ip_addr_t *src, ip_addr_t *dest, u8_t proto, u16_t proto_len, u16_t chksum_len) ICACHE_FLASH_ATTR
#define ip_addr_isbroadcast(ipaddr, netif)
u8_t pbuf_header(struct pbuf *p, s16_t header_size) ICACHE_FLASH_ATTR
#define snmp_insert_udpidx_tree(pcb)
#define ip4_addr1_16(ipaddr)
#define LWIP_ASSERT(message, assertion)
#define LWIP_CHECKSUM_ON_COPY
#define snmp_delete_udpidx_tree(pcb)
#define ip4_addr2_16(ipaddr)
#define ip_addr_ismulticast(addr1)
#define snmp_inc_udpinerrors()
struct pbuf * pbuf_alloc(pbuf_layer l, u16_t length, pbuf_type type) ICACHE_FLASH_ATTR