a_1.c revision db725ebe2b5d913949246b02573df01bd29f5412
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews/*
7d32c065c7bb56f281651ae3dd2888f32ce4f1d9Bob Halley * Copyright (C) 1999 Internet Software Consortium.
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff *
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * Permission to use, copy, modify, and distribute this software for any
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * purpose with or without fee is hereby granted, provided that the above
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * copyright notice and this permission notice appear in all copies.
2f072c2982861ec2e86e97f8a3ed199fe45c1f70Michael Graff *
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews * SOFTWARE.
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews */
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
82ca33427bdd4f3bc4ed3431e86bd810fe751674Andreas Gustafsson /* $Id: a_1.c,v 1.1 1999/10/13 01:24:46 marka Exp $ */
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff#ifndef RDATA_HS_4_A_1_C
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews#define RDATA_HS_4_A_1_C
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews
854d0238dbc2908490197984b3b9d558008a53dfMark Andrews#include <string.h>
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews#include <isc/net.h>
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsfromtext_hs_a(dns_rdataclass_t rdclass, dns_rdatatype_t type,
8360c3dc0f8ab25f4839c79e30d6865838d9a4daBob Halley isc_lex_t *lexer, dns_name_t *origin,
8360c3dc0f8ab25f4839c79e30d6865838d9a4daBob Halley isc_boolean_t downcase, isc_buffer_t *target)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews{
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff isc_token_t token;
6324997211a5e2d82528dcde98e8981190a35faeMichael Graff struct in_addr addr;
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff isc_region_t region;
d981ca645597116d227a48bf37cc5edc061c854dBob Halley
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews REQUIRE(type == 1);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews REQUIRE(rdclass == 4);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews origin = origin; /*unused*/
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews downcase = downcase; /*unused*/
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews RETERR(gettoken(lexer, &token, isc_tokentype_string, ISC_FALSE));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (inet_aton(token.value.as_pointer, &addr) != 1)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_BADDOTTEDQUAD);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_buffer_available(target, &region);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (region.length < 4)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_NOSPACE);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews memcpy(region.base, &addr, 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_SUCCESS);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff}
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graffstatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewstotext_hs_a(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx,
d981ca645597116d227a48bf37cc5edc061c854dBob Halley isc_buffer_t *target)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews{
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t region;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata->type == 1);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(rdata->rdclass == 4);
8360c3dc0f8ab25f4839c79e30d6865838d9a4daBob Halley REQUIRE(rdata->length == 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews tctx = tctx; /* unused */
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_available(target, &region);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (inet_ntop(AF_INET, rdata->data,
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews (char *)region.base, region.length) == NULL)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_NOSPACE);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, strlen((char *)region.base));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_SUCCESS);
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews}
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsfromwire_hs_a(dns_rdataclass_t rdclass, dns_rdatatype_t type,
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_t *source, dns_decompress_t *dctx,
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff isc_boolean_t downcase, isc_buffer_t *target)
df7f20ae77fbe03d2973d1768d6a68da1063af84Andreas Gustafsson{
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t sregion;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t tregion;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(type == 1);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdclass == 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dctx = dctx; /* unused */
df7f20ae77fbe03d2973d1768d6a68da1063af84Andreas Gustafsson downcase = downcase; /* unused */
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews isc_buffer_active(source, &sregion);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews isc_buffer_available(target, &tregion);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews if (sregion.length < 4)
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews return (DNS_R_UNEXPECTEDEND);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (tregion.length < 4)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_NOSPACE);
5d15501996f597d9bbb734d88d4549828e28000bMark Andrews
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff memcpy(tregion.base, sregion.base, 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_forward(source, 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewstowire_hs_a(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t region;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff REQUIRE(rdata->type == 1);
19c5c23ef6e38965949c996592bd92478da0612cMark Andrews REQUIRE(rdata->rdclass == 4);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff cctx = cctx; /*unused*/
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff isc_buffer_available(target, &region);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews if (region.length < rdata->length)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_NOSPACE);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews memcpy(region.base, rdata->data, rdata->length);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_add(target, 4);
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff return (DNS_R_SUCCESS);
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson}
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafsson
5fc7ba3e1ac5d72239e9971e0f469dd5796738f9Andreas Gustafssonstatic inline int
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewscompare_hs_a(dns_rdata_t *rdata1, dns_rdata_t *rdata2) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews int result;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata1->type == rdata2->type);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata1->rdclass == rdata2->type);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata1->type == 1);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff REQUIRE(rdata1->rdclass == 4);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = memcmp(rdata1->data, rdata2->data, 4);
d981ca645597116d227a48bf37cc5edc061c854dBob Halley if (result != 0)
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews result = (result < 0) ? -1 : 1;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence return (result);
8360c3dc0f8ab25f4839c79e30d6865838d9a4daBob Halley}
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
af6dfd762ef13de674c84f70488067ae78d2573eBob Halleystatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsfromstruct_hs_a(dns_rdataclass_t rdclass, dns_rdatatype_t type, void *source,
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_buffer_t *target)
df7f20ae77fbe03d2973d1768d6a68da1063af84Andreas Gustafsson{
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews REQUIRE(type == 1);
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews REQUIRE(rdclass == 4);
b538f54ad3bc526bb1a79d652e71a2816e3c306aAndreas Gustafsson
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews source = source;
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews target = target;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_NOTIMPLEMENTED);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff}
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsstatic inline dns_result_t
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrewstostruct_hs_a(dns_rdata_t *rdata, void *target, isc_mem_t *mctx) {
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews dns_rdata_hs_a_t *a = target;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_uint32_t n;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t region;
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
deaaf94332abbfdb3aff53675546acfed16e5eb6Mark Andrews REQUIRE(rdata->type == 1);
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff REQUIRE(rdata->rdclass == 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews mctx = mctx; /* unused */
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
d981ca645597116d227a48bf37cc5edc061c854dBob Halley a->common.rdclass = rdata->rdclass;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews a->common.rdtype = rdata->type;
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews ISC_LINK_INIT(&a->common, link);
0e8cf9a887c70f96ac448b06c069d90b830215ccMark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews dns_rdata_toregion(rdata, &region);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews n = uint32_fromregion(&region);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews a->in_addr.s_addr = htonl(n);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff return (DNS_R_SUCCESS);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halleystatic inline void
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsfreestruct_hs_a(void *source) {
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(source != NULL);
6e49e91bd08778d7eae45a2229dcf41ed97cc636David Lawrence REQUIRE(ISC_FALSE); /*XXX*/
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
df7f20ae77fbe03d2973d1768d6a68da1063af84Andreas Gustafsson}
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
df7f20ae77fbe03d2973d1768d6a68da1063af84Andreas Gustafssonstatic inline dns_result_t
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrewsadditionaldata_hs_a(dns_rdata_t *rdata, dns_additionaldatafunc_t add,
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews void *arg)
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff{
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata->type == 1);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews REQUIRE(rdata->rdclass == 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews (void)add;
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff (void)arg;
419590499823ce15b5d2ad4fe71eaf04bd5a86c0Michael Graff
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return (DNS_R_SUCCESS);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
3ddd814a97de1d152ba0913c592d6e6dc83d38a6Michael Graff
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graffstatic inline dns_result_t
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graffdigest_hs_a(dns_rdata_t *rdata, dns_digestfunc_t digest, void *arg) {
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews isc_region_t r;
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff REQUIRE(rdata->type == 1);
f31f0b63cbe841720f154c570bcdede9d79e64b8Michael Graff REQUIRE(rdata->rdclass == 4);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
d981ca645597116d227a48bf37cc5edc061c854dBob Halley dns_rdata_toregion(rdata, &r);
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews return ((digest)(arg, &r));
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews}
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews
44a966dff66061ac3f266c6b451a70733eb78e82Mark Andrews#endif /* RDATA_HS_4_A_1_C */
4529cdaedaf1a0a5f8ff89aeca510b7a4475446cBob Halley