Skip to content

Commit

Permalink
DNS: don't use global _res state
Browse files Browse the repository at this point in the history
It is not allowed on NetBSD, it is a bad thing,
anyway.
  • Loading branch information
gaborcsardi committed Oct 25, 2024
1 parent e324599 commit d1f95ea
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,21 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) {
SET_VECTOR_ELT(result, 0, records);
SET_VECTOR_ELT(result, 1, mkNamed(LGLSXP, flagnames));

ret = res_init();
struct __res_state state;
res_state statep = &state;
ret = res_ninit(statep);

Check warning on line 313 in src/dns.c

View check run for this annotation

Codecov / codecov/patch

src/dns.c#L312-L313

Added lines #L312 - L313 were not covered by tests
if (ret) R_THROW_SYSTEM_ERROR("Failed to initialize resolver library");

if (!isNull(server)) {
struct in_addr addr;
ret = inet_pton(AF_INET, CHAR(STRING_ELT(server, 0)), &addr);
_res.options &= ~(RES_DNSRCH | RES_DEFNAMES);
_res.nscount = LENGTH(server);
_res.nsaddr_list[0].sin_addr = addr;
statep->options &= ~(RES_DNSRCH | RES_DEFNAMES);
statep->nscount = LENGTH(server);
statep->nsaddr_list[0].sin_addr = addr;

Check warning on line 321 in src/dns.c

View check run for this annotation

Codecov / codecov/patch

src/dns.c#L319-L321

Added lines #L319 - L321 were not covered by tests
}

ret = res_query(
ret = res_nquery(

Check warning on line 324 in src/dns.c

View check run for this annotation

Codecov / codecov/patch

src/dns.c#L324

Added line #L324 was not covered by tests
statep,
CHAR(STRING_ELT(hostname, 0)),
INTEGER(class)[0],
INTEGER(type)[0],
Expand Down Expand Up @@ -443,6 +446,7 @@ SEXP r_nsl(SEXP hostname, SEXP server, SEXP class, SEXP type) {
if (!raw) SET_VECTOR_ELT(VECTOR_ELT(records, 4), i, mkString(buf));
}

res_nclose(statep);

Check warning on line 449 in src/dns.c

View check run for this annotation

Codecov / codecov/patch

src/dns.c#L449

Added line #L449 was not covered by tests
UNPROTECT(3);
return result;
}
Expand Down

0 comments on commit d1f95ea

Please sign in to comment.