Пример #1
0
static void
parse_ah_spis(const char *spistring, u_int32_t *spis)
{
	char *buffer;
	char *cp;

	buffer = strdup(spistring);
	if ((cp = strchr(buffer, ':')) == NULL)
		spis[0] = spis[1] = parse_ah_spi(buffer);
	else {
		*cp = '\0';
		cp++;

		spis[0] = buffer[0] ? parse_ah_spi(buffer) : 0;
		spis[1] = cp[0] ? parse_ah_spi(cp) : 0xFFFFFFFF;
	}
	free(buffer);
}
Пример #2
0
/* Function which parses command options; returns true if it
   ate an option */
static int
parse(int c, char **argv, int invert, unsigned int *flags,
      const struct ip6t_entry *entry,
      unsigned int *nfcache,
      struct ip6t_entry_match **match)
{
	struct ip6t_ah *ahinfo = (struct ip6t_ah *)(*match)->data;

	switch (c) {
	case '1':
		if (*flags & IP6T_AH_SPI)
			exit_error(PARAMETER_PROBLEM,
				   "Only one `--ahspi' allowed");
		check_inverse(optarg, &invert, &optind, 0);
		parse_ah_spis(argv[optind-1], ahinfo->spis);
		if (invert)
			ahinfo->invflags |= IP6T_AH_INV_SPI;
		*flags |= IP6T_AH_SPI;
		break;
	case '2':
		if (*flags & IP6T_AH_LEN)
			exit_error(PARAMETER_PROBLEM,
				   "Only one `--ahlen' allowed");
		check_inverse(optarg, &invert, &optind, 0);
		ahinfo->hdrlen = parse_ah_spi(argv[optind-1], "length");
		if (invert)
			ahinfo->invflags |= IP6T_AH_INV_LEN;
		*flags |= IP6T_AH_LEN;
		break;
	case '3':
		if (*flags & IP6T_AH_RES)
			exit_error(PARAMETER_PROBLEM,
				   "Only one `--ahres' allowed");
		ahinfo->hdrres = 1;
		*flags |= IP6T_AH_RES;
		break;
	default:
		return 0;
	}

	return 1;
}