示例#1
0
static void
setoption(char *opt) {
	if (strncasecmp(opt, "all", 3) == 0) {
		show_settings(ISC_TRUE, ISC_FALSE);
	} else if (strncasecmp(opt, "class=", 6) == 0) {
		if (testclass(&opt[6]))
			strlcpy(defclass, &opt[6], sizeof(defclass));
	} else if (strncasecmp(opt, "cl=", 3) == 0) {
		if (testclass(&opt[3]))
			strlcpy(defclass, &opt[3], sizeof(defclass));
	} else if (strncasecmp(opt, "type=", 5) == 0) {
		if (testtype(&opt[5]))
			strlcpy(deftype, &opt[5], sizeof(deftype));
	} else if (strncasecmp(opt, "ty=", 3) == 0) {
		if (testtype(&opt[3]))
			strlcpy(deftype, &opt[3], sizeof(deftype));
	} else if (strncasecmp(opt, "querytype=", 10) == 0) {
		if (testtype(&opt[10]))
			strlcpy(deftype, &opt[10], sizeof(deftype));
	} else if (strncasecmp(opt, "query=", 6) == 0) {
		if (testtype(&opt[6]))
			strlcpy(deftype, &opt[6], sizeof(deftype));
	} else if (strncasecmp(opt, "qu=", 3) == 0) {
		if (testtype(&opt[3]))
			strlcpy(deftype, &opt[3], sizeof(deftype));
	} else if (strncasecmp(opt, "q=", 2) == 0) {
		if (testtype(&opt[2]))
			strlcpy(deftype, &opt[2], sizeof(deftype));
	} else if (strncasecmp(opt, "domain=", 7) == 0) {
		strlcpy(domainopt, &opt[7], sizeof(domainopt));
		set_search_domain(domainopt);
		usesearch = ISC_TRUE;
	} else if (strncasecmp(opt, "do=", 3) == 0) {
		strlcpy(domainopt, &opt[3], sizeof(domainopt));
		set_search_domain(domainopt);
		usesearch = ISC_TRUE;
	} else if (strncasecmp(opt, "port=", 5) == 0) {
		set_port(&opt[5]);
	} else if (strncasecmp(opt, "po=", 3) == 0) {
		set_port(&opt[3]);
	} else if (strncasecmp(opt, "timeout=", 8) == 0) {
		set_timeout(&opt[8]);
	} else if (strncasecmp(opt, "t=", 2) == 0) {
		set_timeout(&opt[2]);
	} else if (strncasecmp(opt, "rec", 3) == 0) {
		recurse = ISC_TRUE;
	} else if (strncasecmp(opt, "norec", 5) == 0) {
		recurse = ISC_FALSE;
	} else if (strncasecmp(opt, "retry=", 6) == 0) {
		set_tries(&opt[6]);
	} else if (strncasecmp(opt, "ret=", 4) == 0) {
		set_tries(&opt[4]);
	} else if (strncasecmp(opt, "def", 3) == 0) {
		usesearch = ISC_TRUE;
	} else if (strncasecmp(opt, "nodef", 5) == 0) {
		usesearch = ISC_FALSE;
	} else if (strncasecmp(opt, "vc", 3) == 0) {
		tcpmode = ISC_TRUE;
	} else if (strncasecmp(opt, "novc", 5) == 0) {
		tcpmode = ISC_FALSE;
	} else if (strncasecmp(opt, "deb", 3) == 0) {
		short_form = ISC_FALSE;
		showsearch = ISC_TRUE;
	} else if (strncasecmp(opt, "nodeb", 5) == 0) {
		short_form = ISC_TRUE;
		showsearch = ISC_FALSE;
	} else if (strncasecmp(opt, "d2", 2) == 0) {
		debugging = ISC_TRUE;
	} else if (strncasecmp(opt, "nod2", 4) == 0) {
		debugging = ISC_FALSE;
	} else if (strncasecmp(opt, "search", 3) == 0) {
		usesearch = ISC_TRUE;
	} else if (strncasecmp(opt, "nosearch", 5) == 0) {
		usesearch = ISC_FALSE;
	} else if (strncasecmp(opt, "sil", 3) == 0) {
		/* deprecation_msg = ISC_FALSE; */
	} else if (strncasecmp(opt, "fail", 3) == 0) {
		nofail=ISC_FALSE;
	} else if (strncasecmp(opt, "nofail", 3) == 0) {
		nofail=ISC_TRUE;
	} else if (strncasecmp(opt, "ndots=", 6) == 0) {
		set_ndots(&opt[6]);
	} else {
		printf("*** Invalid option: %s\n", opt);
	}
}
示例#2
0
/*------------------------------------------------------------------------
 * Set the Usage information for the user...
 */
int main(int argc, char **argv)
{
FILE			*ofp = 0;
const char		*outfile = 0;
SOCKET			sockfd;
int			c;
char			errbuf[256];
struct sockaddr_in	myaddr;
int			have_targets = FALSE;
#ifdef _WIN32
int			winsock_level = 2;
#endif

	/* quick hack */
	if ( argv[1]  &&  strcmp(argv[1], "--version") == 0 )
	{
		puts(Version);
		exit(EXIT_SUCCESS);
	}

	while ( (c = getopt(argc, argv, "CHT:nfp:bt:vw:mVO:1P")) != EOF )
	{
		switch (c)
		{
		  default:	Usage(argv[0]);

		  case 'P':
#ifdef ENABLE_PERL
				gen_Perl = TRUE;
#else
				die("Sorry, -P perl support not compiled");
#endif
				break;

		  case 'C':
#ifdef SUPPORT_CIFS
				dest_portno = 445;
				break;
#else
				die("Sorry, -C not supported yet");
#endif

		  case '1':
#ifdef _WIN32
				winsock_level = 1;
#endif
				break;

		  case 'H':	gen_HTTP = TRUE;
				break;
		
		  case 'O':	outfile = optarg;
				break;

		  case 't':	set_tries( atoi(optarg) );
				break;

		  case 'V':
				puts(Version);
				exit(EXIT_SUCCESS);

		  case 'm':	show_mac_address = TRUE;
				break;

		  case 'f':	full_nbtstat = TRUE;
				break;

	 	  case 'p':	bind_portno = (unsigned short)atoi(optarg);
				break;

		  case 'b':
#if SUPPORT_BROADCAST
				broadcast = TRUE;
				break;
#else
				die("Sorry, -b broadcast not yet supported");
#endif

		  case 'v':	verbose++;
				break;

		  case 'T':	timeout_secs = atoi(optarg);
				break;

		  case 'w':	write_sleep_msecs = atoi(optarg);
				break;

		  case 'n':	no_inverse_lookup = TRUE;
				break;
		}
	}

	if ( outfile != 0 )
		ofp = fopen(outfile, "w");
	if ( ofp == 0 )
		ofp = stdout;

	if ( gen_HTTP )
		printf("Content-type: text/plain\n\n");

#if _WIN32
	init_winsock(verbose, winsock_level);
#endif

	/*----------------------------------------------------------------
	 * Run through the rest of the command line parsing the various
	 * target specifications. Each one specifies one or more targets
	 * that we're to scan, and each one gets linked into the end of
	 * the current chain.
	 */
	while ( optind < argc )
	{
	const char		*arg = argv[optind++];

		if ( ! parse_target_range(arg, errbuf) )
			die("ERROR: invalid target specification: %s", errbuf);

		have_targets++;
	}

	if ( ! have_targets )
		Usage(argv[0]);

	sockfd = socket(PF_INET, SOCK_DGRAM, 0);

	if ( ! SOCKET_IS_VALID(sockfd) )
	{
		die("ERROR: cannot create socket [%s]", NATIVE_ERROR);
	}

	/*----------------------------------------------------------------
	 * Some systems require that we specifically enable broadcast on
	 * the local network: do so if requested. It doesn't seem to work
	 * very well.
	 */
#if ENABLE_BROADCAST
	if ( broadcast )
	{
	int	b = 1;
	int	rc;

		rc = setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,
				(char *)&b,
				sizeof b);

		if ( rc != 0 )
		{
			die("ERROR: can't set SO_BROADCAST [%s]", NATIVE_ERROR);
		}
	}
#endif

	/*----------------------------------------------------------------
	 * Bind the local endpoint to receive our responses. If we use a
	 * zero, the system will pick one for us, or we can pick our own
	 * if we wish to make it easier to get past our firewall.
	 */
	memset(&myaddr, 0, sizeof myaddr);

	myaddr.sin_family      = AF_INET;
	myaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	myaddr.sin_port        = htons(bind_portno);

	if ( bind_in(sockfd, &myaddr) != 0 )
#ifdef _WIN32
		die("ERROR: cannot bind to local socket [%ld]",
			WSAGetLastError());
#else
		die("ERROR: cannot bind to local socket [%s]", strerror(errno));
#endif

	if ( verbose )
	{
		fprintf(ofp, "Bound to %s.%d\n", inet_ntoa( myaddr.sin_addr),
						ntohs( myaddr.sin_port));
	}

#ifdef ENABLE_PERL
	if ( gen_Perl ) start_perl(ofp, argv);
#endif

	query_names(ofp, sockfd);

#ifdef ENABLE_PERL
	if ( gen_Perl ) end_perl(ofp);
#endif

#if _WIN32
	WSACleanup();
#endif

	return 0;
}