-
Notifications
You must be signed in to change notification settings - Fork 12
/
LDNS.xs
2553 lines (2254 loc) · 56.2 KB
/
LDNS.xs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <LDNS.h>
MODULE = Zonemaster::LDNS PACKAGE = Zonemaster::LDNS
PROTOTYPES: ENABLE
SV *
to_idn(...)
PPCODE:
{
#ifdef WE_CAN_HAZ_IDN
int i;
for( i = 0; i<items; i++ )
{
char *out;
int status;
SV *obj = ST(i);
if (SvPOK(ST(i)))
{
status = idn2_to_ascii_8z(SvPVutf8_nolen(obj), &out, IDN2_ALLOW_UNASSIGNED);
if (status == IDN2_OK)
{
SV *new = newSVpv(out,0);
SvUTF8_on(new); /* We know the string is plain ASCII, so let Perl know too */
mXPUSHs(new);
free(out);
}
else
{
croak("Error: %s\n", idn2_strerror(status));
}
}
}
#else
croak("libidn2 not installed");
#endif
}
bool
has_idn()
CODE:
#ifdef WE_CAN_HAZ_IDN
RETVAL = 1;
#else
RETVAL = 0;
#endif
OUTPUT:
RETVAL
bool
has_gost()
CODE:
#ifdef USE_GOST
RETVAL = 1;
#else
RETVAL = 0;
#endif
OUTPUT:
RETVAL
const char *
lib_version()
CODE:
RETVAL = ldns_version();
OUTPUT:
RETVAL
SV *
load_zonefile(filename)
char *filename;
PPCODE:
{
ldns_zone *zone;
ldns_status s;
ldns_rr *soa;
ldns_rr_list *rrs;
ldns_rdf *root = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,".");
I32 context = GIMME_V;
size_t i,n;
if (context == G_VOID)
{
return;
}
FILE *fp = fopen(filename, "r");
if(!fp)
{
croak("%s",strerror(errno));
}
s = ldns_zone_new_frm_fp(&zone, fp, root, 3600, LDNS_RR_CLASS_IN);
if(s != LDNS_STATUS_OK)
{
croak("%s",ldns_get_errorstr_by_id(s));
}
soa = ldns_zone_soa(zone);
rrs = ldns_zone_rrs(zone);
n = ldns_rr_list_rr_count(rrs);
if (context == G_SCALAR)
{
ldns_zone_deep_free(zone);
ldns_rdf_deep_free(root);
XSRETURN_IV(n+1); /* Add one for SOA */
}
mXPUSHs(rr2sv(ldns_rr_clone(soa)));
for(i = 0; i < n; ++i)
{
mXPUSHs(rr2sv(ldns_rr_clone(ldns_rr_list_rr(rrs,i))));
}
ldns_zone_deep_free(zone);
ldns_rdf_deep_free(root);
}
SV *
new(class, ...)
char *class;
CODE:
{
int i;
ldns_resolver *res;
RETVAL = newSV(0);
if (items == 1 ) { /* Called without arguments, use resolv.conf */
ldns_resolver_new_frm_file(&res,NULL);
}
else {
res = ldns_resolver_new();
ldns_resolver_set_recursive(res, 1);
for (i=1;i<items;i++)
{
ldns_status s;
ldns_rdf *addr;
SvGETMAGIC(ST(i));
addr = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, SvPV_nolen(ST(i)));
if ( addr == NULL) {
addr = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, SvPV_nolen(ST(i)));
}
if ( addr == NULL ) {
croak("Failed to parse IP address: %s", SvPV_nolen(ST(i)));
}
s = ldns_resolver_push_nameserver(res, addr);
ldns_rdf_deep_free(addr);
if(s != LDNS_STATUS_OK)
{
croak("Adding nameserver failed: %s", ldns_get_errorstr_by_id(s));
}
}
}
sv_setref_pv(RETVAL, class, res);
#ifdef USE_ITHREADS
net_ldns_remember_resolver(RETVAL);
#endif
}
OUTPUT:
RETVAL
SV *
query(obj, dname, rrtype="A", rrclass="IN")
Zonemaster::LDNS obj;
char *dname;
char *rrtype;
char *rrclass;
CODE:
{
ldns_rdf *domain;
ldns_rr_type t;
ldns_rr_class c;
ldns_status status;
ldns_pkt *pkt;
uint16_t flags = 0;
t = ldns_get_rr_type_by_name(rrtype);
if(!t)
{
croak("Unknown RR type: %s", rrtype);
}
c = ldns_get_rr_class_by_name(rrclass);
if(!c)
{
croak("Unknown RR class: %s", rrclass);
}
domain = ldns_dname_new_frm_str(dname);
if(domain==NULL)
{
croak("Invalid domain name: %s", dname);
}
if(ldns_resolver_recursive(obj))
{
flags |= LDNS_RD;
}
if(ldns_resolver_dnssec_cd(obj))
{
flags |= LDNS_CD;
}
status = ldns_resolver_send(&pkt, obj, domain, t, c, flags);
if ( status != LDNS_STATUS_OK) {
/* Remove and reinsert nameserver to make ldns forget it failed */
ldns_status s;
ldns_rdf *ns = ldns_resolver_pop_nameserver(obj);
if (ns != NULL) {
s = ldns_resolver_push_nameserver(obj, ns);
if ( s != LDNS_STATUS_OK) {
croak("Failed to reinsert nameserver after failure (ouch): %s", ldns_get_errorstr_by_id(s));
}
ldns_rdf_deep_free(ns);
}
ldns_rdf_deep_free(domain);
croak("%s", ldns_get_errorstr_by_id(status));
RETVAL = NULL;
}
ldns_pkt *clone = ldns_pkt_clone(pkt);
ldns_pkt_set_timestamp(clone, ldns_pkt_timestamp(pkt));
RETVAL = sv_setref_pv(newSV(0), "Zonemaster::LDNS::Packet", clone);
ldns_rdf_deep_free(domain);
ldns_pkt_free(pkt);
#ifdef USE_ITHREADS
net_ldns_remember_packet(RETVAL);
#endif
}
OUTPUT:
RETVAL
#
# Function: query_with_pkt
# ------------------------
# Sister function of 'query' that takes a 'ready to send'
# packet instead of create a new one from provided parameters.
#
# obj: LDNS resolver object
# query_pkt: the packet to send
#
# returns: a "Zonemaster::LDNS::Packet" object with answer of the query
#
SV *
query_with_pkt(obj, query_pkt)
Zonemaster::LDNS obj;
Zonemaster::LDNS::Packet query_pkt;
CODE:
{
ldns_status status;
ldns_pkt *pkt;
status = ldns_resolver_send_pkt(&pkt, obj, query_pkt);
if ( status != LDNS_STATUS_OK) {
/* Remove and reinsert nameserver to make ldns forget it failed */
ldns_status s;
ldns_rdf *ns = ldns_resolver_pop_nameserver(obj);
if (ns != NULL) {
s = ldns_resolver_push_nameserver(obj, ns);
if ( s != LDNS_STATUS_OK) {
croak("Failed to reinsert nameserver after failure (ouch): %s", ldns_get_errorstr_by_id(s));
}
ldns_rdf_deep_free(ns);
}
croak("%s", ldns_get_errorstr_by_id(status));
RETVAL = NULL;
}
ldns_pkt *clone = ldns_pkt_clone(pkt);
ldns_pkt_set_timestamp(clone, ldns_pkt_timestamp(pkt));
RETVAL = sv_setref_pv(newSV(0), "Zonemaster::LDNS::Packet", clone);
ldns_pkt_free(pkt);
#ifdef USE_ITHREADS
net_ldns_remember_packet(RETVAL);
#endif
}
OUTPUT:
RETVAL
bool
recurse(obj,...)
Zonemaster::LDNS obj;
CODE:
if(items>1) {
SvGETMAGIC(ST(1));
ldns_resolver_set_recursive(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_recursive(obj);
OUTPUT:
RETVAL
bool
debug(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_debug(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_debug(obj);
OUTPUT:
RETVAL
bool
dnssec(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_dnssec(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_dnssec(obj);
OUTPUT:
RETVAL
bool
cd(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_dnssec_cd(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_dnssec_cd(obj);
OUTPUT:
RETVAL
bool
usevc(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_usevc(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_usevc(obj);
OUTPUT:
RETVAL
bool
igntc(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_igntc(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_igntc(obj);
OUTPUT:
RETVAL
#
# Function: fallback
# ------------------
# Get/set 'fallback' flag
#
# returns: a boolean
#
bool
fallback(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_fallback(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_fallback(obj);
OUTPUT:
RETVAL
U8
retry(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_retry(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_retry(obj);
OUTPUT:
RETVAL
U8
retrans(obj,...)
Zonemaster::LDNS obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_resolver_set_retrans(obj, SvIV(ST(1)));
}
RETVAL = ldns_resolver_retrans(obj);
OUTPUT:
RETVAL
U16
edns_size(obj,...)
Zonemaster::LDNS obj;
CODE:
if( items > 1 )
{
SvGETMAGIC(ST(1));
ldns_resolver_set_edns_udp_size(obj, (U16)SvIV(ST(1)));
}
RETVAL = ldns_resolver_edns_udp_size(obj);
OUTPUT:
RETVAL
U16
port(obj,...)
Zonemaster::LDNS obj;
CODE:
if( items > 1 )
{
SvGETMAGIC(ST(1));
ldns_resolver_set_port(obj, (U16)SvIV(ST(1)));
}
RETVAL = ldns_resolver_port(obj);
OUTPUT:
RETVAL
SV *
name2addr(obj,name)
Zonemaster::LDNS obj;
const char *name;
PPCODE:
{
ldns_rr_list *addrs;
ldns_rdf *dname;
size_t n, i;
I32 context;
context = GIMME_V;
if(context == G_VOID)
{
XSRETURN_NO;
}
dname = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, name);
if(dname==NULL)
{
croak("Name error for '%s'", name);
}
addrs = ldns_get_rr_list_addr_by_name(obj,dname,LDNS_RR_CLASS_IN,0);
n = ldns_rr_list_rr_count(addrs);
ldns_rdf_deep_free(dname);
if (context == G_SCALAR)
{
ldns_rr_list_deep_free(addrs);
XSRETURN_IV(n);
}
else
{
for(i = 0; i < n; ++i)
{
ldns_rr *rr = ldns_rr_list_rr(addrs,i);
ldns_rdf *addr_rdf = ldns_rr_a_address(rr);
char *addr_str = ldns_rdf2str(addr_rdf);
SV* sv = newSVpv(addr_str,0);
mXPUSHs(sv);
free(addr_str);
}
ldns_rr_list_deep_free(addrs);
}
}
SV *
addr2name(obj,addr_in)
Zonemaster::LDNS obj;
const char *addr_in;
PPCODE:
{
ldns_rr_list *names;
ldns_rdf *addr_rdf;
size_t n, i;
I32 context;
context = GIMME_V;
if(context == G_VOID)
{
XSRETURN_NO;
}
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, addr_in);
if(addr_rdf==NULL)
{
addr_rdf = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, addr_in);
}
if(addr_rdf==NULL)
{
croak("Failed to parse address: %s", addr_in);
}
names = ldns_get_rr_list_name_by_addr(obj,addr_rdf,LDNS_RR_CLASS_IN,0);
ldns_rdf_deep_free(addr_rdf);
n = ldns_rr_list_rr_count(names);
if (context == G_SCALAR)
{
ldns_rr_list_deep_free(names);
XSRETURN_IV(n);
}
else
{
for(i = 0; i < n; ++i)
{
ldns_rr *rr = ldns_rr_list_rr(names,i);
ldns_rdf *name_rdf = ldns_rr_rdf(rr,0);
char *name_str = randomize_capitalization(ldns_rdf2str(name_rdf));
SV* sv = newSVpv(name_str,0);
mXPUSHs(sv);
free(name_str);
}
ldns_rr_list_deep_free(names);
}
}
bool
axfr(obj,dname,callback,class="IN")
Zonemaster::LDNS obj;
const char *dname;
SV *callback;
const char *class;
CODE:
{
ldns_rdf *domain = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, dname);
ldns_rr_class cl = ldns_get_rr_class_by_name(class);
ldns_status status;
SvGETMAGIC(callback);
if(SvTYPE(SvRV(callback)) != SVt_PVCV)
{
ldns_rdf_deep_free(domain);
croak("Callback not a code reference");
}
if(domain==NULL)
{
ldns_rdf_deep_free(domain);
croak("Name error for '%s", dname);
}
if(!cl)
{
ldns_rdf_deep_free(domain);
croak("Unknown RR class: %s", class);
}
status = ldns_axfr_start(obj, domain, cl);
ldns_rdf_deep_free(domain);
if(status != LDNS_STATUS_OK)
{
croak("AXFR setup error: %s", ldns_get_errorstr_by_id(status));
}
RETVAL = 1;
while (!ldns_axfr_complete(obj))
{
int count;
SV *ret;
ldns_rr *rr = ldns_axfr_next(obj);
if(rr==NULL)
{
ldns_pkt *pkt = ldns_axfr_last_pkt(obj);
if(pkt != NULL)
{
char tmp[20];
char *msg = ldns_pkt_rcode2str(ldns_pkt_get_rcode(pkt));
strncpy(tmp,msg,19);
free(msg);
croak("AXFR transfer error: %s", tmp);
}
else {
croak("AXFR transfer error: unknown problem");
}
ldns_pkt_free(pkt);
}
/* Enter the Cargo Cult */
ENTER;
SAVETMPS;
PUSHMARK(SP);
mXPUSHs(rr2sv(rr));
PUTBACK;
count = call_sv(callback, G_SCALAR);
SPAGAIN;
if(count != 1)
{
croak("Callback did not return exactly one value in scalar context");
}
ret = POPs;
if(!SvTRUE(ret))
{
RETVAL = 0;
break;
}
PUTBACK;
FREETMPS;
LEAVE;
/* Callback magic ends */
}
ldns_axfr_abort(obj);
}
OUTPUT:
RETVAL
bool
axfr_start(obj,dname,class="IN")
Zonemaster::LDNS obj;
const char *dname;
const char *class;
CODE:
{
ldns_rdf *domain = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, dname);
ldns_rr_class cl = ldns_get_rr_class_by_name(class);
ldns_status s;
if(domain==NULL)
{
croak("Name error for '%s", dname);
}
if(!cl)
{
croak("Unknown RR class: %s", class);
}
s = ldns_axfr_start(obj, domain, cl);
RETVAL = (s==LDNS_STATUS_OK);
}
OUTPUT:
RETVAL
SV *
axfr_next(obj)
Zonemaster::LDNS obj;
CODE:
{
ldns_rr *rr;
/* ldns unfortunately prints to standard error, so close it while we call them */
/* EDIT: That behavior should be changed starting with ldns 1.6.17, but we'll keep the closing for a while */
int err_fd = fileno(stderr); /* Remember fd for stderr */
int save_fd = dup(err_fd); /* Copy open fd for stderr */
int tmp_fd;
fflush(stderr); /* Print anything waiting */
tmp_fd = open("/dev/null",O_RDWR); /* Open something to allocate the now-free fd stderr used */
dup2(tmp_fd,err_fd);
rr = ldns_axfr_next(obj); /* Shut up */
close(tmp_fd); /* Close the placeholder */
fflush(stderr); /* Flush anything ldns buffered */
dup2(save_fd,err_fd); /* And copy the open stderr back to where it should be */
if(rr==NULL)
{
croak("AXFR error");
}
RETVAL = rr2sv(rr);
}
OUTPUT:
RETVAL
bool
axfr_complete(obj)
Zonemaster::LDNS obj;
CODE:
RETVAL = ldns_axfr_complete(obj);
OUTPUT:
RETVAL
Zonemaster::LDNS::Packet
axfr_last_packet(obj)
Zonemaster::LDNS obj;
CODE:
RETVAL = ldns_axfr_last_pkt(obj);
OUTPUT:
RETVAL
double
timeout(obj,...)
Zonemaster::LDNS obj;
CODE:
struct timeval tv;
if( items > 1)
{
double dec_part, int_part;
struct timeval tn;
SvGETMAGIC(ST(1));
dec_part = modf(SvNV(ST(1)), &int_part);
tn.tv_sec = int_part;
tn.tv_usec = 1000000*dec_part;
ldns_resolver_set_timeout(obj, tn);
}
tv = ldns_resolver_timeout(obj);
RETVAL = (double)tv.tv_sec;
RETVAL += ((double)tv.tv_usec)/1000000;
OUTPUT:
RETVAL
char *
source(obj,...)
Zonemaster::LDNS obj;
CODE:
if(items >= 2)
{
ldns_rdf *address;
SvGETMAGIC(ST(1));
address = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_A, SvPV_nolen(ST(1)));
if(address == NULL)
{
address = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_AAAA, SvPV_nolen(ST(1)));
}
if(address == NULL)
{
croak("Failed to parse IP address: %s", SvPV_nolen(ST(1)));
}
ldns_resolver_set_source(obj, address);
}
RETVAL = ldns_rdf2str(ldns_resolver_source(obj));
OUTPUT:
RETVAL
CLEANUP:
free(RETVAL);
void
DESTROY(obj)
Zonemaster::LDNS obj;
CODE:
#ifdef USE_ITHREADS
net_ldns_forget();
#endif
ldns_axfr_abort(obj);
ldns_resolver_deep_free(obj);
#ifdef USE_ITHREADS
void
CLONE(class)
char *class;
CODE:
net_ldns_clone_resolvers();
#endif
MODULE = Zonemaster::LDNS PACKAGE = Zonemaster::LDNS::Packet PREFIX=packet_
SV *
packet_new(objclass,name,type="A",class="IN")
char *objclass;
char *name;
char *type;
char *class;
CODE:
{
ldns_rdf *rr_name;
ldns_rr_type rr_type;
ldns_rr_class rr_class;
ldns_pkt *pkt;
rr_type = ldns_get_rr_type_by_name(type);
if(!rr_type)
{
croak("Unknown RR type: %s", type);
}
rr_class = ldns_get_rr_class_by_name(class);
if(!rr_class)
{
croak("Unknown RR class: %s", class);
}
rr_name = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, name);
if(rr_name == NULL)
{
croak("Name error for '%s'", name);
}
pkt = ldns_pkt_query_new(rr_name, rr_type, rr_class,0);
RETVAL = newSV(0);
sv_setref_pv(RETVAL, objclass, pkt);
#ifdef USE_ITHREADS
net_ldns_remember_packet(RETVAL);
#endif
}
OUTPUT:
RETVAL
char *
packet_rcode(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
if ( strnEQ("NOERROR", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NOERROR);
}
else if ( strnEQ("FORMERR", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_FORMERR);
}
else if ( strnEQ("SERVFAIL", SvPV_nolen(ST(1)), 8) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_SERVFAIL);
}
else if ( strnEQ("NXDOMAIN", SvPV_nolen(ST(1)), 8) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NXDOMAIN);
}
else if ( strnEQ("NOTIMPL", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NOTIMPL);
}
else if ( strnEQ("REFUSED", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_REFUSED);
}
else if ( strnEQ("YXDOMAIN", SvPV_nolen(ST(1)), 8) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_YXDOMAIN);
}
else if ( strnEQ("YXRRSET", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_YXRRSET);
}
else if ( strnEQ("NXRRSET", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NXRRSET);
}
else if ( strnEQ("NOTAUTH", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NOTAUTH);
}
else if ( strnEQ("NOTZONE", SvPV_nolen(ST(1)), 7) ) {
ldns_pkt_set_rcode(obj, LDNS_RCODE_NOTZONE);
}
else {
croak("Unknown RCODE: %s", SvPV_nolen(ST(1)));
}
}
RETVAL = ldns_pkt_rcode2str(ldns_pkt_get_rcode(obj));
OUTPUT:
RETVAL
CLEANUP:
free(RETVAL);
char *
packet_opcode(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
if ( strnEQ("QUERY", SvPV_nolen(ST(1)), 5) ) {
ldns_pkt_set_opcode(obj, LDNS_PACKET_QUERY);
}
else if ( strnEQ("IQUERY", SvPV_nolen(ST(1)), 6) ) {
ldns_pkt_set_opcode(obj, LDNS_PACKET_IQUERY);
}
else if ( strnEQ("STATUS", SvPV_nolen(ST(1)), 6) ) {
ldns_pkt_set_opcode(obj, LDNS_PACKET_STATUS);
}
else if ( strnEQ("NOTIFY", SvPV_nolen(ST(1)), 6) ) {
ldns_pkt_set_opcode(obj, LDNS_PACKET_NOTIFY);
}
else if ( strnEQ("UPDATE", SvPV_nolen(ST(1)), 6) ) {
ldns_pkt_set_opcode(obj, LDNS_PACKET_UPDATE);
}
else {
croak("Unknown OPCODE: %s", SvPV_nolen(ST(1)));
}
}
RETVAL = ldns_pkt_opcode2str(ldns_pkt_get_opcode(obj));
OUTPUT:
RETVAL
CLEANUP:
free(RETVAL);
U16
packet_id(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_id(obj, (U16)SvIV(ST(1)));
}
RETVAL = ldns_pkt_id(obj);
OUTPUT:
RETVAL
bool
packet_qr(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_qr(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_qr(obj);
OUTPUT:
RETVAL
bool
packet_aa(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_aa(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_aa(obj);
OUTPUT:
RETVAL
bool
packet_tc(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_tc(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_tc(obj);
OUTPUT:
RETVAL
bool
packet_rd(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_rd(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_rd(obj);
OUTPUT:
RETVAL
bool
packet_cd(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_cd(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_cd(obj);
OUTPUT:
RETVAL
bool
packet_ra(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_ra(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_ra(obj);
OUTPUT:
RETVAL
bool
packet_ad(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_ad(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_ad(obj);
OUTPUT:
RETVAL
bool
packet_do(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
if ( items > 1 ) {
SvGETMAGIC(ST(1));
ldns_pkt_set_edns_do(obj, SvIV(ST(1)));
}
RETVAL = ldns_pkt_edns_do(obj);
OUTPUT:
RETVAL
size_t
packet_size(obj)
Zonemaster::LDNS::Packet obj;