summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--imbox.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/imbox.c b/imbox.c
index eb611a2..fff867f 100644
--- a/imbox.c
+++ b/imbox.c
@@ -27,9 +27,9 @@
 #include <tls.h>
 #include <unistd.h>
 
-#ifndef DIG_PATH
+#if !defined(DIG_PATH) && !defined(DRILL_PATH)
 #	ifdef __FreeBSD__
-#		define DIG_PATH "/usr/bin/drill"
+#		define DRILL_PATH "/usr/bin/drill"
 #	else
 #		define DIG_PATH "dig"
 #	endif
@@ -108,8 +108,13 @@ static void lookup(const char **host, const char **port, const char *domain) {
 		dup2(rw[1], STDOUT_FILENO);
 		dup2(rw[1], STDERR_FILENO);
 		close(rw[1]);
+#ifdef DRILL_PATH
+		execlp(DRILL_PATH, DRILL_PATH, buf, "SRV", NULL);
+		err(EX_CONFIG, "%s", DRILL_PATH);
+#else
 		execlp(DIG_PATH, DIG_PATH, "-t", "SRV", "-q", buf, "+short", NULL);
 		err(EX_CONFIG, "%s", DIG_PATH);
+#endif
 	}
 
 	int status;
@@ -122,7 +127,6 @@ static void lookup(const char **host, const char **port, const char *domain) {
 
 	fgets(buf, sizeof(buf), pipe);
 	if (ferror(pipe)) err(EX_IOERR, "fgets");
-	fclose(pipe);
 
 	if (!WIFEXITED(status) || WEXITSTATUS(status)) {
 		fprintf(stderr, "%s", buf);
@@ -130,6 +134,18 @@ static void lookup(const char **host, const char **port, const char *domain) {
 	}
 
 	char *ptr = buf;
+#ifdef DRILL_PATH
+	for (;;) {
+		char *line = fgets(buf, sizeof(buf), pipe);
+		if (!line || !strcmp(line, ";; ANSWER SECTION:\n")) break;
+	}
+	fgets(buf, sizeof(buf), pipe);
+	if (ferror(pipe)) err(EX_IOERR, "fgets");
+	ptr = strrchr(buf, '\t');
+	ptr = (ptr ? ptr + 1 : buf);
+#endif
+	fclose(pipe);
+
 	char *dot = strrchr(ptr, '.');
 	if (dot) *dot = '\0';
 	strsep(&ptr, " \n"); // priority