add: chain);  if (command == CMD_CHECK && !(options&OPT_VIANAMEOUT)) exit_error(PARAMETER_PROBLEM, "Need -%c with %s\n", opt2char(OPT_VIANAMEOUT),
context: int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle){	struct ipt_entry fw, *e = NULL;	int invert = 0;	unsigned int nsaddrs = 0, ndaddrs = 0;	struct in_addr *saddrs = NULL, *daddrs = NULL;	int c, verbose = 0;	const char *chain = NULL;	const char *shostnetworkmask = NULL, *dhostnetworkmask = NULL;	const char *policy = NULL, *newname = NULL;	unsigned int rulenum = 0, options = 0, command = 0;	int ret = 1;	struct iptables_match *m;	struct iptables_target *target = NULL;	const char *jumpto = "";	char *protocol = NULL;	memset(&fw, 0, sizeof(fw));	/* Suppress error messages: we may add new options if we           demand-load a protocol. */	opterr = 0;	while ((c = getopt_long(argc, argv,	   "-A:C:D:R:I:L::F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:x",					   opts, NULL)) != -1) {		switch (c) {			/*			 * Command selection			 */		case 'A':			add_command(&command, CMD_APPEND, CMD_NONE,				    invert);			chain = optarg;			break;		case 'D':			add_command(&command, CMD_DELETE, CMD_NONE,				    invert);			chain = optarg;			if (optind < argc && argv[optind][0] != '-'			    && argv[optind][0] != '!') {				rulenum = parse_rulenumber(argv[optind++]);				command = CMD_DELETE_NUM;			}			break;		case 'C':			add_command(&command, CMD_CHECK, CMD_NONE,				    invert);			chain = optarg;			break;		case 'R':			add_command(&command, CMD_REPLACE, CMD_NONE,				    invert);			chain = optarg;			if (optind < argc && argv[optind][0] != '-'			    && argv[optind][0] != '!')				rulenum = parse_rulenumber(argv[optind++]);			else				exit_error(PARAMETER_PROBLEM,					   "-%c requires a rule number",					   cmd2char(CMD_REPLACE));			break;		case 'I':			add_command(&command, CMD_INSERT, CMD_NONE,				    invert);			chain = optarg;			if (optind < argc && argv[optind][0] != '-'			    && argv[optind][0] != '!')				rulenum = parse_rulenumber(argv[optind++]);			else rulenum = 1;			break;		case 'L':			add_command(&command, CMD_LIST, CMD_ZERO,				    invert);			if (optarg) chain = optarg;			else if (optind < argc && argv[optind][0] != '-'				 && argv[optind][0] != '!')				chain = argv[optind++];			break;		case 'F':			add_command(&command, CMD_FLUSH, CMD_NONE,				    invert);			if (optarg) chain = optarg;			else if (optind < argc && argv[optind][0] != '-'				 && argv[optind][0] != '!')				chain = argv[optind++];			break;		case 'Z':			add_command(&command, CMD_ZERO, CMD_LIST,				    invert);			if (optarg) chain = optarg;			else if (optind < argc && argv[optind][0] != '-'				&& argv[optind][0] != '!')				chain = argv[optind++];			break;		case 'N':			add_command(&command, CMD_NEW_CHAIN, CMD_NONE,				    invert);			chain = optarg;			break;		case 'X':			add_command(&command, CMD_DELETE_CHAIN, CMD_NONE,				    invert);			if (optarg) chain = optarg;			else if (optind < argc && argv[optind][0] != '-'				 && argv[optind][0] != '!')				chain = argv[optind++];			break;		case 'E':			add_command(&command, CMD_RENAME_CHAIN, CMD_NONE,				    invert);			chain = optarg;			if (optind < argc && argv[optind][0] != '-'			    && argv[optind][0] != '!')				newname = argv[optind++];			else				exit_error(PARAMETER_PROBLEM,				           "-%c requires old-chain-name and "					   "new-chain-name",					    cmd2char(CMD_RENAME_CHAIN));			break;		case 'P':			add_command(&command, CMD_SET_POLICY, CMD_NONE,				    invert);			chain = optarg;			if (optind < argc && argv[optind][0] != '-'			    && argv[optind][0] != '!')				policy = argv[optind++];			else				exit_error(PARAMETER_PROBLEM,					   "-%c requires a chain and a policy",					   cmd2char(CMD_SET_POLICY));			break;		case 'h':			if (!optarg)				optarg = argv[optind];			/* iptables -p icmp -h */			if (!iptables_matches && protocol)				find_match(protocol, TRY_LOAD);			exit_printhelp();			/*			 * Option selection			 */		case 'p':			if (check_inverse(optarg, &invert))				optind++;			set_option(&options, OPT_PROTOCOL, &fw.ip.invflags,				   invert);			/* Canonicalize into lower case */			for (protocol = argv[optind-1]; *protocol; protocol++)				*protocol = tolower(*protocol);			protocol = argv[optind-1];			fw.ip.proto = parse_protocol(protocol);			if (fw.ip.proto == 0			    && (fw.ip.invflags & IPT_INV_PROTO))				exit_error(PARAMETER_PROBLEM,					   "rule would never match protocol");			fw.nfcache |= NFC_IP_PROTO;			break;		case 's':			if (check_inverse(optarg, &invert))				optind++;			set_option(&options, OPT_SOURCE, &fw.ip.invflags,				   invert);			shostnetworkmask = argv[optind-1];			fw.nfcache |= NFC_IP_SRC;			break;		case 'd':			if (check_inverse(optarg, &invert))				optind++;			set_option(&options, OPT_DESTINATION, &fw.ip.invflags,				   invert);			dhostnetworkmask = argv[optind-1];			fw.nfcache |= NFC_IP_DST;			break;		case 'j':			set_option(&options, OPT_JUMP, &fw.ip.invflags,				   invert);			jumpto = parse_target(optarg);			target = find_target(jumpto, TRY_LOAD);			if (target) {				size_t size;				size = IPT_ALIGN(sizeof(struct ipt_entry_target)						 + target->size);				target->t = fw_calloc(1, size);				target->t->u.target_size = size;				strcpy(target->t->u.user.name, jumpto);				target->init(target->t, &fw.nfcache);			}			break;		case 'i':			if (check_inverse(optarg, &invert))				optind++;			set_option(&options, OPT_VIANAMEIN, &fw.ip.invflags,				   invert);			parse_interface(argv[optind-1],					fw.ip.iniface,					fw.ip.iniface_mask);			fw.nfcache |= NFC_IP_IF_IN;			break;		case 'o':			if (check_inverse(optarg, &invert))				optind++;			set_option(&options, OPT_VIANAMEOUT, &fw.ip.invflags,				   invert);			parse_interface(argv[optind-1],					fw.ip.outiface,					fw.ip.outiface_mask);			fw.nfcache |= NFC_IP_IF_OUT;			break;		case 'f':			set_option(&options, OPT_FRAGMENT, &fw.ip.invflags,				   invert);			fw.ip.flags |= IPT_F_FRAG;			fw.nfcache |= NFC_IP_FRAG;			break;		case 'v':			if (!verbose)				set_option(&options, OPT_VERBOSE,					   &fw.ip.invflags, invert);			verbose++;			break;		case 'm': {			size_t size;			if (invert)				exit_error(PARAMETER_PROBLEM,					   "unexpected ! flag before --match");			m = find_match(optarg, LOAD_MUST_SUCCEED);			size = IPT_ALIGN(sizeof(struct ipt_entry_match)					 + m->size);			m->m = fw_calloc(1, size);			m->m->u.match_size = size;			strcpy(m->m->u.user.name, m->name);			m->init(m->m, &fw.nfcache);		}		break;		case 'n':			set_option(&options, OPT_NUMERIC, &fw.ip.invflags,				   invert);			break;		case 't':			if (invert)				exit_error(PARAMETER_PROBLEM,					   "unexpected ! flag before --table");			*table = argv[optind-1];			break;		case 'x':			set_option(&options, OPT_EXPANDED, &fw.ip.invflags,				   invert);			break;		case 'V':			if (invert)				printf("Not %s ;-)\n", program_version);			else				printf("%s v%s\n",				       program_name, program_version);			exit(0);		case '0':			set_option(&options, OPT_LINENUMBERS, &fw.ip.invflags,				   invert);			break;		case 1: /* non option */			if (optarg[0] == '!' && optarg[1] == '\0') {				if (invert)					exit_error(PARAMETER_PROBLEM,						   "multiple consecutive ! not"						   " allowed");				invert = TRUE;				optarg[0] = '\0';				continue;			}			printf("Bad argument `%s'\n", optarg);			exit_tryhelp(2);		default:			/* FIXME: This scheme doesn't allow two of the same			   matches --RR */			if (!target			    || !(target->parse(c - target->option_offset,					       argv, invert,					       &target->tflags,					       &fw, &target->t))) {				for (m = iptables_matches; m; m = m->next) {					if (m->parse(c - m->option_offset,						     argv, invert,						     &m->mflags,						     &fw,						     &fw.nfcache,						     &m->m))						break;				}				/* If you listen carefully, you can				   actually hear this code suck. */				if (m == NULL				    && protocol				    && !find_proto(protocol, DONT_LOAD,						   options&OPT_NUMERIC)				    && (m = find_proto(protocol, TRY_LOAD,						       options&OPT_NUMERIC))) {					/* Try loading protocol */					size_t size;					size = IPT_ALIGN(sizeof(struct ipt_entry_match)							 + m->size);					m->m = fw_calloc(1, size);					m->m->u.match_size = size;					strcpy(m->m->u.user.name, m->name);					m->init(m->m, &fw.nfcache);					optind--;					continue;				}				if (!m)					exit_error(PARAMETER_PROBLEM,						   "Unknown arg `%s'",						   argv[optind-1]);			}		}		invert = FALSE;	}	for (m = iptables_matches; m; m = m->next)		m->final_check(m->mflags);	if (target)		target->final_check(target->tflags);	/* Fix me: must put inverse options checking here --MN */	if (optind < argc)		exit_error(PARAMETER_PROBLEM,			   "unknown arguments found on commandline");	if (!command)		exit_error(PARAMETER_PROBLEM, "no command specified");	if (invert)		exit_error(PARAMETER_PROBLEM,			   "nothing appropriate following !");	if (command & (CMD_REPLACE | CMD_INSERT | CMD_DELETE | CMD_APPEND |	    CMD_CHECK)) {		if (!(options & OPT_DESTINATION))			dhostnetworkmask = "0.0.0.0/0";		if (!(options & OPT_SOURCE))			shostnetworkmask = "0.0.0.0/0";	}	if (shostnetworkmask)		parse_hostnetworkmask(shostnetworkmask, &saddrs,				      &(fw.ip.smsk), &nsaddrs);	if (dhostnetworkmask)		parse_hostnetworkmask(dhostnetworkmask, &daddrs,				      &(fw.ip.dmsk), &ndaddrs);	if ((nsaddrs > 1 || ndaddrs > 1) &&	    (fw.ip.invflags & (IPT_INV_SRCIP | IPT_INV_DSTIP)))		exit_error(PARAMETER_PROBLEM, "! not allowed with multiple"			   " source or destination IP addresses");	if (command == CMD_CHECK && fw.ip.invflags != 0)		exit_error(PARAMETER_PROBLEM, "! not allowed with -%c",			   cmd2char(CMD_CHECK));	if (command == CMD_REPLACE && (nsaddrs != 1 || ndaddrs != 1))		exit_error(PARAMETER_PROBLEM, "Replacement rule does not "			   "specify a unique address");	generic_opt_check(command, options);	if (chain && strlen(chain) > IPT_FUNCTION_MAXNAMELEN)		exit_error(PARAMETER_PROBLEM,			   "chain name `%s' too long (must be under %i chars)",			   chain, IPT_FUNCTION_MAXNAMELEN);	*handle = iptc_init(*table);	if (!*handle)		exit_error(VERSION_PROBLEM,			   "can't initialize iptables table `%s': %s",			   *table, iptc_strerror(errno));	if (command == CMD_CHECK	    || command == CMD_APPEND	    || command == CMD_DELETE	    || command == CMD_INSERT	    || command == CMD_REPLACE) {		/* -o not valid with incoming packets. */		if (options & OPT_VIANAMEOUT)			if (strcmp(chain, "PREROUTING") == 0		    	    || strcmp(chain, "INPUT") == 0) {				exit_error(PARAMETER_PROBLEM,					   "Can't use -%c with %s\n",					   opt2char(OPT_VIANAMEOUT),					   chain);		}		/* -i not valid with outgoing packets */		if (options & OPT_VIANAMEIN)			if (strcmp(chain, "POSTROUTING") == 0			    || strcmp(chain, "OUTPUT") == 0) {				exit_error(PARAMETER_PROBLEM,					   "Can't use -%c with %s\n",					   opt2char(OPT_VIANAMEIN),					   chain);		}		if (target && iptc_is_chain(jumpto, *handle)) {			printf("Warning: using chain %s, not extension\n",			       jumpto);			target = NULL;		}		/* If they didn't specify a target, or it's a chain		   name, use standard. */		if (!target		    && (strlen(jumpto) == 0			|| iptc_is_chain(jumpto, *handle))) {			size_t size;			target = find_target(IPT_STANDARD_TARGET,					     LOAD_MUST_SUCCEED);			size = sizeof(struct ipt_entry_target)				+ target->size;			target->t = fw_calloc(1, size);			target->t->u.target_size = size;			strcpy(target->t->u.user.name, jumpto);			target->init(target->t, &fw.nfcache);		}		if (!target) {			struct ipt_entry_target unknown_target;			/* Don't know it.  Must be extension with no                           options? */			unknown_target.u.target_size = sizeof(unknown_target);			strcpy(unknown_target.u.user.name, jumpto);			e = generate_entry(&fw, iptables_matches,					   &unknown_target);		} else {			e = generate_entry(&fw, iptables_matches, target->t);		}	}	switch (command) {	case CMD_APPEND:		ret = append_entry(chain, e,				   nsaddrs, saddrs, ndaddrs, daddrs,				   options&OPT_VERBOSE,				   handle);		break;	case CMD_CHECK:		ret = check_packet(chain, e,				   nsaddrs, saddrs, ndaddrs, daddrs,				   options&OPT_VERBOSE, handle);		break;	case CMD_DELETE:		ret = delete_entry(chain, e,				   nsaddrs, saddrs, ndaddrs, daddrs,				   options&OPT_VERBOSE,				   handle);		break;	case CMD_DELETE_NUM:		ret = iptc_delete_num_entry(chain, rulenum - 1, handle);		break;	case CMD_REPLACE:		ret = replace_entry(chain, e, rulenum - 1,				    saddrs, daddrs, options&OPT_VERBOSE,				    handle);		break;	case CMD_INSERT:		ret = insert_entry(chain, e, rulenum - 1,				   nsaddrs, saddrs, ndaddrs, daddrs,				   options&OPT_VERBOSE,				   handle);		break;	case CMD_LIST:		ret = list_entries(chain,				   options&OPT_VERBOSE,				   options&OPT_NUMERIC,				   options&OPT_EXPANDED,				   options&OPT_LINENUMBERS,				   handle);		break;	case CMD_FLUSH:		ret = flush_entries(chain, options&OPT_VERBOSE, handle);		break;	case CMD_ZERO:		ret = zero_entries(chain, options&OPT_VERBOSE, handle);		break;	case CMD_LIST|CMD_ZERO:		ret = list_entries(chain,				   options&OPT_VERBOSE,				   options&OPT_NUMERIC,				   options&OPT_EXPANDED,				   options&OPT_LINENUMBERS,				   handle);		if (ret)			ret = zero_entries(chain,					   options&OPT_VERBOSE, handle);		break;	case CMD_NEW_CHAIN:		ret = iptc_create_chain(chain, handle);		break;	case CMD_DELETE_CHAIN:		ret = delete_chain(chain, options&OPT_VERBOSE, handle);		break;	case CMD_RENAME_CHAIN:		ret = iptc_rename_chain(chain, newname,	handle);		break;	case CMD_SET_POLICY:		ret = iptc_set_policy(chain, policy, handle);		break;	default:		/* We should never reach this... */		exit_tryhelp(2);	}	if (verbose > 1)		dump_entries(*handle);	return ret;}