コード例 #1
0
ファイル: ipv6cp.c プロジェクト: vstakhov/mpd
static int
Ipv6cpSetCommand(Context ctx, int ac, char *av[], void *arg)
{
	Ipv6cpState const ipv6cp = &ctx->bund->ipv6cp;

	if (ac == 0)
		return (-1);
	switch ((intptr_t)arg) {
	case SET_ACCEPT:
		AcceptCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_DENY:
		DenyCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_ENABLE:
		EnableCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_DISABLE:
		DisableCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_YES:
		YesCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_NO:
		NoCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	default:
		assert(0);
	}
	return (0);
}
コード例 #2
0
ファイル: ipcp.c プロジェクト: ZRouter/ZRouter
static int
IpcpSetCommand(Context ctx, int ac, char *av[], void *arg)
{
  IpcpState		const ipcp = &ctx->bund->ipcp;
  struct in_addr	*ips;

  if (ac == 0)
    return(-1);
  switch ((intptr_t)arg) {
    case SET_RANGES:
      {
	struct u_range	self_new_allow;
	struct u_range	peer_new_allow;
	int pos = 0, self_new_pool = -1, peer_new_pool = -1;

	/* Parse args */
	if (ac < 2)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    self_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &self_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos >= ac)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    if ((pos + 1) >= ac)
		return (-1);
	    peer_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &peer_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos != ac)
	    return (-1);

	if (self_new_pool >= 0)
	    strlcpy(ipcp->conf.self_ippool, av[self_new_pool], sizeof(ipcp->conf.self_ippool));
	else
	    ipcp->conf.self_ippool[0] = 0;
	if (peer_new_pool >= 0)
	    strlcpy(ipcp->conf.ippool, av[peer_new_pool], sizeof(ipcp->conf.ippool));
	else
	    ipcp->conf.ippool[0] = 0;
	ipcp->conf.self_allow = self_new_allow;
	ipcp->conf.peer_allow = peer_new_allow;

      }
      break;

    case SET_DNS:
      ips = ipcp->conf.peer_dns;
      goto getPrimSec;
      break;
    case SET_NBNS:
      ips = ipcp->conf.peer_nbns;
getPrimSec:
      if (!inet_aton(av[0], &ips[0]))
	Error("invalid IP address: \'%s\'", av[0]);
      ips[1].s_addr = 0;
      if (ac > 1 && !inet_aton(av[1], &ips[1]))
	Error("invalid IP address: \'%s\'", av[1]);
      break;

    case SET_ACCEPT:
      AcceptCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DENY:
      DenyCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_ENABLE:
      EnableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DISABLE:
      DisableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_YES:
      YesCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_NO:
      NoCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    default:
      assert(0);
  }
  return(0);
}