/contrib/bind9/lib/dns/rdata/hs_4/a_1.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 237 lines · 162 code · 57 blank · 18 comment · 41 complexity · 30aa32be88dc4088aced668201bd878b MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2002 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: a_1.c,v 1.33 2009/12/04 22:06:37 tbox Exp $ */
  18. /* reviewed: Thu Mar 16 15:58:36 PST 2000 by brister */
  19. #ifndef RDATA_HS_4_A_1_C
  20. #define RDATA_HS_4_A_1_C
  21. #include <isc/net.h>
  22. #define RRTYPE_A_ATTRIBUTES (0)
  23. static inline isc_result_t
  24. fromtext_hs_a(ARGS_FROMTEXT) {
  25. isc_token_t token;
  26. struct in_addr addr;
  27. isc_region_t region;
  28. REQUIRE(type == 1);
  29. REQUIRE(rdclass == 4);
  30. UNUSED(type);
  31. UNUSED(origin);
  32. UNUSED(options);
  33. UNUSED(rdclass);
  34. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
  35. ISC_FALSE));
  36. if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
  37. RETTOK(DNS_R_BADDOTTEDQUAD);
  38. isc_buffer_availableregion(target, &region);
  39. if (region.length < 4)
  40. return (ISC_R_NOSPACE);
  41. memcpy(region.base, &addr, 4);
  42. isc_buffer_add(target, 4);
  43. return (ISC_R_SUCCESS);
  44. }
  45. static inline isc_result_t
  46. totext_hs_a(ARGS_TOTEXT) {
  47. isc_region_t region;
  48. REQUIRE(rdata->type == 1);
  49. REQUIRE(rdata->rdclass == 4);
  50. REQUIRE(rdata->length == 4);
  51. UNUSED(tctx);
  52. dns_rdata_toregion(rdata, &region);
  53. return (inet_totext(AF_INET, &region, target));
  54. }
  55. static inline isc_result_t
  56. fromwire_hs_a(ARGS_FROMWIRE) {
  57. isc_region_t sregion;
  58. isc_region_t tregion;
  59. REQUIRE(type == 1);
  60. REQUIRE(rdclass == 4);
  61. UNUSED(type);
  62. UNUSED(dctx);
  63. UNUSED(options);
  64. UNUSED(rdclass);
  65. isc_buffer_activeregion(source, &sregion);
  66. isc_buffer_availableregion(target, &tregion);
  67. if (sregion.length < 4)
  68. return (ISC_R_UNEXPECTEDEND);
  69. if (tregion.length < 4)
  70. return (ISC_R_NOSPACE);
  71. memcpy(tregion.base, sregion.base, 4);
  72. isc_buffer_forward(source, 4);
  73. isc_buffer_add(target, 4);
  74. return (ISC_R_SUCCESS);
  75. }
  76. static inline isc_result_t
  77. towire_hs_a(ARGS_TOWIRE) {
  78. isc_region_t region;
  79. REQUIRE(rdata->type == 1);
  80. REQUIRE(rdata->rdclass == 4);
  81. REQUIRE(rdata->length == 4);
  82. UNUSED(cctx);
  83. isc_buffer_availableregion(target, &region);
  84. if (region.length < rdata->length)
  85. return (ISC_R_NOSPACE);
  86. memcpy(region.base, rdata->data, rdata->length);
  87. isc_buffer_add(target, 4);
  88. return (ISC_R_SUCCESS);
  89. }
  90. static inline int
  91. compare_hs_a(ARGS_COMPARE) {
  92. int order;
  93. REQUIRE(rdata1->type == rdata2->type);
  94. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  95. REQUIRE(rdata1->type == 1);
  96. REQUIRE(rdata1->rdclass == 4);
  97. REQUIRE(rdata1->length == 4);
  98. REQUIRE(rdata2->length == 4);
  99. order = memcmp(rdata1->data, rdata2->data, 4);
  100. if (order != 0)
  101. order = (order < 0) ? -1 : 1;
  102. return (order);
  103. }
  104. static inline isc_result_t
  105. fromstruct_hs_a(ARGS_FROMSTRUCT) {
  106. dns_rdata_hs_a_t *a = source;
  107. isc_uint32_t n;
  108. REQUIRE(type == 1);
  109. REQUIRE(rdclass == 4);
  110. REQUIRE(source != NULL);
  111. REQUIRE(a->common.rdtype == type);
  112. REQUIRE(a->common.rdclass == rdclass);
  113. UNUSED(type);
  114. UNUSED(rdclass);
  115. n = ntohl(a->in_addr.s_addr);
  116. return (uint32_tobuffer(n, target));
  117. }
  118. static inline isc_result_t
  119. tostruct_hs_a(ARGS_TOSTRUCT) {
  120. dns_rdata_hs_a_t *a = target;
  121. isc_uint32_t n;
  122. isc_region_t region;
  123. REQUIRE(rdata->type == 1);
  124. REQUIRE(rdata->rdclass == 4);
  125. REQUIRE(rdata->length == 4);
  126. UNUSED(mctx);
  127. a->common.rdclass = rdata->rdclass;
  128. a->common.rdtype = rdata->type;
  129. ISC_LINK_INIT(&a->common, link);
  130. dns_rdata_toregion(rdata, &region);
  131. n = uint32_fromregion(&region);
  132. a->in_addr.s_addr = htonl(n);
  133. return (ISC_R_SUCCESS);
  134. }
  135. static inline void
  136. freestruct_hs_a(ARGS_FREESTRUCT) {
  137. UNUSED(source);
  138. REQUIRE(source != NULL);
  139. }
  140. static inline isc_result_t
  141. additionaldata_hs_a(ARGS_ADDLDATA) {
  142. REQUIRE(rdata->type == 1);
  143. REQUIRE(rdata->rdclass == 4);
  144. UNUSED(rdata);
  145. UNUSED(add);
  146. UNUSED(arg);
  147. return (ISC_R_SUCCESS);
  148. }
  149. static inline isc_result_t
  150. digest_hs_a(ARGS_DIGEST) {
  151. isc_region_t r;
  152. REQUIRE(rdata->type == 1);
  153. REQUIRE(rdata->rdclass == 4);
  154. dns_rdata_toregion(rdata, &r);
  155. return ((digest)(arg, &r));
  156. }
  157. static inline isc_boolean_t
  158. checkowner_hs_a(ARGS_CHECKOWNER) {
  159. REQUIRE(type == 1);
  160. REQUIRE(rdclass == 4);
  161. UNUSED(name);
  162. UNUSED(type);
  163. UNUSED(rdclass);
  164. UNUSED(wildcard);
  165. return (ISC_TRUE);
  166. }
  167. static inline isc_boolean_t
  168. checknames_hs_a(ARGS_CHECKNAMES) {
  169. REQUIRE(rdata->type == 1);
  170. REQUIRE(rdata->rdclass == 4);
  171. UNUSED(rdata);
  172. UNUSED(owner);
  173. UNUSED(bad);
  174. return (ISC_TRUE);
  175. }
  176. static inline int
  177. casecompare_hs_a(ARGS_COMPARE) {
  178. return (compare_hs_a(rdata1, rdata2));
  179. }
  180. #endif /* RDATA_HS_4_A_1_C */