static void parse_command_line(int argc, char *argv[]) { int ch; int port; isc_boolean_t disable6 = ISC_FALSE; isc_boolean_t disable4 = ISC_FALSE; save_command_line(argc, argv); isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, "46c:C:d:E:fFgi:lm:n:N:p:P:" "sS:t:T:u:vVx:")) != -1) { switch (ch) { case '4': if (disable4) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv4() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv4 not supported by OS"); isc_net_disableipv6(); disable6 = ISC_TRUE; break; case '6': if (disable6) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv6() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv6 not supported by OS"); isc_net_disableipv4(); disable4 = ISC_TRUE; break; case 'c': ns_g_conffile = isc_commandline_argument; lwresd_g_conffile = isc_commandline_argument; if (lwresd_g_useresolvconf) ns_main_earlyfatal("cannot specify -c and -C"); ns_g_conffileset = ISC_TRUE; break; case 'C': lwresd_g_resolvconffile = isc_commandline_argument; if (ns_g_conffileset) ns_main_earlyfatal("cannot specify -c and -C"); lwresd_g_useresolvconf = ISC_TRUE; break; case 'd': ns_g_debuglevel = parse_int(isc_commandline_argument, "debug level"); break; case 'E': ns_g_engine = isc_commandline_argument; break; case 'f': ns_g_foreground = ISC_TRUE; break; case 'g': ns_g_foreground = ISC_TRUE; ns_g_logstderr = ISC_TRUE; break; /* XXXBEW -i should be removed */ case 'i': lwresd_g_defaultpidfile = isc_commandline_argument; break; case 'l': ns_g_lwresdonly = ISC_TRUE; break; case 'm': set_flags(isc_commandline_argument, mem_debug_flags, &isc_mem_debugging); break; case 'N': /* Deprecated. */ case 'n': ns_g_cpus = parse_int(isc_commandline_argument, "number of cpus"); if (ns_g_cpus == 0) ns_g_cpus = 1; break; case 'p': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); ns_g_port = port; break; /* XXXBEW Should -P be removed? */ case 'P': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); lwresd_g_listenport = port; break; case 's': /* XXXRTH temporary syntax */ want_stats = ISC_TRUE; break; case 'S': maxsocks = parse_int(isc_commandline_argument, "max number of sockets"); break; case 't': /* XXXJAB should we make a copy? */ ns_g_chrootdir = isc_commandline_argument; break; case 'T': /* * clienttest: make clients single shot with their * own memory context. */ if (!strcmp(isc_commandline_argument, "clienttest")) ns_g_clienttest = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "maxudp512")) maxudp = 512; else if (!strcmp(isc_commandline_argument, "maxudp1460")) maxudp = 1460; else fprintf(stderr, "unknown -T flag '%s\n", isc_commandline_argument); break; case 'u': ns_g_username = isc_commandline_argument; break; case 'v': printf("BIND %s\n", ns_g_version); exit(0); case 'V': printf("BIND %s built with %s\n", ns_g_version, ns_g_configargs); exit(0); case 'F': /* Reserved for FIPS mode */ /* FALLTHROUGH */ case '?': usage(); if (isc_commandline_option == '?') exit(0); ns_main_earlyfatal("unknown option '-%c'", isc_commandline_option); /* FALLTHROUGH */ default: ns_main_earlyfatal("parsing options returned %d", ch); } } argc -= isc_commandline_index; argv += isc_commandline_index; if (argc > 0) { usage(); ns_main_earlyfatal("extra command line arguments"); } }
static void parse_command_line(int argc, char *argv[]) { int ch; int port; const char *p; save_command_line(argc, argv); /* * NS_MAIN_ARGS is defined in main.h, so that it can be used * both by named and by ntservice hooks. */ isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, NS_MAIN_ARGS)) != -1) { switch (ch) { case '4': if (ns_g_disable4) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv4() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv4 not supported by OS"); isc_net_disableipv6(); ns_g_disable6 = ISC_TRUE; break; case '6': if (ns_g_disable6) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv6() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv6 not supported by OS"); isc_net_disableipv4(); ns_g_disable4 = ISC_TRUE; break; case 'c': ns_g_conffile = isc_commandline_argument; lwresd_g_conffile = isc_commandline_argument; if (lwresd_g_useresolvconf) ns_main_earlyfatal("cannot specify -c and -C"); ns_g_conffileset = ISC_TRUE; break; case 'C': lwresd_g_resolvconffile = isc_commandline_argument; if (ns_g_conffileset) ns_main_earlyfatal("cannot specify -c and -C"); lwresd_g_useresolvconf = ISC_TRUE; break; case 'd': ns_g_debuglevel = parse_int(isc_commandline_argument, "debug level"); break; case 'D': /* Descriptive comment for 'ps'. */ break; case 'E': ns_g_engine = isc_commandline_argument; break; case 'f': ns_g_foreground = ISC_TRUE; break; case 'g': ns_g_foreground = ISC_TRUE; ns_g_logstderr = ISC_TRUE; break; /* XXXBEW -i should be removed */ case 'i': lwresd_g_defaultpidfile = isc_commandline_argument; break; case 'l': ns_g_lwresdonly = ISC_TRUE; break; case 'M': if (strcmp(isc_commandline_argument, "external") == 0) isc_mem_defaultflags = 0; break; case 'm': set_flags(isc_commandline_argument, mem_debug_flags, &isc_mem_debugging); break; case 'N': /* Deprecated. */ case 'n': ns_g_cpus = parse_int(isc_commandline_argument, "number of cpus"); if (ns_g_cpus == 0) ns_g_cpus = 1; break; case 'p': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); ns_g_port = port; break; /* XXXBEW Should -P be removed? */ case 'P': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); lwresd_g_listenport = port; break; case 's': /* XXXRTH temporary syntax */ want_stats = ISC_TRUE; break; case 'S': maxsocks = parse_int(isc_commandline_argument, "max number of sockets"); break; case 't': /* XXXJAB should we make a copy? */ ns_g_chrootdir = isc_commandline_argument; break; case 'T': /* NOT DOCUMENTED */ /* * force the server to behave (or misbehave) in * specified ways for testing purposes. * * clienttest: make clients single shot with their * own memory context. * delay=xxxx: delay client responses by xxxx ms to * simulate remote servers. * dscp=x: check that dscp values are as * expected and assert otherwise. */ if (!strcmp(isc_commandline_argument, "clienttest")) ns_g_clienttest = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "nosoa")) ns_g_nosoa = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "noaa")) ns_g_noaa = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "maxudp512")) maxudp = 512; else if (!strcmp(isc_commandline_argument, "maxudp1460")) maxudp = 1460; else if (!strcmp(isc_commandline_argument, "dropedns")) ns_g_dropedns = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "noedns")) ns_g_noedns = ISC_TRUE; else if (!strncmp(isc_commandline_argument, "maxudp=", 7)) maxudp = atoi(isc_commandline_argument + 7); else if (!strncmp(isc_commandline_argument, "delay=", 6)) ns_g_delay = atoi(isc_commandline_argument + 6); else if (!strcmp(isc_commandline_argument, "nosyslog")) ns_g_nosyslog = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "nonearest")) ns_g_nonearest = ISC_TRUE; else if (!strncmp(isc_commandline_argument, "dscp=", 5)) isc_dscp_check_value = atoi(isc_commandline_argument + 5); else if (!strncmp(isc_commandline_argument, "mkeytimers=", 11)) { p = strtok(isc_commandline_argument + 11, "/"); if (p == NULL) ns_main_earlyfatal("bad mkeytimer"); dns_zone_mkey_hour = atoi(p); if (dns_zone_mkey_hour == 0) ns_main_earlyfatal("bad mkeytimer"); p = strtok(NULL, "/"); if (p == NULL) { dns_zone_mkey_day = (24 * dns_zone_mkey_hour); dns_zone_mkey_month = (30 * dns_zone_mkey_day); break; } dns_zone_mkey_day = atoi(p); if (dns_zone_mkey_day < dns_zone_mkey_hour) ns_main_earlyfatal("bad mkeytimer"); p = strtok(NULL, "/"); if (p == NULL) { dns_zone_mkey_month = (30 * dns_zone_mkey_day); break; } dns_zone_mkey_month = atoi(p); if (dns_zone_mkey_month < dns_zone_mkey_day) ns_main_earlyfatal("bad mkeytimer"); } else if (!strcmp(isc_commandline_argument, "notcp")) ns_g_notcp = ISC_TRUE; else fprintf(stderr, "unknown -T flag '%s\n", isc_commandline_argument); break; case 'U': ns_g_udpdisp = parse_int(isc_commandline_argument, "number of UDP listeners " "per interface"); break; case 'u': ns_g_username = isc_commandline_argument; break; case 'v': printf("%s %s%s%s <id:%s>\n", ns_g_product, ns_g_version, (*ns_g_description != '\0') ? " " : "", ns_g_description, ns_g_srcid); exit(0); case 'V': printf("%s %s%s%s <id:%s>\n", ns_g_product, ns_g_version, (*ns_g_description != '\0') ? " " : "", ns_g_description, ns_g_srcid); printf("running on %s\n", ns_os_uname()); printf("built by %s with %s\n", ns_g_builder, ns_g_configargs); #ifdef __clang__ printf("compiled by CLANG %s\n", __VERSION__); #else #if defined(__ICC) || defined(__INTEL_COMPILER) printf("compiled by ICC %s\n", __VERSION__); #else #ifdef __GNUC__ printf("compiled by GCC %s\n", __VERSION__); #endif #endif #endif #ifdef _MSC_VER printf("compiled by MSVC %d\n", _MSC_VER); #endif #ifdef __SUNPRO_C printf("compiled by Solaris Studio %x\n", __SUNPRO_C); #endif #ifdef OPENSSL printf("compiled with OpenSSL version: %s\n", OPENSSL_VERSION_TEXT); printf("linked to OpenSSL version: %s\n", SSLeay_version(SSLEAY_VERSION)); #endif #ifdef HAVE_LIBXML2 printf("compiled with libxml2 version: %s\n", LIBXML_DOTTED_VERSION); printf("linked to libxml2 version: %s\n", xmlParserVersion); #endif #if defined(HAVE_JSON) && defined(JSON_C_VERSION) printf("compiled with libjson-c version: %s\n", JSON_C_VERSION); printf("linked to libjson-c version: %s\n", json_c_version()); #endif exit(0); case 'F': /* Reserved for FIPS mode */ /* FALLTHROUGH */ case '?': usage(); if (isc_commandline_option == '?') exit(0); p = strchr(NS_MAIN_ARGS, isc_commandline_option); if (p == NULL || *++p != ':') ns_main_earlyfatal("unknown option '-%c'", isc_commandline_option); else ns_main_earlyfatal("option '-%c' requires " "an argument", isc_commandline_option); /* FALLTHROUGH */ default: ns_main_earlyfatal("parsing options returned %d", ch); } } argc -= isc_commandline_index; argv += isc_commandline_index; POST(argv); if (argc > 0) { usage(); ns_main_earlyfatal("extra command line arguments"); } }
static void parse_command_line(int argc, char *argv[]) { int ch; int port; const char *p; isc_boolean_t disable6 = ISC_FALSE; isc_boolean_t disable4 = ISC_FALSE; save_command_line(argc, argv); /* PLEASE keep options synchronized when main is hooked! */ #define CMDLINE_FLAGS "46c:C:d:D:E:fFgi:lm:n:N:p:P:sS:t:T:U:u:vVx:" isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) { switch (ch) { case '4': if (disable4) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv4() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv4 not supported by OS"); isc_net_disableipv6(); disable6 = ISC_TRUE; break; case '6': if (disable6) ns_main_earlyfatal("cannot specify -4 and -6"); if (isc_net_probeipv6() != ISC_R_SUCCESS) ns_main_earlyfatal("IPv6 not supported by OS"); isc_net_disableipv4(); disable4 = ISC_TRUE; break; case 'c': ns_g_conffile = isc_commandline_argument; lwresd_g_conffile = isc_commandline_argument; if (lwresd_g_useresolvconf) ns_main_earlyfatal("cannot specify -c and -C"); ns_g_conffileset = ISC_TRUE; break; case 'C': lwresd_g_resolvconffile = isc_commandline_argument; if (ns_g_conffileset) ns_main_earlyfatal("cannot specify -c and -C"); lwresd_g_useresolvconf = ISC_TRUE; break; case 'd': ns_g_debuglevel = parse_int(isc_commandline_argument, "debug level"); break; case 'D': /* Descriptive comment for 'ps'. */ break; case 'E': ns_g_engine = isc_commandline_argument; break; case 'f': ns_g_foreground = ISC_TRUE; break; case 'g': ns_g_foreground = ISC_TRUE; ns_g_logstderr = ISC_TRUE; break; /* XXXBEW -i should be removed */ case 'i': lwresd_g_defaultpidfile = isc_commandline_argument; break; case 'l': ns_g_lwresdonly = ISC_TRUE; break; case 'm': set_flags(isc_commandline_argument, mem_debug_flags, &isc_mem_debugging); break; case 'N': /* Deprecated. */ case 'n': ns_g_cpus = parse_int(isc_commandline_argument, "number of cpus"); if (ns_g_cpus == 0) ns_g_cpus = 1; break; case 'p': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); ns_g_port = port; break; /* XXXBEW Should -P be removed? */ case 'P': port = parse_int(isc_commandline_argument, "port"); if (port < 1 || port > 65535) ns_main_earlyfatal("port '%s' out of range", isc_commandline_argument); lwresd_g_listenport = port; break; case 's': /* XXXRTH temporary syntax */ want_stats = ISC_TRUE; break; case 'S': maxsocks = parse_int(isc_commandline_argument, "max number of sockets"); break; case 't': /* XXXJAB should we make a copy? */ ns_g_chrootdir = isc_commandline_argument; break; case 'T': /* NOT DOCUMENTED */ /* * force the server to behave (or misbehave) in * specified ways for testing purposes. * * clienttest: make clients single shot with their * own memory context. * delay=xxxx: delay client responses by xxxx ms to * simulate remote servers. * dscp=x: check that dscp values are as * expected and assert otherwise. */ if (!strcmp(isc_commandline_argument, "clienttest")) ns_g_clienttest = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "nosoa")) ns_g_nosoa = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "noaa")) ns_g_noaa = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "maxudp512")) maxudp = 512; else if (!strcmp(isc_commandline_argument, "maxudp1460")) maxudp = 1460; else if (!strcmp(isc_commandline_argument, "dropedns")) ns_g_dropedns = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "noedns")) ns_g_noedns = ISC_TRUE; else if (!strncmp(isc_commandline_argument, "maxudp=", 7)) maxudp = atoi(isc_commandline_argument + 7); else if (!strncmp(isc_commandline_argument, "delay=", 6)) ns_g_delay = atoi(isc_commandline_argument + 6); else if (!strcmp(isc_commandline_argument, "nosyslog")) ns_g_nosyslog = ISC_TRUE; else if (!strcmp(isc_commandline_argument, "nonearest")) ns_g_nonearest = ISC_TRUE; else if (!strncmp(isc_commandline_argument, "dscp=", 5)) isc_dscp_check_value = atoi(isc_commandline_argument + 5); else fprintf(stderr, "unknown -T flag '%s\n", isc_commandline_argument); break; case 'U': ns_g_udpdisp = parse_int(isc_commandline_argument, "number of UDP listeners " "per interface"); break; case 'u': ns_g_username = isc_commandline_argument; break; case 'v': printf("%s %s", ns_g_product, ns_g_version); if (*ns_g_description != 0) printf(" %s", ns_g_description); printf("\n"); exit(0); case 'V': printf("%s %s", ns_g_product, ns_g_version); if (*ns_g_description != 0) printf(" %s", ns_g_description); printf(" <id:%s> built by %s with %s\n", ns_g_srcid, ns_g_builder, ns_g_configargs); #ifdef __clang__ printf("compiled by CLANG %s\n", __VERSION__); #else #if defined(__ICC) || defined(__INTEL_COMPILER) printf("compiled by ICC %s\n", __VERSION__); #else #ifdef __GNUC__ printf("compiled by GCC %s\n", __VERSION__); #endif #endif #endif #ifdef _MSC_VER printf("compiled by MSVC %d\n", _MSC_VER); #endif #ifdef __SUNPRO_C printf("compiled by Solaris Studio %x\n", __SUNPRO_C); #endif #ifdef OPENSSL printf("using OpenSSL version: %s\n", OPENSSL_VERSION_TEXT); #endif #ifdef HAVE_LIBXML2 printf("using libxml2 version: %s\n", LIBXML_DOTTED_VERSION); #endif exit(0); case 'F': /* Reserved for FIPS mode */ /* FALLTHROUGH */ case '?': usage(); if (isc_commandline_option == '?') exit(0); p = strchr(CMDLINE_FLAGS, isc_commandline_option); if (p == NULL || *++p != ':') ns_main_earlyfatal("unknown option '-%c'", isc_commandline_option); else ns_main_earlyfatal("option '-%c' requires " "an argument", isc_commandline_option); /* FALLTHROUGH */ default: ns_main_earlyfatal("parsing options returned %d", ch); } } argc -= isc_commandline_index; argv += isc_commandline_index; POST(argv); if (argc > 0) { usage(); ns_main_earlyfatal("extra command line arguments"); } }