test_dhcp.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_DHCP_H
  20. #define TNET_TEST_DHCP_H
  21. void test_dhcp_discover(tnet_dhcp_ctx_t *ctx)
  22. {
  23. }
  24. void test_dhcp_offer(tnet_dhcp_ctx_t *ctx)
  25. {
  26. }
  27. void test_dhcp_request(tnet_dhcp_ctx_t *ctx)
  28. {
  29. }
  30. void test_dhcp_inform(tnet_dhcp_ctx_t *ctx)
  31. {
  32. tnet_dhcp_params_t *params = tsk_null;
  33. tnet_dhcp_reply_t *reply = tsk_null;
  34. params = tnet_dhcp_params_create();
  35. tnet_dhcp_params_add_code(params, dhcp_code_SIP_Servers_DHCP_Option); /* SIP Servers */
  36. tnet_dhcp_params_add_code(params, dhcp_code_Domain_Server); /* DNS Server */
  37. reply = tnet_dhcp_query_inform(ctx, params);
  38. if(reply && !TNET_DHCP_MESSAGE_IS_REPLY(reply)) {
  39. TSK_DEBUG_ERROR("DHCP request is not expected in response to a request.");
  40. goto bail;
  41. }
  42. if(reply) {
  43. switch(reply->type) {
  44. case dhcp_type_ack: {
  45. tsk_list_item_t *item;
  46. TSK_DEBUG_INFO("DHCP response type ==> ACK.");
  47. tsk_list_foreach(item, reply->options) {
  48. const tnet_dhcp_option_t *option = item->data;
  49. /* SIP SERVERS */
  50. if(option->code == dhcp_code_SIP_Servers_DHCP_Option) {
  51. tsk_list_item_t *item2;
  52. const tnet_dhcp_option_sip_t *option_sip4 = (const tnet_dhcp_option_sip_t*)option;;
  53. tsk_list_foreach(item2, option_sip4->servers) {
  54. const tsk_string_t *str = item2->data;
  55. TSK_DEBUG_INFO("DHCP-SIP_SERVER ==>%s", str->value);
  56. }
  57. }
  58. /* DNS SERVERS */
  59. if(option->code == dhcp_code_Domain_Server) {
  60. tsk_list_item_t *item2;
  61. const tnet_dhcp_option_dns_t *option_dns = (const tnet_dhcp_option_dns_t*)option;;
  62. tsk_list_foreach(item2, option_dns->servers) {
  63. const tsk_string_t *str = item2->data;
  64. TSK_DEBUG_INFO("DHCP-DNS_SERVER ==>%s", str->value);
  65. }
  66. }
  67. }
  68. break;
  69. }
  70. default: {
  71. break;
  72. }
  73. }
  74. }
  75. else {
  76. TSK_DEBUG_ERROR("DHCP reply is NULL.");
  77. goto bail;
  78. }
  79. bail:
  80. TSK_OBJECT_SAFE_FREE(reply);
  81. TSK_OBJECT_SAFE_FREE(params);
  82. //tsk_thread_sleep(1000);
  83. }
  84. void test_dhcp()
  85. {
  86. tnet_dhcp_ctx_t *ctx = tnet_dhcp_ctx_create();
  87. test_dhcp_inform(ctx);
  88. TSK_OBJECT_SAFE_FREE(ctx);
  89. }
  90. #endif /* TNET_TEST_DHCP_H */