mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
used fixed names
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include <dns/types.h>
|
#include <dns/types.h>
|
||||||
#include <dns/result.h>
|
#include <dns/result.h>
|
||||||
#include <dns/name.h>
|
#include <dns/name.h>
|
||||||
|
#include <dns/fixedname.h>
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_wirename(isc_region_t *name) {
|
print_wirename(isc_region_t *name) {
|
||||||
@@ -45,17 +46,13 @@ print_wirename(isc_region_t *name) {
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[]) {
|
main(int argc, char *argv[]) {
|
||||||
char s[1000];
|
char s[1000];
|
||||||
unsigned char b[255];
|
|
||||||
unsigned char o[255];
|
|
||||||
unsigned char c[255];
|
|
||||||
dns_result_t result;
|
dns_result_t result;
|
||||||
dns_name_t name, oname, compname;
|
dns_fixedname_t wname, oname, compname;
|
||||||
isc_buffer_t source, target;
|
isc_buffer_t source;
|
||||||
isc_region_t r;
|
isc_region_t r;
|
||||||
dns_name_t *origin, *comp;
|
dns_name_t *name, *origin, *comp;
|
||||||
isc_boolean_t downcase = ISC_FALSE;
|
isc_boolean_t downcase = ISC_FALSE;
|
||||||
size_t len;
|
size_t len;
|
||||||
dns_offsets_t offsets, compoffsets;
|
|
||||||
isc_boolean_t quiet = ISC_FALSE;
|
isc_boolean_t quiet = ISC_FALSE;
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
@@ -78,19 +75,17 @@ main(int argc, char *argv[]) {
|
|||||||
isc_buffer_init(&source, argv[0], len,
|
isc_buffer_init(&source, argv[0], len,
|
||||||
ISC_BUFFERTYPE_TEXT);
|
ISC_BUFFERTYPE_TEXT);
|
||||||
isc_buffer_add(&source, len);
|
isc_buffer_add(&source, len);
|
||||||
isc_buffer_init(&target, o, 255,
|
dns_fixedname_init(&oname);
|
||||||
ISC_BUFFERTYPE_BINARY);
|
origin = &oname.name;
|
||||||
dns_name_init(&oname, NULL);
|
result = dns_name_fromtext(origin, &source,
|
||||||
result = dns_name_fromtext(&oname, &source,
|
|
||||||
dns_rootname, ISC_FALSE,
|
dns_rootname, ISC_FALSE,
|
||||||
&target);
|
NULL);
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"dns_name_fromtext() failed: %d\n",
|
"dns_name_fromtext() failed: %d\n",
|
||||||
result);
|
result);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
origin = &oname;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
origin = dns_rootname;
|
origin = dns_rootname;
|
||||||
@@ -103,37 +98,34 @@ main(int argc, char *argv[]) {
|
|||||||
isc_buffer_init(&source, argv[1], len,
|
isc_buffer_init(&source, argv[1], len,
|
||||||
ISC_BUFFERTYPE_TEXT);
|
ISC_BUFFERTYPE_TEXT);
|
||||||
isc_buffer_add(&source, len);
|
isc_buffer_add(&source, len);
|
||||||
isc_buffer_init(&target, c, 255,
|
dns_fixedname_init(&compname);
|
||||||
ISC_BUFFERTYPE_BINARY);
|
comp = &compname.name;
|
||||||
dns_name_init(&compname, compoffsets);
|
result = dns_name_fromtext(comp, &source,
|
||||||
result = dns_name_fromtext(&compname, &source,
|
origin, ISC_FALSE, NULL);
|
||||||
origin, ISC_FALSE,
|
|
||||||
&target);
|
|
||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"dns_name_fromtext() failed: %d\n",
|
"dns_name_fromtext() failed: %d\n",
|
||||||
result);
|
result);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
comp = &compname;
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
comp = NULL;
|
comp = NULL;
|
||||||
|
|
||||||
dns_name_init(&name, offsets);
|
dns_fixedname_init(&wname);
|
||||||
|
name = &wname.name;
|
||||||
while (gets(s) != NULL) {
|
while (gets(s) != NULL) {
|
||||||
len = strlen(s);
|
len = strlen(s);
|
||||||
isc_buffer_init(&source, s, len, ISC_BUFFERTYPE_TEXT);
|
isc_buffer_init(&source, s, len, ISC_BUFFERTYPE_TEXT);
|
||||||
isc_buffer_add(&source, len);
|
isc_buffer_add(&source, len);
|
||||||
isc_buffer_init(&target, b, 255, ISC_BUFFERTYPE_BINARY);
|
result = dns_name_fromtext(name, &source, origin, downcase,
|
||||||
result = dns_name_fromtext(&name, &source, origin, downcase,
|
NULL);
|
||||||
&target);
|
|
||||||
if (result == DNS_R_SUCCESS) {
|
if (result == DNS_R_SUCCESS) {
|
||||||
dns_name_toregion(&name, &r);
|
dns_name_toregion(name, &r);
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
print_wirename(&r);
|
print_wirename(&r);
|
||||||
printf("%u labels, %u bytes.\n",
|
printf("%u labels, %u bytes.\n",
|
||||||
dns_name_countlabels(&name),
|
dns_name_countlabels(name),
|
||||||
r.length);
|
r.length);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
@@ -142,7 +134,7 @@ main(int argc, char *argv[]) {
|
|||||||
if (result == DNS_R_SUCCESS) {
|
if (result == DNS_R_SUCCESS) {
|
||||||
isc_buffer_init(&source, s, sizeof s,
|
isc_buffer_init(&source, s, sizeof s,
|
||||||
ISC_BUFFERTYPE_TEXT);
|
ISC_BUFFERTYPE_TEXT);
|
||||||
result = dns_name_totext(&name, ISC_FALSE, &source);
|
result = dns_name_totext(name, ISC_FALSE, &source);
|
||||||
if (result == DNS_R_SUCCESS) {
|
if (result == DNS_R_SUCCESS) {
|
||||||
isc_buffer_used(&source, &r);
|
isc_buffer_used(&source, &r);
|
||||||
printf("%.*s\n", (int)r.length, r.base);
|
printf("%.*s\n", (int)r.length, r.base);
|
||||||
@@ -158,7 +150,7 @@ main(int argc, char *argv[]) {
|
|||||||
unsigned int nlabels, nbits;
|
unsigned int nlabels, nbits;
|
||||||
dns_namereln_t namereln;
|
dns_namereln_t namereln;
|
||||||
|
|
||||||
namereln = dns_name_fullcompare(&name, comp, &order,
|
namereln = dns_name_fullcompare(name, comp, &order,
|
||||||
&nlabels, &nbits);
|
&nlabels, &nbits);
|
||||||
if (!quiet) {
|
if (!quiet) {
|
||||||
if (order < 0)
|
if (order < 0)
|
||||||
|
Reference in New Issue
Block a user