test_ifaces.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_IFACES_H
  20. #define TNET_TEST_IFACES_H
  21. void test_faces_bestsource()
  22. {
  23. tnet_ip_t source;
  24. // IPv6
  25. if(!tnet_getbestsource("fe80::fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)) {
  26. TSK_DEBUG_INFO("Best IPv6 source is [%s]", source);
  27. }
  28. else {
  29. TSK_DEBUG_ERROR("Failed to get best IPv6 source.");
  30. }
  31. // IPv6
  32. if(!tnet_getbestsource("2a01:e35:8b32:7050:212:f0ff:fe4c:3ea1", 5060, tnet_socket_type_udp_ipv6, &source)) {
  33. TSK_DEBUG_INFO("Best IPv6 source is [%s]", source);
  34. }
  35. else {
  36. TSK_DEBUG_ERROR("Failed to get best IPv6 source.");
  37. }
  38. // IPv4
  39. if(!tnet_getbestsource("192.168.0.11", 5060, tnet_socket_type_udp_ipv4, &source)) {
  40. TSK_DEBUG_INFO("Best IPv4 source is [%s]", source);
  41. }
  42. else {
  43. TSK_DEBUG_ERROR("Failed to get best IPv4 source.");
  44. }
  45. }
  46. void test_ifaces_dump_ifaces()
  47. {
  48. tnet_interfaces_L_t* ifaces = tnet_get_interfaces();
  49. tsk_list_item_t *item;
  50. tsk_list_foreach(item, ifaces) {
  51. const tnet_interface_t *iface = item->data;
  52. TSK_DEBUG_INFO("Interface: %s", iface->description);
  53. }
  54. TSK_OBJECT_SAFE_FREE(ifaces);
  55. }
  56. void test_ifaces_dump_addresses()
  57. {
  58. tnet_addresses_L_t* addresses = tnet_get_addresses_all();
  59. tsk_list_item_t *item;
  60. tsk_list_foreach(item, addresses) {
  61. const tnet_address_t *address = item->data;
  62. if(address->anycast) {
  63. TSK_DEBUG_INFO("ANYCAST address: %s", address->ip);
  64. }
  65. else if(address->unicast) {
  66. TSK_DEBUG_INFO("UNICAST address: %s", address->ip);
  67. }
  68. else if(address->multicast) {
  69. TSK_DEBUG_INFO("MULTICAST address: %s", address->ip);
  70. }
  71. else if(address->dnsserver) {
  72. TSK_DEBUG_INFO("DNSSERVER address: %s", address->ip);
  73. }
  74. }
  75. TSK_OBJECT_SAFE_FREE(addresses);
  76. }
  77. void test_ifaces()
  78. {
  79. test_faces_bestsource();
  80. test_ifaces_dump_ifaces();
  81. test_ifaces_dump_addresses();
  82. }
  83. #endif /* TNET_TEST_IFACES_H */