bind9/lib/dns/byaddr.c

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

85 lines
2.2 KiB
C
Raw Normal View History

2000-01-12 15:05:15 -05:00
/*
2018-02-14 20:08:52 -05:00
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2000-01-12 15:05:15 -05:00
*
* SPDX-License-Identifier: MPL-2.0
*
2000-01-12 15:05:15 -05:00
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
2000-01-12 15:05:15 -05:00
* See the COPYRIGHT file distributed with this work for additional
2000-01-17 21:50:23 -05:00
* information regarding copyright ownership.
2000-01-12 15:05:15 -05:00
*/
/*! \file */
2000-06-22 18:00:42 -04:00
#include <stdbool.h>
2000-01-18 14:07:39 -05:00
#include <isc/mem.h>
#include <isc/netaddr.h>
#include <isc/result.h>
#include <isc/string.h>
2000-01-12 15:05:15 -05:00
#include <isc/util.h>
#include <dns/byaddr.h>
2000-01-14 21:20:49 -05:00
#include <dns/db.h>
#include <dns/rdata.h>
2000-01-14 19:48:49 -05:00
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
2000-01-12 15:05:15 -05:00
#include <dns/resolver.h>
#include <dns/view.h>
/*
* XXXRTH We could use a static event...
*/
2000-01-17 21:50:23 -05:00
static char hex_digits[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
isc_result_t
dns_byaddr_createptrname(const isc_netaddr_t *address, dns_name_t *name) {
2000-01-17 21:50:23 -05:00
char textname[128];
const unsigned char *bytes;
2000-01-17 21:50:23 -05:00
int i;
char *cp;
isc_buffer_t buffer;
unsigned int len;
2000-01-14 21:20:49 -05:00
REQUIRE(address != NULL);
2000-01-14 21:20:49 -05:00
2000-01-17 21:50:23 -05:00
/*
* We create the text representation and then convert to a
* dns_name_t. This is not maximally efficient, but it keeps all
* of the knowledge of wire format in the dns_name_ routines.
*/
2000-01-14 21:20:49 -05:00
bytes = (const unsigned char *)(&address->type);
2000-01-17 21:50:23 -05:00
if (address->family == AF_INET) {
(void)snprintf(textname, sizeof(textname),
"%u.%u.%u.%u.in-addr.arpa.",
2019-03-14 04:46:10 -04:00
((unsigned int)bytes[3] & 0xffU),
((unsigned int)bytes[2] & 0xffU),
((unsigned int)bytes[1] & 0xffU),
((unsigned int)bytes[0] & 0xffU));
2000-01-17 21:50:23 -05:00
} else if (address->family == AF_INET6) {
size_t remaining;
cp = textname;
for (i = 15; i >= 0; i--) {
*cp++ = hex_digits[bytes[i] & 0x0f];
*cp++ = '.';
*cp++ = hex_digits[(bytes[i] >> 4) & 0x0f];
*cp++ = '.';
2000-01-17 21:50:23 -05:00
}
remaining = sizeof(textname) - (cp - textname);
strlcpy(cp, "ip6.arpa.", remaining);
2000-01-17 21:50:23 -05:00
} else {
return ISC_R_NOTIMPLEMENTED;
}
2000-01-17 21:50:23 -05:00
len = (unsigned int)strlen(textname);
isc_buffer_init(&buffer, textname, len);
2000-01-17 21:50:23 -05:00
isc_buffer_add(&buffer, len);
return dns_name_fromtext(name, &buffer, dns_rootname, 0);
}