summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author[Thomas Green] <thomas.green@afnic.fr>2023-01-10 16:35:46 +0100
committer[Thomas Green] <thomas.green@afnic.fr>2023-01-10 16:35:46 +0100
commitbed4a20a8899bd759099c6077e4baea860088b83 (patch)
tree5a920c7f91c3a596746eb02dc13b600d366836d7
parent6c674e1ed6e37bdfbddc9e5c46d9ac9f25e63033 (diff)
Initial commit
Updated edns_data to be able to return the entire RDATA of an EDNS packet Renamed variable to a more adequate name - it was not an 'opt' (option) that was returned, but a LDNS structure (Ressource Record Field, 'rdf') Updated documentation
-rw-r--r--src/LDNS.xs30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/LDNS.xs b/src/LDNS.xs
index e4b63a9..2f1dd24 100644
--- a/src/LDNS.xs
+++ b/src/LDNS.xs
@@ -1375,32 +1375,42 @@ packet_edns_version(obj,...)
# -------------------
# Get/set EDNS data
#
-# Beware, this code can only take a unique U32 parameter which means it
-# is not a full implementation of EDNS data but it is enough for our
+# This function will set EDNS RDATA in a packet when given a parameter,
+# otherwise it will return the entire EDNS RDATA of the packet (if any).
+#
+# Beware, when setting EDNS RDATA, this code can only take a unique U32 parameter
+# which means it is not a full implementation of EDNS data but it is enough for our
# current purpose. It can only deal with option codes with OPTION-LENGTH=0
# (see 6.1.2 section of RFC 6891) which means OPTION-DATA is always empty.
#
-# returns: a bytes string
+# returns: a bytes string (or undef if no EDNS data is found)
#
SV *
packet_edns_data(obj,...)
Zonemaster::LDNS::Packet obj;
CODE:
- ldns_rdf* opt;
+ ldns_rdf* rdf;
if(items>=2)
{
SvGETMAGIC(ST(1));
- opt = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, (U32)SvIV(ST(1)));
- if(opt == NULL)
+ rdf = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, (U32)SvIV(ST(1)));
+ if(rdf == NULL)
{
- croak("Failed to set OPT RDATA");
+ croak("Failed to set rdf RDATA");
}
- ldns_pkt_set_edns_data(obj, opt);
+ ldns_pkt_set_edns_data(obj, rdf);
+ RETVAL = newSVpvn((char*)(rdf), 4);
}
else {
- opt = ldns_pkt_edns_data(obj);
+ rdf = ldns_pkt_edns_data(obj);
+ if(rdf == NULL)
+ {
+ XSRETURN_UNDEF;
+ }
+ else{
+ RETVAL = newSVpvn((char*)(rdf->_data), rdf->_size);
+ }
}
- RETVAL = newSVpvn((char*)(opt), 4);
OUTPUT:
RETVAL