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

https://bitbucket.org/freebsd/freebsd-head/ · C · 241 lines · 164 code · 59 blank · 18 comment · 41 complexity · bbfd0512acd74000c77676357e405c78 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2007, 2009 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1998-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.55 2009/12/04 22:06:37 tbox Exp $ */
  18. /* Reviewed: Thu Mar 16 16:52:50 PST 2000 by bwelling */
  19. #ifndef RDATA_IN_1_A_1_C
  20. #define RDATA_IN_1_A_1_C
  21. #include <string.h>
  22. #include <isc/net.h>
  23. #define RRTYPE_A_ATTRIBUTES (0)
  24. static inline isc_result_t
  25. fromtext_in_a(ARGS_FROMTEXT) {
  26. isc_token_t token;
  27. struct in_addr addr;
  28. isc_region_t region;
  29. REQUIRE(type == 1);
  30. REQUIRE(rdclass == 1);
  31. UNUSED(type);
  32. UNUSED(origin);
  33. UNUSED(options);
  34. UNUSED(rdclass);
  35. RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string,
  36. ISC_FALSE));
  37. if (getquad(DNS_AS_STR(token), &addr, lexer, callbacks) != 1)
  38. RETTOK(DNS_R_BADDOTTEDQUAD);
  39. isc_buffer_availableregion(target, &region);
  40. if (region.length < 4)
  41. return (ISC_R_NOSPACE);
  42. memcpy(region.base, &addr, 4);
  43. isc_buffer_add(target, 4);
  44. return (ISC_R_SUCCESS);
  45. }
  46. static inline isc_result_t
  47. totext_in_a(ARGS_TOTEXT) {
  48. isc_region_t region;
  49. REQUIRE(rdata->type == 1);
  50. REQUIRE(rdata->rdclass == 1);
  51. REQUIRE(rdata->length == 4);
  52. UNUSED(tctx);
  53. dns_rdata_toregion(rdata, &region);
  54. return (inet_totext(AF_INET, &region, target));
  55. }
  56. static inline isc_result_t
  57. fromwire_in_a(ARGS_FROMWIRE) {
  58. isc_region_t sregion;
  59. isc_region_t tregion;
  60. REQUIRE(type == 1);
  61. REQUIRE(rdclass == 1);
  62. UNUSED(type);
  63. UNUSED(dctx);
  64. UNUSED(options);
  65. UNUSED(rdclass);
  66. isc_buffer_activeregion(source, &sregion);
  67. isc_buffer_availableregion(target, &tregion);
  68. if (sregion.length < 4)
  69. return (ISC_R_UNEXPECTEDEND);
  70. if (tregion.length < 4)
  71. return (ISC_R_NOSPACE);
  72. memcpy(tregion.base, sregion.base, 4);
  73. isc_buffer_forward(source, 4);
  74. isc_buffer_add(target, 4);
  75. return (ISC_R_SUCCESS);
  76. }
  77. static inline isc_result_t
  78. towire_in_a(ARGS_TOWIRE) {
  79. isc_region_t region;
  80. REQUIRE(rdata->type == 1);
  81. REQUIRE(rdata->rdclass == 1);
  82. REQUIRE(rdata->length == 4);
  83. UNUSED(cctx);
  84. isc_buffer_availableregion(target, &region);
  85. if (region.length < rdata->length)
  86. return (ISC_R_NOSPACE);
  87. memcpy(region.base, rdata->data, rdata->length);
  88. isc_buffer_add(target, 4);
  89. return (ISC_R_SUCCESS);
  90. }
  91. static inline int
  92. compare_in_a(ARGS_COMPARE) {
  93. isc_region_t r1;
  94. isc_region_t r2;
  95. REQUIRE(rdata1->type == rdata2->type);
  96. REQUIRE(rdata1->rdclass == rdata2->rdclass);
  97. REQUIRE(rdata1->type == 1);
  98. REQUIRE(rdata1->rdclass == 1);
  99. REQUIRE(rdata1->length == 4);
  100. REQUIRE(rdata2->length == 4);
  101. dns_rdata_toregion(rdata1, &r1);
  102. dns_rdata_toregion(rdata2, &r2);
  103. return (isc_region_compare(&r1, &r2));
  104. }
  105. static inline isc_result_t
  106. fromstruct_in_a(ARGS_FROMSTRUCT) {
  107. dns_rdata_in_a_t *a = source;
  108. isc_uint32_t n;
  109. REQUIRE(type == 1);
  110. REQUIRE(rdclass == 1);
  111. REQUIRE(source != NULL);
  112. REQUIRE(a->common.rdtype == type);
  113. REQUIRE(a->common.rdclass == rdclass);
  114. UNUSED(type);
  115. UNUSED(rdclass);
  116. n = ntohl(a->in_addr.s_addr);
  117. return (uint32_tobuffer(n, target));
  118. }
  119. static inline isc_result_t
  120. tostruct_in_a(ARGS_TOSTRUCT) {
  121. dns_rdata_in_a_t *a = target;
  122. isc_uint32_t n;
  123. isc_region_t region;
  124. REQUIRE(rdata->type == 1);
  125. REQUIRE(rdata->rdclass == 1);
  126. REQUIRE(rdata->length == 4);
  127. UNUSED(mctx);
  128. a->common.rdclass = rdata->rdclass;
  129. a->common.rdtype = rdata->type;
  130. ISC_LINK_INIT(&a->common, link);
  131. dns_rdata_toregion(rdata, &region);
  132. n = uint32_fromregion(&region);
  133. a->in_addr.s_addr = htonl(n);
  134. return (ISC_R_SUCCESS);
  135. }
  136. static inline void
  137. freestruct_in_a(ARGS_FREESTRUCT) {
  138. dns_rdata_in_a_t *a = source;
  139. REQUIRE(source != NULL);
  140. REQUIRE(a->common.rdtype == 1);
  141. REQUIRE(a->common.rdclass == 1);
  142. UNUSED(a);
  143. }
  144. static inline isc_result_t
  145. additionaldata_in_a(ARGS_ADDLDATA) {
  146. REQUIRE(rdata->type == 1);
  147. REQUIRE(rdata->rdclass == 1);
  148. UNUSED(rdata);
  149. UNUSED(add);
  150. UNUSED(arg);
  151. return (ISC_R_SUCCESS);
  152. }
  153. static inline isc_result_t
  154. digest_in_a(ARGS_DIGEST) {
  155. isc_region_t r;
  156. REQUIRE(rdata->type == 1);
  157. REQUIRE(rdata->rdclass == 1);
  158. dns_rdata_toregion(rdata, &r);
  159. return ((digest)(arg, &r));
  160. }
  161. static inline isc_boolean_t
  162. checkowner_in_a(ARGS_CHECKOWNER) {
  163. REQUIRE(type == 1);
  164. REQUIRE(rdclass == 1);
  165. UNUSED(type);
  166. UNUSED(rdclass);
  167. return (dns_name_ishostname(name, wildcard));
  168. }
  169. static inline isc_boolean_t
  170. checknames_in_a(ARGS_CHECKNAMES) {
  171. REQUIRE(rdata->type == 1);
  172. REQUIRE(rdata->rdclass == 1);
  173. UNUSED(rdata);
  174. UNUSED(owner);
  175. UNUSED(bad);
  176. return (ISC_TRUE);
  177. }
  178. static inline int
  179. casecompare_in_a(ARGS_COMPARE) {
  180. return (compare_in_a(rdata1, rdata2));
  181. }
  182. #endif /* RDATA_IN_1_A_1_C */