feature-test.c revision 2b9f526504d80d332ce14e8d008e79b68188f972
d0be1e954bd4674fc27f2616c72adb37cf3525a2David Lawrence/*
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater * Copyright (C) 2016, 2017 Internet Systems Consortium, Inc. ("ISC")
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington *
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence * This Source Code Form is subject to the terms of the Mozilla Public
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * License, v. 2.0. If a copy of the MPL was not distributed with this
d0be1e954bd4674fc27f2616c72adb37cf3525a2David Lawrence * file, You can obtain one at http://mozilla.org/MPL/2.0/.
d0be1e954bd4674fc27f2616c72adb37cf3525a2David Lawrence */
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <config.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <unistd.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <stdio.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <stdlib.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews#include <string.h>
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews
d0be1e954bd4674fc27f2616c72adb37cf3525a2David Lawrence#include <isc/print.h>
d0be1e954bd4674fc27f2616c72adb37cf3525a2David Lawrence#include <isc/util.h>
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater#include <isc/net.h>
821644d49b73b49f2abc5463bc53a3132f612478Mark Andrews#include <dns/edns.h>
821644d49b73b49f2abc5463bc53a3132f612478Mark Andrews
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence#ifdef WIN32
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer#include <Winsock2.h>
ee6fe1d1975604af266af6c370fc6193dae80fddMichael Sawyer#endif
dfd7798d8b870abf03795d8095297a4b982ab6e9Mark Andrews
533df4efdafcf7a8b7292a298f45df9ab7f7f7f9Mark Andrews#ifndef MAXHOSTNAMELEN
10bc8ffed60f064a2950527a82d7fdffe91b6206Michael Sawyer#ifdef HOST_NAME_MAX
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer#define MAXHOSTNAMELEN HOST_NAME_MAX
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer#else
5a77e9620a0b2f7417469c98be374de49d0eccc6Andreas Gustafsson#define MAXHOSTNAMELEN 256
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer#endif
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer#endif
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyerstatic void
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyerusage() {
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, "usage: feature-test <arg>\n");
1988fd60faefcc65119896996e0f33d91440b1d2Andreas Gustafsson fprintf(stderr, "args:\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --edns-version\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --enable-filter-aaaa\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --gethostname\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --gssapi\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --have-dlopen\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --have-geoip\n");
bd334e0366c0f21bf15de9282b02f1bed4ccde14Michael Sawyer fprintf(stderr, " --have-libxml2\n");
fprintf(stderr, " --ipv6only=no\n");
fprintf(stderr, " --rpz-nsdname\n");
fprintf(stderr, " --rpz-nsip\n");
fprintf(stderr, " --with-idn\n");
fprintf(stderr, " --with-lmdb\n");
}
int
main(int argc, char **argv) {
if (argc != 2) {
usage();
return (1);
}
if (strcmp(argv[1], "--enable-filter-aaaa") == 0) {
#ifdef ALLOW_FILTER_AAAA
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--edns-version") == 0) {
#ifdef DNS_EDNS_VERSION
printf("%d\n", DNS_EDNS_VERSION);
#else
printf("0\n");
#endif
return (0);
}
if (strcmp(argv[1], "--gethostname") == 0) {
char hostname[MAXHOSTNAMELEN];
int n;
#ifdef WIN32
/* From lwres InitSocket() */
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(2, 0);
err = WSAStartup( wVersionRequested, &wsaData );
if (err != 0) {
fprintf(stderr, "WSAStartup() failed: %d\n", err);
exit(1);
}
#endif
n = gethostname(hostname, sizeof(hostname));
if (n == -1) {
perror("gethostname");
return(1);
}
fprintf(stdout, "%s\n", hostname);
#ifdef WIN32
WSACleanup();
#endif
return (0);
}
if (strcmp(argv[1], "--gssapi") == 0) {
#if defined(GSSAPI)
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--have-dlopen") == 0) {
#if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN)
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--have-geoip") == 0) {
#ifdef HAVE_GEOIP
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--have-libxml2") == 0) {
#ifdef HAVE_LIBXML2
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--rpz-nsip") == 0) {
#ifdef ENABLE_RPZ_NSIP
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--rpz-nsdname") == 0) {
#ifdef ENABLE_RPZ_NSDNAME
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--with-idn") == 0) {
#ifdef WITH_IDN
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--with-lmdb") == 0) {
#ifdef HAVE_LMDB
return (0);
#else
return (1);
#endif
}
if (strcmp(argv[1], "--ipv6only=no") == 0) {
#ifdef WIN32
return (0);
#elif defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
int s;
int n = -1;
int v6only = -1;
ISC_SOCKADDR_LEN_T len = sizeof(v6only);
s = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
if (s >= 0) {
n = getsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
(void *)&v6only, &len);
close(s);
}
return ((n == 0 && v6only == 0) ? 0 : 1);
#else
return (1);
#endif
}
fprintf(stderr, "unknown arg: %s\n", argv[1]);
usage();
return (1);
}