Esempio n. 1
0
int
EncryptType(char *type, char *mode)
{
	Encryptions *ep;
	int ret = 0;

	if (isprefix(type, "help") || isprefix(type, "?")) {
		printf("Usage: encrypt type <type> [input|output]\n");
		encrypt_list_types();
	} else if ((ep = (Encryptions *)genget(type, (char **)encryptions,
						sizeof(Encryptions))) == 0) {
		printf("%s: invalid encryption type\n", type);
	} else if (Ambiguous((char **)ep)) {
		printf("Ambiguous type '%s'\n", type);
	} else {
		if ((mode == 0) || isprefix(mode, "input")) {
			decrypt_mode = ep->type;
			i_wont_support_decrypt &= ~typemask(ep->type);
			ret = 1;
		}
		if ((mode == 0) || isprefix(mode, "output")) {
			encrypt_mode = ep->type;
			i_wont_support_encrypt &= ~typemask(ep->type);
			ret = 1;
		}
		if (ret == 0)
			printf("%s: invalid encryption mode\n", mode);
	}
	return(ret);
}
Esempio n. 2
0
int
EncryptDisable(char *type, char *mode)
{
	Encryptions *ep;
	int ret = 0;

	if (isprefix(type, "help") || isprefix(type, "?")) {
		printf("Usage: encrypt disable <type> [input|output]\n");
		encrypt_list_types();
	} else if ((ep = (Encryptions *)genget(type, (char **)encryptions,
						sizeof(Encryptions))) == NULL) {
		printf("%s: invalid encryption type\n", type);
	} else if (Ambiguous((char **)ep)) {
		printf("Ambiguous type '%s'\n", type);
	} else {
		if ((mode == NULL) || (isprefix(mode, "input") ? 1 : 0)) {
			if (decrypt_mode == ep->type)
				EncryptStopInput();
			i_wont_support_decrypt |= typemask(ep->type);
			ret = 1;
		}
		if ((mode == NULL) || (isprefix(mode, "output"))) {
			if (encrypt_mode == ep->type)
				EncryptStopOutput();
			i_wont_support_encrypt |= typemask(ep->type);
			ret = 1;
		}
		if (ret == 0)
			printf("%s: invalid encryption mode\n", mode);
	}
	return(ret);
}
Esempio n. 3
0
namespace CopyCtorIssues {
  struct Private {
    Private();
  private:
    Private(const Private&); // expected-note {{declared private here}}
  };
  struct NoViable {
    NoViable(); // expected-note {{not viable}}
    NoViable(NoViable&); // expected-note {{not viable}}
  };
  struct Ambiguous {
    Ambiguous();
    Ambiguous(const Ambiguous &, int = 0); // expected-note {{candidate}}
    Ambiguous(const Ambiguous &, double = 0); // expected-note {{candidate}}
  };
  struct Deleted {
    Private p; // expected-note {{implicitly deleted}}
  };

  const Private &a = Private(); // expected-warning {{copying variable of type 'CopyCtorIssues::Private' when binding a reference to a temporary would invoke an inaccessible constructor in C++98}}
  const NoViable &b = NoViable(); // expected-warning {{copying variable of type 'CopyCtorIssues::NoViable' when binding a reference to a temporary would find no viable constructor in C++98}}
#if !CXX98
  const Ambiguous &c = Ambiguous(); // expected-warning {{copying variable of type 'CopyCtorIssues::Ambiguous' when binding a reference to a temporary would find ambiguous constructors in C++98}}
#endif
  const Deleted &d = Deleted(); // expected-warning {{copying variable of type 'CopyCtorIssues::Deleted' when binding a reference to a temporary would invoke a deleted constructor in C++98}}
}
Esempio n. 4
0
File: complete.c Progetto: danrl/nsh
/*
 * Generic complete routine
 */
unsigned char
complete(EditLine *el, int ch, char **table, size_t stlen, char *arg)
{
	static char word[256];
	static int lastc_argc, lastc_argo;
	struct ghs *c;
	const LineInfo *lf;
	int celems, dolist;
	size_t len;

	ch = ch;		/* not used */
	lf = el_line(el);
	len = lf->lastchar - lf->buffer;
	if (len >= sizeof(line))
		return (CC_ERROR);
	(void)memcpy(line, lf->buffer, len);
	line[len] = '\0';
	cursor_pos = line + (lf->cursor - lf->buffer);
	lastc_argc = cursor_argc;	/* remember last cursor pos */
	lastc_argo = cursor_argo;
	makeargv();			/* build argc/argv of current line */

	if (cursor_argo >= sizeof(word))
		return (CC_ERROR);

	dolist = 0;

	/* if cursor and word is same, list alternatives */
	if (lastc_argc == cursor_argc && lastc_argo == cursor_argo
	    && strncmp(word, margv[cursor_argc], cursor_argo) == 0)
		dolist = 1;
	else if (cursor_argo)
		memcpy(word, margv[cursor_argc], cursor_argo);
	word[cursor_argo] = '\0';

	if (cursor_argc == 0)
		return (complete_command(word, dolist, el, table, stlen));

	if (arg == NULL)
		arg = margv[0];
	c = (struct ghs *) genget(arg, table, stlen);
	if (c == (struct ghs *)-1 || c == 0 || Ambiguous(c))
		return (CC_ERROR);
	celems = strlen(c->complete);

	/* check for 'continuation' completes (which are uppercase) */
	if ((cursor_argc > celems) && (celems > 0)
	    && isupper(c->complete[celems-1]))
		cursor_argc = celems;

	if (cursor_argc > celems)
		return (CC_ERROR);

	return(complete_args(c, word, dolist, el, table, stlen,
	    cursor_argc - 1));
}
Esempio n. 5
0
File: sysctl.c Progetto: danrl/nsh
int
ipsysctl(int set, char *cmd, char *arg, int type)
{
	int32_t larg;
	const char *errmsg = NULL;
	struct ipsysctl *x;
	struct sysctltab *stab;

	for (stab = sysctls; stab-> name != NULL; stab++)
		if(stab->pf == type)
			break;
	if (stab->pf != type) {
		printf("%% table lookup failed (%d)\n", type);
		return 0;
	}

	x = (struct ipsysctl *) genget(cmd, (char **)stab->sysctl,
	    sizeof(struct ipsysctl));
	if (x == 0) {
		printf("%% Invalid argument %s\n", cmd);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Ambiguous argument %s\n", cmd);
		return 0;
	}

	if (set) {
		if (arg) {
			larg = strtonum(arg, 0, INT_MAX, &errmsg);
			if (errmsg) {
				printf("%% Invalid argument %s: %s\n", arg,
				    errmsg);
				return(0);
			}
		} else
			larg = 1;
	} else
		larg = x->def_larg;

	sysctl_int(x->mib, larg, 0);

	return(1);
}
Esempio n. 6
0
File: complete.c Progetto: danrl/nsh
/*
 * Complete a (sub)command
 */
static unsigned char
complete_subcommand(char *word, int list, EditLine *el, char **table, int stlen)
{
	struct ghs *ghs = NULL;

	if (table == NULL)
		return(CC_ERROR);

	ghs = (struct ghs *)genget(margv[cursor_argc-1], table, stlen);
	if (ghs == 0 || Ambiguous(ghs))
		return(CC_ERROR);

	/*
	 * XXX completion lists that hit subcommand tables don't get more than
	 * the first CMPL arg tested in complete_args as long as the level
	 * 0 is passed to complete_args
	 */
	return(complete_args(ghs, word, list, el, table, stlen, 0));
}
Esempio n. 7
0
int
brpri(char *ifname, int ifs, int argc, char **argv)   
{
	int set, val;
	const char *errmsg = NULL;
	struct brd *x;
         
	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	x = (struct brd *) genget(argv[0], (char **)brds, sizeof(struct brd));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argv++;
	argc--;

	/*
	 * the ifpriority value is ignored for 'no ifpriority' but
	 * we allow it anyways to retain compatibility with the 
	 * set form of this command
	 */
	if ((set && argc != 2) || (!set && (argc < 1 || argc > 2))) {
		printf("%% %s <member> <%s>\n", x->name, x->descr);
		printf("%% no %s <member> [%s]\n", x->name, x->descr);
		return(0);
	}

	if (!is_valid_ifname(argv[0]) || is_bridge(ifs, argv[0]))
	{
		printf("%% invalid member name: %s", argv[0]);
		return(0);
	}

	errno = 0;
	val = strtonum(argv[1], 0, 0xff, &errmsg);
	if (errmsg) {
		printf("%% invalid priority %s: %s\n", argv[1], errmsg);
		return (0);
        }

	switch(x->type) {
	case BRPRI_IFPRIORITY:
		if (set) {
			if (val > 0xff) {
				printf("%% %s exceeds limit\n", x->name);
				return(0);
			}
			bridge_ifprio(ifs, ifname, argv[0], val);
		} else {
			bridge_ifprio(ifs, ifname, argv[0], DEFAULT_IFPRIORITY);
		}	
	break;
	case BRPRI_IFCOST:
		if (set) {
			if (val > 65535) {
				printf("%% %s exceeds limit\n", x->name);
				return(0);
			}
			bridge_ifcost(ifs, ifname, argv[0], val);
		} else {
			bridge_ifcost(ifs, ifname, argv[0], DEFAULT_IFCOST);
		}
	break;
	}
	

	return(0);
}
Esempio n. 8
0
int
brval(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	u_int32_t val = 0;
	const char *errmsg = NULL;
	struct brc *x;

	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	x = (struct brc *) genget(argv[0], (char **)brvs, sizeof(struct brc));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argv++;
	argc--;

	if ((set && argc != 1) || (!set && argc > 1)) {
		printf("%% %s <val>\n", x->name);
		printf("%% no %s [val]\n", x->name);
		return(0);
	}

	if (set) {
		errno = 0;
		val = strtonum(argv[0], 0, ULONG_MAX, &errmsg);
		if (errmsg) {
			printf("%% invalid %s argument %s: %s\n", x->name,
			    argv[0], errmsg);
			return(0);
		}
	}

	switch(x->type) {
	case BRVAL_MAXADDR:
		if (set)
			bridge_maxaddr(ifs, ifname, val);
		else
			bridge_maxaddr(ifs, ifname, DEFAULT_MAXADDR);
		break;
	case BRVAL_TIMEOUT:
		if (set)
			bridge_timeout(ifs, ifname, (int)val);
		else
			bridge_timeout(ifs, ifname, DEFAULT_TIMEOUT);
		break;
	case BRVAL_MAXAGE:
		if (val > 0xff) {
			printf("%% maxage too large\n");
			return(0);
		}
		if (set)
			bridge_maxage(ifs, ifname, val);
		else
			bridge_maxage(ifs, ifname, DEFAULT_MAXAGE);
		break;
	case BRVAL_FWDDELAY:
		if (val > 0xff) {
			printf("%% fwddelay too large\n");
			return(0);
		}
		if (set)
			bridge_fwddelay(ifs, ifname, val);
		else
			bridge_fwddelay(ifs, ifname, DEFAULT_FWDDELAY);
		break;
	case BRVAL_HELLOTIME:
		if (val > 0xff) {
			printf("%% hellotime too large\n");
			return(0);
		}
		if (set)
			bridge_hellotime(ifs, ifname, val);
		else
			bridge_hellotime(ifs, ifname, DEFAULT_HELLOTIME);
		break;
	case BRVAL_PRIORITY:
		if (val > 0xffff) {
			printf("%% priority too large\n");
			return(0);
		}
		if (set)
			bridge_priority(ifs, ifname, val);
		else
			bridge_priority(ifs, ifname, DEFAULT_PRIORITY);
		break;
	}

	return(0);
}
Esempio n. 9
0
int
brport(char *ifname, int ifs, int argc, char **argv)
{
	int set, i;
	struct brc *x;
 
	if (NO_ARG(argv[0])) {
		set = 0;
		argv++;
		argc--;
	} else
		set = 1;

	x = (struct brc *) genget(argv[0], (char **)brps, sizeof(struct brc));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argv++;
	argc--;

	if (argc == 0) {
		printf("%% %s <if> [if]...\n", x->name);
		printf("%% no %s <if> [if]...\n", x->name);
		return(0);
	}

	for (i = 0; i < argc; i++) {
		if (!is_valid_ifname(argv[i]) ||
		    is_bridge(ifs, argv[i])) {
			printf("%% Invalid interface name %s\n", argv[i]);
			continue;
		}
		switch(x->type) {
		case BRPORT_MEMBER:
			if (set) {
				/* adding a member activates a bridge */
				set_ifflag(ifs, ifname, IFF_UP);
				bridge_add(ifs, ifname, argv[i]);
			} else
				bridge_delete(ifs, ifname, argv[i]);
			break;
		case BRPORT_SPAN:
			if (set)
				bridge_addspan(ifs, ifname, argv[i]);
			else
				bridge_delspan(ifs, ifname, argv[i]);
			break;
		case BRPORT_BLOCKNONIP:
			if (set)
				bridge_ifsetflag(ifs, ifname, argv[i],
				    IFBIF_BLOCKNONIP);
			else
				bridge_ifclrflag(ifs, ifname, argv[i],
				    IFBIF_BLOCKNONIP);
			break;
		case BRPORT_DISCOVER:
			if (set)
				bridge_ifsetflag(ifs, ifname, argv[i],
				    IFBIF_DISCOVER);
			else
				bridge_ifclrflag(ifs, ifname, argv[i],
				    IFBIF_DISCOVER);
			break;
		case BRPORT_LEARN:
			if (set)
				bridge_ifsetflag(ifs, ifname, argv[i],
				    IFBIF_LEARNING);
			else
				bridge_ifclrflag(ifs, ifname, argv[i],
				    IFBIF_LEARNING);
			break;
		case BRPORT_STP:
			if (set)
				bridge_ifsetflag(ifs, ifname, argv[i],
				    IFBIF_STP);
			else
				bridge_ifclrflag(ifs, ifname, argv[i],
				    IFBIF_STP);
			break;
		}
	}

	return(0);
}
Esempio n. 10
0
void conf_ctl(FILE *output, char *name)
{
	FILE *conf;
	struct stat enst;
	struct daemons *x;
	struct ctl *ctl;
	char tmp_str[TMPSIZ];
	char fenabled[SIZE_CONF_TEMP + sizeof(".enabled") + 1],
	    *fenablednm = NULL;
	char flocal[SIZE_CONF_TEMP + sizeof(".local") + 1], *flocalnm = NULL;
	char fother[SIZE_CONF_TEMP + sizeof(".other") + 1], *fothernm = NULL;
	int pntdrules = 0, pntdflag = 0;

	x = (struct daemons *)genget(name, (char **)ctl_daemons,
	    sizeof(struct daemons));
	if (x == 0 || Ambiguous(x)) {
		printf("%% conf_ctl: %s: genget internal failure\n", name);
		return;
	}

	/* print rules */
	if ((conf = fopen(x->tmpfile, "r")) != NULL) {
		fprintf(output, "%s rules\n", name);
		for (;;) {
			if(fgets(tmp_str, TMPSIZ, conf) == NULL)
				break;
			if(tmp_str[0] == 0)
				break;
			fprintf(output, " %s", tmp_str);
		}
		fclose(conf);
		fprintf(output, "!\n");
		pntdrules = 1;
	} else if (errno != ENOENT || (errno != ENOENT && verbose))
		printf("%% conf_ctl: %s: %s\n", x->tmpfile, strerror(errno));

	/* grab names from ctl struct for X_LOCAL, X_OTHER, X_ENABLE funcs */
	for (ctl = x->table; ctl != NULL && ctl->name != NULL; ctl++) {
		if (ctl->flag_x == X_LOCAL)
			flocalnm = ctl->name;
		if (ctl->flag_x == X_OTHER)
			fothernm = ctl->name;
		if (ctl->flag_x == X_ENABLE)
			fenablednm = ctl->name;
	}

	snprintf(fenabled, sizeof(fenabled), "%s.enabled", x->tmpfile);
	snprintf(flocal, sizeof(flocal), "%s.local", x->tmpfile);
	snprintf(fother, sizeof(fother), "%s.other", x->tmpfile);

	/*
	 * if a function has the X_LOCAL, X_OTHER or X_ENABLE flags set,
	 * save it in the config
	 */
	if (fenablednm && stat(fenabled, &enst) == 0 && S_ISREG(enst.st_mode)) {
		fprintf(output, "%s %s\n", x->name, fenablednm);
		pntdflag = 1;
	}
	if (flocalnm && stat(flocal, &enst) == 0 && S_ISREG(enst.st_mode)) {
		fprintf(output, "%s %s\n", x->name, flocalnm);
		pntdflag = 1;
	}
	if (fothernm && stat(fother, &enst) == 0 && S_ISREG(enst.st_mode)) {
		fprintf(output, "%s %s\n", x->name, fothernm);
		pntdflag = 1;
	}

	if (pntdrules && x->doreload) {
		fprintf(output, "%s reload\n", x->name);
		pntdflag = 1;
	}
	if (pntdflag)
		fprintf(output, "!\n");
}
Esempio n. 11
0
static void check_for_user_hooks( a_state *state, a_shift_action *saction, index_n rule )
{
    int                 min_max_set;
    int                 all_match;
    unsigned            min;
    unsigned            max;
    unsigned            index;
    an_item             **item;
    a_pro               *pro;
    a_SR_conflict       *conflict;
    a_SR_conflict_list  *cx;
    a_SR_conflict_list  *last;
    a_sym               *sym;

    if( state->kersize < 2 ) {
        return;
    }
    sym = saction->sym;
    min_max_set = 0;
    min = UINT_MAX;
    max = 0;
    for( item = state->items; *item != NULL; ++item ) {
        pro = extract_pro( *item );
        if( pro->SR_conflicts == NULL ) {
            /* production doesn't contain any conflicts */
            return;
        }
        for( cx = pro->SR_conflicts; cx != NULL; cx = cx->next ) {
            conflict = cx->conflict;
            if( conflict->sym != sym ) {
                continue;
            }
            index = conflict->id;
            if( index < min ) {
                min_max_set = 1;
                min = index;
            }
            if( index > max ) {
                min_max_set = 1;
                max = index;
            }
        }
        if( ! min_max_set ) {
            /* production doesn't contain a matching conflict */
            return;
        }
    }
    for( index = min; index <= max; ++index ) {
        last = NULL;
        all_match = 1;
        for( item = state->items; *item != NULL; ++item ) {
            pro = extract_pro( *item );
            for( cx = pro->SR_conflicts; cx != NULL; cx = cx->next ) {
                conflict = cx->conflict;
                if( conflict->id != index ) {
                    continue;
                }
                if( conflict->sym != sym ) {
                    continue;
                }
                break;
            }
            if( cx == NULL ) {
                all_match = 0;
                break;
            }
            last = cx;
        }
        if( all_match ) {
            /* found the desired S/R conflict */
            Ambiguous( state );
            conflict = last->conflict;
            conflict->state = state;
            conflict->shift = saction->state;
            conflict->reduce = rule;
            return;
        }
    }
}
Esempio n. 12
0
File: conf.c Progetto: sthen/nsh
void conf_ctl(FILE *output, char *delim, char *name, int rtableid)
{
	FILE *conf;
	struct daemons *x;
	struct ctl *ctl;
	char tmp_str[TMPSIZ], tmpfile[64];
	char *fenablednm = NULL, *fothernm = NULL, *flocalnm = NULL;
	int pntdrules = 0, pntdflag = 0, dbflag;

	x = (struct daemons *)genget(name, (char **)ctl_daemons,
	    sizeof(struct daemons));
	if (x == 0 || Ambiguous(x)) {
		printf("%% conf_ctl: %s: genget internal failure\n", name);
		return;
	}

	/* print rules */
	snprintf(tmpfile, sizeof(tmpfile), "%s.%d", x->tmpfile, rtableid);
	if ((conf = fopen(tmpfile, "r")) != NULL) {
		fprintf(output, "%s%s rules\n", delim, name);
		for (;;) {
			if(fgets(tmp_str, TMPSIZ, conf) == NULL)
				break;
			if(tmp_str[0] == 0)
				break;
			fprintf(output, "%s %s", delim, tmp_str);
		}
		fclose(conf);
		fprintf(output, "%s!\n", delim);
		pntdrules = 1;
	} else if (errno != ENOENT || (errno != ENOENT && verbose))
		printf("%% conf_ctl: %s: %s\n", tmpfile, strerror(errno));

	for (ctl = x->table; ctl != NULL && ctl->name != NULL; ctl++) {
		if (ctl->flag_x == DB_X_LOCAL)
			flocalnm = ctl->name;
		if (ctl->flag_x == DB_X_OTHER)
			fothernm = ctl->name;
		if (ctl->flag_x == DB_X_ENABLE)
			fenablednm = ctl->name;
	}

	if ((dbflag = db_select_flag_x_dbflag_rtable("ctl", x->name, rtableid))
	    < 0) {
		printf("%% database ctl select failure (%s, %d)\n", x->name, rtableid);
		return;
	}
	switch(dbflag) {
	case DB_X_ENABLE:
		fprintf(output, "%s%s %s\n", delim, x->name, fenablednm ?
		    fenablednm : "enable");
		pntdflag = 1;
		break;
	case DB_X_LOCAL:
		fprintf(output, "%s%s %s\n", delim, x->name, flocalnm ?
		    flocalnm : "local");
		pntdflag = 1;
		break;
	case DB_X_OTHER:
		fprintf(output, "%s%s %s\n", delim, x->name, fothernm ?
		    fothernm : "other");
		pntdflag = 1;
		break;
	case DB_X_DISABLE:
	case 0:
		break;
	default:
		printf("%% conf_ctl dbflag %d unknown\n", dbflag);
	}
	if (pntdrules && x->doreload) {
		fprintf(output, "%s%s reload\n", delim, x->name);
		pntdflag = 1;
	}
	if (pntdflag)
		fprintf(output, "%s!\n", delim);
}
Esempio n. 13
0
File: if.c Progetto: yellowman/nsh
/* from ifconfig.c */
int
intmpw(char *ifname, int ifs, int argc, char **argv)
{
	int set;
	struct sockaddr_in *sin, *sinn;
	struct ifmpwreq imr;
	struct ifreq ifr;
	struct mpwc *x;
	const char *errstr;

	bzero(&imr, sizeof(imr));
	bzero(&ifr, sizeof(ifr));

	strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);

	if (NO_ARG(argv[0])) {
		set = 0;
		argc--;
		argv++;
	} else
		set = 1;

	x=(struct mpwc *) genget(argv[0], (char **)mpwcs, sizeof(struct mpwc));
	if (x == 0) {
		printf("%% Internal error - Invalid argument %s\n", argv[0]);
		return 0;
	} else if (Ambiguous(x)) {
		printf("%% Internal error - Ambiguous argument %s\n", argv[0]);
		return 0;
	}

	argc--;
	argv++;

	if (x->args == 2 && ((!set && argc > 2) || (set && argc != 2))) {
		printf("%% %s <%s> <%s>\n", x->name, x->descr, x->descr2);
		printf("%% no %s [%s] [%s]\n", x->name, x->descr, x->descr2);
		return(0);
	}
	if (x->args == 1 && ((!set && argc > 1) || (set && argc != 1))) {
		printf("%% %s <%s>\n", x->name, x->descr);
		printf("%% no %s [%s]\n", x->name, x->descr);
		return(0);
	}
	if (!x->args && argc) {
		printf("%% %s\n", x->name);
		printf("%% no %s\n", x->name);
		return(0);
	}

	switch(x->type) {
	case MPWLABEL:
		if (!set) {
			imrsave.imr_lshim.shim_label = 0;
			imrsave.imr_rshim.shim_label = 0;
			break;
		}
		imrsave.imr_lshim.shim_label = strtonum(argv[0],
		    (MPLS_LABEL_RESERVED_MAX + 1), MPLS_LABEL_MAX, &errstr);
		if (errstr != NULL) {
			printf("%% invalid local label: %s\n", errstr);
			return 0;
		}

		imrsave.imr_rshim.shim_label = strtonum(argv[1],
		    (MPLS_LABEL_RESERVED_MAX + 1), MPLS_LABEL_MAX, &errstr);
		if (errstr != NULL) {
			printf("%% invalid remote label: %s\n", errstr);
			return 0;
		}
	break;
	case MPWNEIGHBOR:
		sin = (struct sockaddr_in *) &imrsave.imr_nexthop;
		if (set && inet_aton(argv[0], &sin->sin_addr) == 0) {
			printf("%% invalid neighbor addresses\n");
			return 0;
		}
		if (!set) {
			sin->sin_addr.s_addr = 0;
		}
		sin->sin_family = AF_INET;
	break;
	case MPWCONTROLWORD:
		if (set)
			imrsave.imr_flags |= IMR_FLAG_CONTROLWORD;
		else
			imrsave.imr_flags &= ~IMR_FLAG_CONTROLWORD;
	break;
	case MPWENCAP:
		if (!set) {
			imrsave.imr_type = UINT32_MAX;
			break;
		}
		if (isprefix(argv[0], "ethernet")) {
			imrsave.imr_type = IMR_TYPE_ETHERNET;
		} else if (isprefix(argv[0], "ethernet-tagged")) {
			imrsave.imr_type = IMR_TYPE_ETHERNET_TAGGED;
		} else {
			printf("%% invalid mpw encapsulation type\n");
			return 0;
		}
		break;
	}

	ifr.ifr_data = (caddr_t) &imr;
	if (ioctl(ifs, SIOCGETMPWCFG, (caddr_t) &ifr) == -1) {
		printf("%% SIOCGETMPWCFG: %s\n", strerror(errno));
		return 0;
	}

	if (imrsave.imr_type == 0)
		imrsave.imr_type = imr.imr_type;
	if (imrsave.imr_type == UINT32_MAX)
		imrsave.imr_type = 0;

	if (x->type != MPWCONTROLWORD)
		imrsave.imr_flags |= imr.imr_flags;

	if (imrsave.imr_lshim.shim_label == 0 ||
	    imrsave.imr_rshim.shim_label == 0) {
		if (imr.imr_lshim.shim_label == 0 ||
		    imr.imr_rshim.shim_label == 0) {
			/* mpw local / remote label not specified */
			return 0;
		}
		imrsave.imr_lshim.shim_label = imr.imr_lshim.shim_label;
		imrsave.imr_rshim.shim_label = imr.imr_rshim.shim_label;
	}

	sin = (struct sockaddr_in *) &imrsave.imr_nexthop;
	sinn = (struct sockaddr_in *) &imr.imr_nexthop;
	if (sin->sin_addr.s_addr == 0) {
		if (sinn->sin_addr.s_addr == 0) {
			/* mpw neighbor address not specified */
			return 0;
		}

		sin->sin_family = sinn->sin_family;
		sin->sin_addr.s_addr = sinn->sin_addr.s_addr;
	}

	ifr.ifr_data = (caddr_t) &imrsave;
	if (ioctl(ifs, SIOCSETMPWCFG, (caddr_t) &ifr) == -1)
		printf("%% intmpw: SIOCSETMPWCFG: %s\n", strerror(errno));

	return 0;
}