-
Notifications
You must be signed in to change notification settings - Fork 1
/
zoneoutput.c
57 lines (51 loc) · 1.6 KB
/
zoneoutput.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
55
56
57
#define _LARGEFILE64_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <ldns/ldns.h>
#include "uthash.h"
#include "proto.h"
#pragma GCC optimize ("O0")
int
writezone(names_view_type view, const char* filename, const char* apex, int* defaultttl)
{
char* s;
const char* recordname;
ldns_rr_type recordtype;
resourcerecord_t item;
names_iterator domainiter;
names_iterator rrsetiter;
names_iterator rriter;
dictionary domainitem;
ldns_rdf* origin;
FILE* fp;
origin = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, apex);
fp = fopen(filename,"w");
if(!fp) {
fprintf(stderr,"unable to open file \"%s\"\n",filename);
}
s = ldns_rdf2str(origin);
fprintf(fp, "$ORIGIN %s\n", s);
free(s);
if(defaultttl)
fprintf(fp, "$TTL %d\n",*defaultttl);
for (domainiter = names_viewiterator(view, 0); names_iterate(&domainiter, &domainitem); names_advance(&domainiter, NULL)) {
getset(domainitem, "name", &recordname, NULL);
for (rrsetiter = names_recordalltypes(domainitem); names_iterate(&rrsetiter, &recordtype); names_advance(&rrsetiter, NULL)) {
for (rriter = names_recordallvalues(domainitem,recordtype); names_iterate(&rriter, &item); names_advance(&rriter, NULL)) {
s = names_rr2str(domainitem, recordtype, item);
fprintf(fp, "%s", s);
free(s);
}
}
}
fclose(fp);
ldns_rdf_free(origin);
return 0;
}