| 22 | #define UDP_ECHO_PORT 7 |
| 23 | rt_thread_t udpecho_tid = RT_NULL; |
| 24 | void udpecho_entry(void *parameter) |
| 25 | { |
| 26 | struct netconn *conn; |
| 27 | struct netbuf *buf; |
| 28 | struct ip_addr *addr; |
| 29 | unsigned short port; |
| 30 | |
| 31 | conn = netconn_new(NETCONN_UDP); |
| 32 | if(conn == NULL) |
| 33 | { |
| 34 | rt_kprintf("no memory error\n"); |
| 35 | return; |
| 36 | } |
| 37 | netconn_bind(conn, IP_ADDR_ANY, 7); |
| 38 | |
| 39 | while(1) |
| 40 | { |
| 41 | /* received data to buffer */ |
| 42 | #if LWIP_VERSION_MINOR==3U |
| 43 | buf = netconn_recv(conn); |
| 44 | #else |
| 45 | netconn_recv(conn, &buf); |
| 46 | #endif |
| 47 | if(buf == NULL) |
| 48 | { |
| 49 | break; |
| 50 | } |
| 51 | addr = netbuf_fromaddr(buf); |
| 52 | port = netbuf_fromport(buf); |
| 53 | |
| 54 | /* send the data to buffer */ |
| 55 | netconn_connect(conn, addr, port); |
| 56 | |
| 57 | /* reset address, and send to client */ |
| 58 | #if LWIP_VERSION_MINOR==3U |
| 59 | buf->addr = RT_NULL; |
| 60 | #else |
| 61 | buf->addr = *IP_ADDR_ANY; |
| 62 | #endif |
| 63 | |
| 64 | netconn_send(conn, buf); |
| 65 | |
| 66 | /* release buffer */ |
| 67 | netbuf_delete(buf); |
| 68 | } |
| 69 | |
| 70 | netconn_delete(conn); |
| 71 | } |
| 72 | /* |
| 73 | * UDP socket echo server |
| 74 | */ |
nothing calls this directly
no test coverage detected