while ((ch = getopt(argc, argv, "a:AdD:eqf:F:hk:nNOrRs:t:T:vx:z")) !=
while ((ch = getopt(argc, argv, "a:AdD:eqf:F:ghk:nNOrRs:t:T:vx:z")) !=
main(int argc, char *argv[]){	int error = 0;	int ch;	int mode = O_RDONLY;	int opts = 0;	if (argc < 2)		usage();	while ((ch = getopt(argc, argv, "a:AdD:eqf:F:hk:nNOrRs:t:T:vx:z")) !=		-1) {		switch (ch) {		case 'a':			anchoropt = optarg;			break;		case 'd':			opts |= PF_OPT_DISABLE;			mode = O_RDWR;			break;		case 'D':			if (pfctl_cmdline_symset(optarg) < 0)				warnx("could not parse macro definition %s",				    optarg);			break;		case 'e':			opts |= PF_OPT_ENABLE;			mode = O_RDWR;			break;		case 'q':			opts |= PF_OPT_QUIET;			break;		case 'F':			clearopt = pfctl_lookup_option(optarg, clearopt_list);			if (clearopt == NULL) {				warnx("Unknown flush modifier '%s'", optarg);				usage();			}			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 'n':			opts |= PF_OPT_NOACTION;			break;		case 'N':			loadopt &= ~PFCTL_FLAG_ALL;			loadopt |= PFCTL_FLAG_NAT;			break;		case 'r':			opts |= PF_OPT_USEDNS;			break;		case 'f':			rulesopt = optarg;			mode = O_RDWR;			break;		case 'A':			loadopt &= ~PFCTL_FLAG_ALL;			loadopt |= PFCTL_FLAG_ALTQ;			break;		case 'R':			loadopt &= ~PFCTL_FLAG_ALL;			loadopt |= PFCTL_FLAG_FILTER;			break;		case 'O':			loadopt &= ~PFCTL_FLAG_ALL;			loadopt |= PFCTL_FLAG_OPTION;			break;		case 's':			showopt = pfctl_lookup_option(optarg, showopt_list);			if (showopt == NULL) {				warnx("Unknown show modifier '%s'", optarg);				usage();			}			break;		case 't':			tableopt = optarg;			break;		case 'T':			tblcmdopt = pfctl_lookup_option(optarg, tblcmdopt_list);			if (tblcmdopt == NULL) {				warnx("Unknown table command '%s'", optarg);				usage();			}			break;		case 'v':			if (opts & PF_OPT_VERBOSE)				opts |= PF_OPT_VERBOSE2;			opts |= PF_OPT_VERBOSE;			break;		case 'x':			debugopt = pfctl_lookup_option(optarg, debugopt_list);			if (debugopt == NULL) {				warnx("Unknown debug level '%s'", optarg);				usage();			}			mode = O_RDWR;			break;		case 'z':			opts |= PF_OPT_CLRRULECTRS;			mode = O_RDWR;			break;		case 'h':			/* FALLTHROUGH */		default:			usage();			/* NOTREACHED */		}	}	if (tblcmdopt != NULL) {		argc -= optind;		argv += optind;		ch = *tblcmdopt;		if (ch == 'l') {			loadopt = PFCTL_FLAG_TABLE;			tblcmdopt = NULL;		} else {			mode = strchr("acdfkrz", ch) ? O_RDWR : O_RDONLY;			if (opts & PF_OPT_NOACTION) {				dev = open("/dev/pf", mode);				if (dev >= 0)					opts |= PF_OPT_DUMMYACTION;			}		}	} else if (argc != optind) {		warnx("unknown command line argument: %s ...", argv[optind]);		usage();		/* NOTREACHED */	}	memset(anchorname, 0, sizeof(anchorname));	memset(rulesetname, 0, sizeof(rulesetname));	if (anchoropt != NULL) {		char *t;		if ((t = strchr(anchoropt, ':')) == NULL) {			if (strlcpy(anchorname, anchoropt,			    sizeof(anchorname)) >= sizeof(anchorname))				errx(1, "anchor name '%s' too long",				    anchoropt);		} else {			char *p;			if ((p = strdup(anchoropt)) == NULL)				err(1, "anchoropt: strdup");			t = strsep(&p, ":");			if (*t == '\0' || *p == '\0')				errx(1, "anchor '%s' invalid", anchoropt);			if (strlcpy(anchorname, t, sizeof(anchorname)) >=			    sizeof(anchorname))				errx(1, "anchor name '%s' too long", t);			if (strlcpy(rulesetname, p, sizeof(rulesetname)) >=			    sizeof(rulesetname))				errx(1, "ruleset name '%s' too long", p);			free(t); /* not p */		}		if (loadopt & PFCTL_FLAG_ALL) {			loadopt &= ~PFCTL_FLAG_ALL;			loadopt |= PFCTL_FLAG_FILTER;			loadopt |= PFCTL_FLAG_NAT;		}	}	if ((opts & PF_OPT_NOACTION) == 0) {		dev = open("/dev/pf", mode);		if (dev == -1)			err(1, "/dev/pf");		altqsupport = pfctl_test_altqsupport(dev, opts);	} else {		/* turn off options */		opts &= ~ (PF_OPT_DISABLE | PF_OPT_ENABLE);		clearopt = showopt = debugopt = NULL;		altqsupport = 1;	}	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 'q':			pfctl_clear_altq(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_altq(dev, opts);			pfctl_clear_states(dev, opts);			pfctl_clear_stats(dev, opts);			pfctl_clear_tables(opts);			break;		case 'T':			pfctl_clear_tables(opts);			break;		default:			assert(0);		}	}	if (state_killers)		pfctl_kill_states(dev, opts);	if (tblcmdopt != NULL) {		error = pfctl_command_tables(argc, argv, tableopt,		    tblcmdopt, rulesopt, opts);		rulesopt = NULL;	}	if (rulesopt != NULL)		if (pfctl_rules(dev, rulesopt, opts))			error = 1;	if (showopt != NULL) {		switch (*showopt) {		case 'A':			pfctl_show_anchors(dev, opts);			break;		case 'r':			pfctl_show_rules(dev, opts, 0);			break;		case 'l':			pfctl_show_rules(dev, opts, 1);			break;		case 'n':			pfctl_show_nat(dev, opts);			break;		case 'q':			pfctl_show_altq(dev, opts & PF_OPT_VERBOSE,			    opts & PF_OPT_VERBOSE2);			break;		case 's':			pfctl_show_states(dev, 0, opts);			break;		case 'i':			pfctl_show_status(dev);			break;		case 't':			pfctl_show_timeouts(dev);			break;		case 'm':			pfctl_show_limits(dev);			break;		case 'a':			pfctl_show_rules(dev, opts, 0);			pfctl_show_nat(dev, opts);			pfctl_show_altq(dev, opts & PF_OPT_VERBOSE, 0);			pfctl_show_states(dev, 0, opts);			pfctl_show_status(dev);			pfctl_show_rules(dev, opts, 1);			pfctl_show_timeouts(dev);			pfctl_show_limits(dev);			pfctl_show_tables(opts);			break;		case 'T':			pfctl_show_tables(opts);			break;		default:			assert(0);		}	}	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:			assert(0);		}	}	if (opts & PF_OPT_CLRRULECTRS) {		if (pfctl_clear_rule_counters(dev, opts))			error = 1;	}	exit(error);}