extern char *optarg; extern int optind;
main(int argc, char *argv[]){	extern char *optarg;	extern int optind;	int error = 0;	int dev = -1;	int ch;	int mode = O_RDONLY;	if (argc < 2)		usage();	while ((ch = getopt(argc, argv, "deqF:hk:l:m:nN:O:rR:s:t:vx:z")) != -1)	{		switch (ch) {		case 'd':			opts |= PF_OPT_DISABLE;			mode = O_RDWR;			break;		case 'e':			opts |= PF_OPT_ENABLE;			mode = O_RDWR;			break;		case 'q':			opts |= PF_OPT_QUIET;			break;		case 'F':			clearopt = optarg;			mode = O_RDWR;			break;		case 'k':			if (state_killers >= 2) {				warnx("can only specify -k twice");				usage();				/* NOTREACHED */			}			state_kill[state_killers++] = optarg;			mode = O_RDWR;			break;		case 'l':			logopt = optarg;			mode = O_RDWR;			break;		case 'm':			limitopt = optarg;			if (strchr(limitopt, '=') != NULL)				mode = O_RDWR;			break;		case 'n':			opts |= PF_OPT_NOACTION;			break;		case 'N':			natopt = optarg;			mode = O_RDWR;			break;		case 'O':			hintopt = optarg;			mode = O_RDWR;			break;		case 'r':			opts |= PF_OPT_USEDNS;			break;		case 'R':			rulesopt = optarg;			mode = O_RDWR;			break;		case 's':			showopt = optarg;			break;		case 't':			timeoutopt = optarg;			if (strchr(timeoutopt, '=') != NULL)				mode = O_RDWR;			break;		case 'v':			opts |= PF_OPT_VERBOSE;			break;		case 'x':			debugopt = optarg;			mode = O_RDWR;			break;		case 'z':			opts |= PF_OPT_CLRRULECTRS;			mode = O_RDWR;			break;		case 'h':		default:			usage();			/* NOTREACHED */		}	}	if (argc != optind) {		warnx("unknown command line argument: %s ...", argv[optind]);		usage();		/* NOTREACHED */	}	if (opts & PF_OPT_NOACTION)		mode = O_RDONLY;	if ((opts & PF_OPT_NOACTION) == 0) {		dev = open("/dev/pf", mode);		if (dev == -1)			err(1, "open(\"/dev/pf\")");	} else {		/* turn off options */		opts &= ~ (PF_OPT_DISABLE | PF_OPT_ENABLE);		clearopt = logopt = showopt = debugopt = NULL;	}	if (opts & PF_OPT_DISABLE)		if (pfctl_disable(dev, opts))			error = 1;	if (clearopt != NULL) {		switch (*clearopt) {		case 'r':			pfctl_clear_rules(dev, opts);			break;		case 'n':			pfctl_clear_nat(dev, opts);			break;		case 's':			pfctl_clear_states(dev, opts);			break;		case 'i':			pfctl_clear_stats(dev, opts);			break;		case 'a':			pfctl_clear_rules(dev, opts);			pfctl_clear_nat(dev, opts);			pfctl_clear_states(dev, opts);			pfctl_clear_stats(dev, opts);			break;		default:			warnx("Unknown flush modifier '%s'", clearopt);			error = 1;		}	}	if (state_killers)		pfctl_kill_states(dev, opts);	if (rulesopt != NULL)		if (pfctl_rules(dev, rulesopt, opts))			error = 1;	if (natopt != NULL)		if (pfctl_nat(dev, natopt, opts))			error = 1;	if (showopt != NULL) {		switch (*showopt) {		case 'r':			pfctl_show_rules(dev, opts, 0);			break;		case 'l':			pfctl_show_rules(dev, opts, 1);			break;		case 'n':			pfctl_show_nat(dev);			break;		case 's':			pfctl_show_states(dev, 0, opts);			break;		case 'i':			pfctl_show_status(dev);			break;		case 'a':			pfctl_show_rules(dev, opts, 0);			pfctl_show_nat(dev);			pfctl_show_states(dev, 0, opts);			pfctl_show_status(dev);			break;		default:			warnx("Unknown show modifier '%s'", showopt);			error = 1;		}	}	if (logopt != NULL)		if (pfctl_log(dev, logopt, opts))			error = 1;	if (hintopt != NULL)		if (pfctl_hint(dev, hintopt, opts))			error = 1;	if (timeoutopt != NULL)		if (pfctl_timeout(dev, timeoutopt, opts))			error = 1;	if (limitopt != NULL)		if (pfctl_limit(dev, limitopt, opts))			error = 1;	if (opts & PF_OPT_ENABLE)		if (pfctl_enable(dev, opts))			error = 1;	if (debugopt != NULL) {		switch (*debugopt) {		case 'n':			pfctl_debug(dev, PF_DEBUG_NONE, opts);			break;		case 'u':			pfctl_debug(dev, PF_DEBUG_URGENT, opts);			break;		case 'm':			pfctl_debug(dev, PF_DEBUG_MISC, opts);			break;		default:			warnx("Unknown debug level '%s'", debugopt);			error = 1;		}	}	if (opts & PF_OPT_CLRRULECTRS) {		if (pfctl_clear_rule_counters(dev, opts))			error = 1;	}	close(dev);	exit(error);}