-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnsec.c
54 lines (49 loc) · 1.18 KB
/
nsec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include "dnssec.h"
#include "arg.h"
static void
usage(void)
{
fprintf(stderr, "usage: nsec [zonefile]\n");
exit(2);
}
int
main(int argc, char *argv[])
{
ARGBEGIN {
default:
usage();
} ARGEND
if (argc > 1)
usage();
struct zone z;
char errmsg[256];
if (zone_parse(&z, argv[0], errmsg, sizeof(errmsg)) != 0) {
fprintf(stderr, "%s\n", errmsg);
errx(1, "zone parse failed");
}
for (size_t i = 0, j = 0; i < z.rr_len; i = j) {
unsigned char m[32] = {0}, t;
m[TYPE_NSEC / 8] |= 0x80 >> (TYPE_NSEC % 8);
m[TYPE_RRSIG / 8] |= 0x80 >> (TYPE_RRSIG % 8);
do {
if ((t = z.rr[j]->type) > 255)
errx(1, "record types above 255 are not supported");
m[t / 8] |= 0x80 >> (t % 8);
} while (++j < z.rr_len && dname_compare(z.rr[i]->name, z.rr[j]->name) == 0);
dname_print(z.rr[i]->name);
printf("\t%lu\t%s\tNSEC\t", z.minimum_ttl, class_to_string(z.rr[i]->class));
dname_print(z.rr[j % z.rr_len]->name);
for (int t = 0; t <= 255; ++t) {
if (m[t / 8] & 0x80 >> t % 8)
printf(" %s", type_to_string(t));
}
putchar('\n');
}
fflush(stdout);
if (ferror(stdout))
errx(1, "write failed");
}