You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Copyright (c) 2014, Vsevolod Stakhov
  2. * All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY
  13. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  14. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  15. * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY
  16. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  18. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  19. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  21. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #ifndef UTIL_H_
  24. #define UTIL_H_
  25. #include "dns_private.h"
  26. /**
  27. * Make a universal socket
  28. * @param credits host, ip or path to unix socket
  29. * @param port port (used for network sockets)
  30. * @param type of socket (SOCK_STREAM or SOCK_DGRAM)
  31. */
  32. int
  33. rdns_make_client_socket (const char *credits,
  34. uint16_t port,
  35. int type,
  36. struct sockaddr **psockaddr,
  37. socklen_t *psocklen);
  38. /**
  39. * Generate new random DNS id
  40. * @return dns id
  41. */
  42. uint16_t rdns_permutor_generate_id (void);
  43. /**
  44. * Free IO channel
  45. */
  46. void rdns_ioc_free (struct rdns_io_channel *ioc);
  47. /**
  48. * Creates a new IO channel
  49. */
  50. struct rdns_io_channel * rdns_ioc_new (struct rdns_server *srv,
  51. struct rdns_resolver *resolver,
  52. bool is_tcp);
  53. /**
  54. * Resets inactive/errored TCP chain as recommended by RFC
  55. * @param ioc
  56. */
  57. void rdns_ioc_tcp_reset (struct rdns_io_channel *ioc);
  58. /**
  59. * Connect TCP IO channel to a server
  60. * @param ioc
  61. */
  62. bool rdns_ioc_tcp_connect (struct rdns_io_channel *ioc);
  63. /**
  64. * Free request
  65. * @param req
  66. */
  67. void rdns_request_free (struct rdns_request *req);
  68. /**
  69. * Removes request from a channel's hash (e.g. if needed to migrate to another channel)
  70. * @param req
  71. */
  72. void rdns_request_remove_from_hash (struct rdns_request *req);
  73. /**
  74. * Creates a new reply
  75. * @param req
  76. * @param rcode
  77. * @return
  78. */
  79. struct rdns_reply * rdns_make_reply (struct rdns_request *req, enum dns_rcode rcode);
  80. /**
  81. * Free reply
  82. * @param rep
  83. */
  84. void rdns_reply_free (struct rdns_reply *rep);
  85. void rdns_request_unschedule (struct rdns_request *req, bool remove_from_hash);
  86. #endif /* UTIL_H_ */