diff options
-rw-r--r-- | README.7 | 15 | ||||
-rw-r--r-- | imbox.c | 22 |
2 files changed, 31 insertions, 6 deletions
diff --git a/README.7 b/README.7 index 619ff64..b78dc49 100644 --- a/README.7 +++ b/README.7 @@ -31,13 +31,22 @@ The install prefix of LibreSSL is set by .Va LIBRESSL_PREFIX . The path of .Xr dig 1 +or +.Xr drill 1 can be set by defining the C preprocessor macro -.Va DIG_PATH . -The default is +.Va DIG_PATH +or +.Va DRILL_PATH , +respectively. +The default is to set +.Va DRILL_PATH +to .Pa /usr/bin/drill on .Fx -and +and set +.Va DIG_PATH +to .Pa dig everywhere else. . 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 |