From 5f475509e9ea15d0e007b361f05f61f03fd61e7c Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Fri, 19 Sep 2025 15:02:05 -0400 Subject: [PATCH 1/4] Draft parsing of SRV records --- src/dns.c | 27 +++++++++++++++++++++++++++ tests/testthat/_snaps/nsl.md | 9 +++++++++ tests/testthat/test-nsl.R | 6 ++++++ 3 files changed, 42 insertions(+) create mode 100644 tests/testthat/_snaps/nsl.md create mode 100644 tests/testthat/test-nsl.R diff --git a/src/dns.c b/src/dns.c index a413eb4..c120c49 100644 --- a/src/dns.c +++ b/src/dns.c @@ -241,6 +241,14 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) { (unsigned int) ptr->Data.SOA.dwDefaultTtl); break; + case DNS_TYPE_SRV: + snprintf(buf, sizeof buf, "%u %u %u %s", + ptr->Data.SRV.wPriority, + ptr->Data.SRV.wWeight, + ptr->Data.SRV.wPort, + ptr->Data.SRV.pNameTarget); + break; + default: raw = 1; rawdata = PROTECT(Rf_allocVector(RAWSXP, ptr->wDataLength)); @@ -468,6 +476,25 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) { soa[0], soa[1], soa[2], soa[3], soa[4]); break; } + case ns_t_srv: { + u_int16_t priority, weight, port; + char target[NS_MAXDNAME]; + + NS_GET16(priority, data); + NS_GET16(weight, data); + NS_GET16(port, data); + ret = xxns_name_uncompress(ns_msg_base(msg), ns_msg_end(msg), + data, target, sizeof target); + if (ret < 0) { +#if (__RES >= 19991006) + res_nclose(statep); +#endif + R_THROW_SYSTEM_ERROR("Cannot parse SRV target hostname"); + } + + snprintf(buf, sizeof buf, "%u %u %u %s", priority, weight, port, target); + break; } + default: raw = 1; rawdata = PROTECT(Rf_allocVector(RAWSXP, ns_rr_rdlen(rec))); diff --git a/tests/testthat/_snaps/nsl.md b/tests/testthat/_snaps/nsl.md new file mode 100644 index 0000000..b1902e7 --- /dev/null +++ b/tests/testthat/_snaps/nsl.md @@ -0,0 +1,9 @@ +# nsl function works with SRV records + + Code + result$answer$data + Output + [[1]] + [1] "10 100 80 mxtoolbox.com" + + diff --git a/tests/testthat/test-nsl.R b/tests/testthat/test-nsl.R new file mode 100644 index 0000000..3d42048 --- /dev/null +++ b/tests/testthat/test-nsl.R @@ -0,0 +1,6 @@ +test_that("nsl function works with SRV records", { + testthat::skip_on_ci() + + result = nsl("_http._tcp.mxtoolbox.com", type = 33L) + expect_snapshot(result$answer$data) +}) From c14ad1ba59b2449ef1ea7a781b8aeca74b08f996 Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Fri, 19 Sep 2025 15:04:53 -0400 Subject: [PATCH 2/4] Fix --- src/dns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dns.c b/src/dns.c index c120c49..6744b68 100644 --- a/src/dns.c +++ b/src/dns.c @@ -476,7 +476,7 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) { soa[0], soa[1], soa[2], soa[3], soa[4]); break; } - case ns_t_srv: { + case ns_t_srv: u_int16_t priority, weight, port; char target[NS_MAXDNAME]; @@ -493,7 +493,7 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) { } snprintf(buf, sizeof buf, "%u %u %u %s", priority, weight, port, target); - break; } + break; default: raw = 1; From 54593e33668fff7dabd566862f848bf154f420d1 Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Fri, 19 Sep 2025 15:19:03 -0400 Subject: [PATCH 3/4] Trigger --- src/dns.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dns.c b/src/dns.c index 6744b68..339771e 100644 --- a/src/dns.c +++ b/src/dns.c @@ -491,7 +491,6 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) { #endif R_THROW_SYSTEM_ERROR("Cannot parse SRV target hostname"); } - snprintf(buf, sizeof buf, "%u %u %u %s", priority, weight, port, target); break; From 10f4f33d23a0817724b529306a186ed7454db0e1 Mon Sep 17 00:00:00 2001 From: Colin Rundel Date: Fri, 19 Sep 2025 15:34:21 -0400 Subject: [PATCH 4/4] Update --- tests/testthat/_snaps/nsl.md | 9 --------- tests/testthat/test-nsl.R | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 tests/testthat/_snaps/nsl.md diff --git a/tests/testthat/_snaps/nsl.md b/tests/testthat/_snaps/nsl.md deleted file mode 100644 index b1902e7..0000000 --- a/tests/testthat/_snaps/nsl.md +++ /dev/null @@ -1,9 +0,0 @@ -# nsl function works with SRV records - - Code - result$answer$data - Output - [[1]] - [1] "10 100 80 mxtoolbox.com" - - diff --git a/tests/testthat/test-nsl.R b/tests/testthat/test-nsl.R index 3d42048..64cad76 100644 --- a/tests/testthat/test-nsl.R +++ b/tests/testthat/test-nsl.R @@ -2,5 +2,5 @@ test_that("nsl function works with SRV records", { testthat::skip_on_ci() result = nsl("_http._tcp.mxtoolbox.com", type = 33L) - expect_snapshot(result$answer$data) + expect_true("10 100 80 mxtoolbox.com" %in% unlist(result$answer$data)) })