udpecho6.c 657 B

1234567891011121314151617181920212223242526272829303132
  1. #include <rtthread.h>
  2. #include <finsh.h>
  3. #include <lwip/api.h>
  4. #define UDP_ECHO_PORT 10002
  5. void udpecho6(void)
  6. {
  7. struct netconn *conn, *newconn;
  8. struct netbuf *buf;
  9. struct ip6_addr *addr6;
  10. unsigned short port;
  11. err_t err;
  12. conn = netconn_new(NETCONN_UDP_IPV6);
  13. netconn_bind_ip6(conn, IP6_ADDR_ANY, UDP_ECHO_PORT);
  14. while(1)
  15. {
  16. netconn_recv(conn, &buf);
  17. addr6 = netbuf_fromaddr_ip6(buf);
  18. port = netbuf_fromport(buf);
  19. netconn_connect_ip6(conn, addr6, port);
  20. netconn_sendto_ip6(conn, buf, addr6, port);
  21. netbuf_delete(buf);
  22. }
  23. }
  24. #ifdef RT_USING_FINSH
  25. #include <finsh.h>
  26. FINSH_FUNCTION_EXPORT(udpecho6, startup udpecho via ipv6);
  27. #endif