diff options
author | tgreenx <96772376+tgreenx@users.noreply.github.com> | 2023-01-18 15:05:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-18 15:05:49 +0100 |
commit | 2250891e3800a35e58c294206cb39cd1041713df (patch) | |
tree | 0ea90abc27ac23625e8ab69f16d78b7dfa7be57e | |
parent | 6c674e1ed6e37bdfbddc9e5c46d9ac9f25e63033 (diff) | |
parent | 988a29d27517a71dd306e24054600e44e4626f96 (diff) |
Merge pull request #166 from tgreenx/fix-edns-data
Update edns_data to return RDATA
-rw-r--r-- | src/LDNS.xs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/LDNS.xs b/src/LDNS.xs index e4b63a9..0b5dae2 100644 --- a/src/LDNS.xs +++ b/src/LDNS.xs @@ -1375,12 +1375,17 @@ 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 acts on the OPT RDATA field of a packet. An OPT RDATA consists of at least one triplet +# {OPTION-CODE, OPTION-LENGTH, OPTION-DATA}. +# When given a parameter, this function will set and return the field, although with the limitation described below. +# Otherwise, it will get and return the field (if any). +# +# Beware, when setting OPT 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 OPT RDATA is found) # SV * packet_edns_data(obj,...) @@ -1391,7 +1396,7 @@ packet_edns_data(obj,...) { SvGETMAGIC(ST(1)); opt = ldns_native2rdf_int32(LDNS_RDF_TYPE_INT32, (U32)SvIV(ST(1))); - if(opt == NULL) + if(opt == NULL) { croak("Failed to set OPT RDATA"); } @@ -1399,8 +1404,12 @@ packet_edns_data(obj,...) } else { opt = ldns_pkt_edns_data(obj); + if(opt == NULL) + { + XSRETURN_UNDEF; + } } - RETVAL = newSVpvn((char*)(opt), 4); + RETVAL = newSVpvn((char*)(opt->_data), opt->_size); OUTPUT: RETVAL |