/** * An UDP packet has been received. */ static void on_udp_recv(void *arg_p, struct udp_pcb *pcb_p, struct pbuf *pbuf_p, #if LWIP_VERSION_MINOR <= 4 ip_addr_t *addr_p, #else const ip_addr_t *addr_p, #endif uint16_t port) { struct socket_t *socket_p = arg_p; /* Discard the packet if there is already a packed waiting. */ if (socket_p->input.u.recvfrom.pbuf_p != NULL) { pbuf_free(pbuf_p); return; } /* Save the remote address and port. */ socket_p->input.u.recvfrom.remote_addr.ip.number = ip_addr_get_ip4_u32(addr_p); socket_p->input.u.recvfrom.remote_addr.ip.number = ip_addr_get_ip4_u32(addr_p); socket_p->input.u.recvfrom.remote_addr.port = port; /* Copy the data to the receive buffer if there is one. */ if (socket_p->input.cb.state == STATE_RECVFROM) { socket_p->input.cb.state = STATE_IDLE; socket_p->input.u.recvfrom.pbuf_p = NULL; socket_p->input.u.recvfrom.left = 0; udp_recv_from_copy_resume(socket_p, pbuf_p); } else { socket_p->input.u.recvfrom.pbuf_p = pbuf_p; socket_p->input.u.recvfrom.left = pbuf_p->tot_len; resume_if_polled(socket_p); } }
END_TEST /** Call tcp_new() and tcp_abort() and test memp stats */ START_TEST(test_tcp_listen_passive_open) { struct tcp_pcb *pcb, *pcbl; struct tcp_pcb_listen *lpcb; struct netif netif; struct test_tcp_txcounters txcounters; struct test_tcp_counters counters; struct pbuf *p; ip_addr_t src_addr; err_t err; LWIP_UNUSED_ARG(_i); fail_unless(MEMP_STATS_GET(used, MEMP_TCP_PCB) == 0); test_tcp_init_netif(&netif, &txcounters, &test_local_ip, &test_netmask); /* initialize counter struct */ memset(&counters, 0, sizeof(counters)); pcb = tcp_new(); EXPECT_RET(pcb != NULL); err = tcp_bind(pcb, &netif.ip_addr, 1234); EXPECT(err == ERR_OK); pcbl = tcp_listen(pcb); EXPECT_RET(pcbl != NULL); EXPECT_RET(pcbl != pcb); lpcb = (struct tcp_pcb_listen *)pcbl; ip_addr_set_ip4_u32_val(src_addr, lwip_htonl(lwip_ntohl(ip_addr_get_ip4_u32(&lpcb->local_ip)) + 1)); /* check correct syn packet */ p = tcp_create_segment(&src_addr, &lpcb->local_ip, 12345, lpcb->local_port, NULL, 0, 12345, 54321, TCP_SYN); EXPECT(p != NULL); if (p != NULL) { /* pass the segment to tcp_input */ test_tcp_input(p, &netif); /* check if counters are as expected */ EXPECT(txcounters.num_tx_calls == 1); } /* check syn packet with short length */ p = tcp_create_segment(&src_addr, &lpcb->local_ip, 12345, lpcb->local_port, NULL, 0, 12345, 54321, TCP_SYN); EXPECT(p != NULL); EXPECT(p->next == NULL); if ((p != NULL) && (p->next == NULL)) { p->len -= 2; p->tot_len -= 2; /* pass the segment to tcp_input */ test_tcp_input(p, &netif); /* check if counters are as expected */ EXPECT(txcounters.num_tx_calls == 1); } tcp_close(pcbl); }