test_sockets.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (C) 2014 Mamadou DIOP.
  2. *
  3. * This file is part of Open Source Doubango Framework.
  4. *
  5. * DOUBANGO is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * DOUBANGO is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with DOUBANGO.
  17. *
  18. */
  19. #ifndef TNET_TEST_SOCKETS_H
  20. #define TNET_TEST_SOCKETS_H
  21. void test_sockets()
  22. {
  23. int test;
  24. tnet_socket_tcp_t * tcp_socket;
  25. tnet_socket_type_t type = tnet_socket_type_udp_ipv4;
  26. struct sockaddr_storage to;
  27. TNET_SOCKET_TYPE_SET_IPV4(type);
  28. TNET_SOCKET_TYPE_SET_IPV6(type);
  29. TNET_SOCKET_TYPE_SET_IPV4Only(type);
  30. TNET_SOCKET_TYPE_SET_IPV6Only(type);
  31. TNET_SOCKET_TYPE_SET_IPV6Only(type);
  32. TNET_SOCKET_TYPE_SET_IPV4(type);
  33. TNET_SOCKET_TYPE_SET_IPV6(type);
  34. TNET_SOCKET_TYPE_SET_TLS(type);
  35. TNET_SOCKET_TYPE_SET_UDP(type);
  36. TNET_SOCKET_TYPE_SET_SCTP(type);
  37. TNET_SOCKET_TYPE_SET_TCP(type);
  38. tcp_socket = tnet_socket_create(TNET_SOCKET_HOST_ANY, TNET_SOCKET_PORT_ANY, type);
  39. if(!TNET_SOCKET_IS_VALID(tcp_socket)) {
  40. TSK_OBJECT_SAFE_FREE(tcp_socket);
  41. return;
  42. }
  43. //if(!(test = tnet_sockaddr_init("www.google.com", 80, type, &to))){
  44. // test = tnet_sockfd_connetto(tcp_socket->fd, (const struct sockaddr_storage *)&to);
  45. //}
  46. if(!(test = tnet_sockaddr_init("ipv6.google.com", 80, type, &to))) {
  47. test = tnet_sockfd_connectto(tcp_socket->fd, (const struct sockaddr_storage *)&to);
  48. }
  49. TSK_OBJECT_SAFE_FREE(tcp_socket);
  50. }
  51. #endif /* TNET_TEST_SOCKETS_H */