dns_server.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program 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 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program 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 General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJLIB_UTIL_DNS_SERVER_H__
  20. #define __PJLIB_UTIL_DNS_SERVER_H__
  21. /**
  22. * @file dns_server.h
  23. * @brief Simple DNS server
  24. */
  25. #include <pjlib-util/types.h>
  26. #include <pjlib-util/dns.h>
  27. PJ_BEGIN_DECL
  28. /**
  29. * @defgroup PJ_DNS_SERVER Simple DNS Server
  30. * @ingroup PJ_DNS
  31. * @{
  32. * This contains a simple but fully working DNS server implementation,
  33. * mostly for testing purposes. It supports serving various DNS resource
  34. * records such as SRV, CNAME, A, and AAAA.
  35. */
  36. /**
  37. * Opaque structure to hold DNS server instance.
  38. */
  39. typedef struct pj_dns_server pj_dns_server;
  40. /**
  41. * Create the DNS server instance. The instance will run immediately.
  42. *
  43. * @param pf The pool factory to create memory pools.
  44. * @param ioqueue Ioqueue instance where the server socket will be
  45. * registered to.
  46. * @param af Address family of the server socket (valid values
  47. * are pj_AF_INET() for IPv4 and pj_AF_INET6() for IPv6).
  48. * @param port The UDP port to listen. Specify zero to bind to any
  49. * port.
  50. * @param flags Flags, currently must be zero.
  51. * @param p_srv Pointer to receive the DNS server instance.
  52. *
  53. * @return PJ_SUCCESS if server has been created successfully,
  54. * otherwise the function will return the appropriate
  55. * error code.
  56. */
  57. PJ_DECL(pj_status_t) pj_dns_server_create(pj_pool_factory *pf,
  58. pj_ioqueue_t *ioqueue,
  59. int af,
  60. unsigned port,
  61. unsigned flags,
  62. pj_dns_server **p_srv);
  63. /**
  64. * Get the DNS server address
  65. *
  66. * @param srv The DNS server instance.
  67. * @param addr It will be filled with the server's bound address.
  68. *
  69. * @return PJ_SUCCESS on success or the appropriate error code.
  70. */
  71. PJ_DECL(pj_status_t) pj_dns_server_get_addr(pj_dns_server *srv,
  72. pj_sockaddr *bound_addr);
  73. /**
  74. * Destroy DNS server instance.
  75. *
  76. * @param srv The DNS server instance.
  77. *
  78. * @return PJ_SUCCESS on success or the appropriate error code.
  79. */
  80. PJ_DECL(pj_status_t) pj_dns_server_destroy(pj_dns_server *srv);
  81. /**
  82. * Add generic resource record entries to the server.
  83. *
  84. * @param srv The DNS server instance.
  85. * @param count Number of records to be added.
  86. * @param rr Array of records to be added.
  87. *
  88. * @return PJ_SUCCESS on success or the appropriate error code.
  89. */
  90. PJ_DECL(pj_status_t) pj_dns_server_add_rec(pj_dns_server *srv,
  91. unsigned count,
  92. const pj_dns_parsed_rr rr[]);
  93. /**
  94. * Remove the specified record from the server.
  95. *
  96. * @param srv The DNS server instance.
  97. * @param dns_class The resource's DNS class. Valid value is PJ_DNS_CLASS_IN.
  98. * @param type The resource type.
  99. * @param name The resource name to be removed.
  100. *
  101. * @return PJ_SUCCESS on success or the appropriate error code.
  102. */
  103. PJ_DECL(pj_status_t) pj_dns_server_del_rec(pj_dns_server *srv,
  104. int dns_class,
  105. pj_dns_type type,
  106. const pj_str_t *name);
  107. /**
  108. * @}
  109. */
  110. PJ_END_DECL
  111. #endif /* __PJLIB_UTIL_DNS_SERVER_H__ */