summaryrefslogtreecommitdiff
path: root/src/dnsstub/dns_resolve.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-09 13:58:20 +0200
commit249866e3d1e11dc72eaa1305f4bb479ded92ef38 (patch)
tree7118c5f58e29fe61c100e4d067bb90ba8d52589e /src/dnsstub/dns_resolve.c
parent96cf8dffe4f7b0b910f790066ae622dc429eb522 (diff)
reorganized file structure
Moved c files into src/. Corrected VERSION file. Removed BUILD and FILES.
Diffstat (limited to 'src/dnsstub/dns_resolve.c')
-rw-r--r--src/dnsstub/dns_resolve.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/dnsstub/dns_resolve.c b/src/dnsstub/dns_resolve.c
new file mode 100644
index 0000000..bcc4308
--- /dev/null
+++ b/src/dnsstub/dns_resolve.c
@@ -0,0 +1,39 @@
+#include "iopause.h"
+#include "taia.h"
+#include "byte.h"
+#include "ip.h"
+#include "dnsresolv.h"
+
+/**
+ @file dns_resolve.c
+ @author djb, fefe, feh
+ @source ucspi-tcp
+ @brief high-level DNS resolve function
+*/
+
+struct dns_transmit dns_resolve_tx = {0};
+
+int dns_resolve(const char *q,const char qtype[2])
+{
+ struct taia stamp;
+ struct taia deadline;
+ char servers[QUERY_MAXIPLEN];
+ uint32 scopes[QUERY_MAXNS];
+ iopause_fd x[1];
+ int r;
+
+ if (dns_resolvconfip(servers,scopes) < 0) return DNS_INT;
+
+ if (dns_transmit_start6(&dns_resolve_tx,servers,1,q,qtype,(const char *)V6localnet,scopes) < 0) return DNS_COM;
+
+ for (;;) {
+ taia_now(&stamp);
+ taia_uint(&deadline,120);
+ taia_add(&deadline,&deadline,&stamp);
+ dns_transmit_io(&dns_resolve_tx,x,&deadline);
+ iopause(x,1,&deadline,&stamp);
+ r = dns_transmit_get(&dns_resolve_tx,x,&stamp);
+ if (r < 0) return DNS_COM;
+ if (r == 1) return 0;
+ }
+}