2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 10:10:06 +00:00
bind/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 20:05:15 +00:00
/*
2018-02-15 12:08:52 +11:00
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
2000-01-12 20:05:15 +00:00
*
* SPDX-License-Identifier: MPL-2.0
*
2000-01-12 20:05:15 +00: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 20:05:15 +00:00
* See the COPYRIGHT file distributed with this work for additional
2000-01-18 02:50:23 +00:00
* information regarding copyright ownership.
2000-01-12 20:05:15 +00:00
*/
/*! \file */
2000-06-22 22:00:42 +00:00
#include <stdbool.h>
2000-01-18 19:07:39 +00:00
#include <isc/mem.h>
#include <isc/netaddr.h>
#include <isc/result.h>
#include <isc/string.h>
2000-01-12 20:05:15 +00:00
#include <isc/util.h>
#include <dns/byaddr.h>
2000-01-15 02:20:49 +00:00
#include <dns/db.h>
#include <dns/rdata.h>
2000-01-15 00:48:49 +00:00
#include <dns/rdataset.h>
#include <dns/rdatastruct.h>
2000-01-12 20:05:15 +00:00
#include <dns/resolver.h>
#include <dns/view.h>
/*
* XXXRTH We could use a static event...
*/
2000-01-18 02:50:23 +00: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-18 02:50:23 +00:00
char textname[128];
const unsigned char *bytes;
2000-01-18 02:50:23 +00:00
int i;
char *cp;
isc_buffer_t buffer;
unsigned int len;
2000-01-15 02:20:49 +00:00
REQUIRE(address != NULL);
2000-01-15 02:20:49 +00:00
2000-01-18 02:50:23 +00: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-15 02:20:49 +00:00
bytes = (const unsigned char *)(&address->type);
2000-01-18 02:50:23 +00:00
if (address->family == AF_INET) {
(void)snprintf(textname, sizeof(textname),
"%u.%u.%u.%u.in-addr.arpa.",
2019-03-14 19:46:10 +11:00
((unsigned int)bytes[3] & 0xffU),
((unsigned int)bytes[2] & 0xffU),
((unsigned int)bytes[1] & 0xffU),
((unsigned int)bytes[0] & 0xffU));
2000-01-18 02:50:23 +00: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-18 02:50:23 +00:00
}
remaining = sizeof(textname) - (cp - textname);
strlcpy(cp, "ip6.arpa.", remaining);
2000-01-18 02:50:23 +00:00
} else {
return ISC_R_NOTIMPLEMENTED;
}
2000-01-18 02:50:23 +00:00
len = (unsigned int)strlen(textname);
isc_buffer_init(&buffer, textname, len);
2000-01-18 02:50:23 +00:00
isc_buffer_add(&buffer, len);
return dns_name_fromtext(name, &buffer, dns_rootname, 0);
}