mpath++;
flags |= RTF_MPATH;
newroute(int argc, char **argv){	char *cmd, *dest = "", *gateway = "", *err;	int ishost = 0, ret = 0, attempts, oerrno, flags = RTF_STATIC;	int key, mpath = 0;	struct hostent *hp = 0;	if (uid)		errx(1, "must be root to alter routing table");	cmd = argv[0];	if (*cmd != 'g')		shutdown(s, 0); /* Don't want to read back our messages */	while (--argc > 0) {		if (**(++argv)== '-') {			switch (key = keyword(1 + *argv)) {			case K_LINK:				af = AF_LINK;				aflen = sizeof(struct sockaddr_dl);				break;			case K_INET:				af = AF_INET;				aflen = sizeof(struct sockaddr_in);				break;#ifdef INET6			case K_INET6:				af = AF_INET6;				aflen = sizeof(struct sockaddr_in6);				break;#endif			case K_X25:				af = AF_CCITT;				aflen = sizeof(struct sockaddr_x25);				break;			case K_SA:				af = PF_ROUTE;				aflen = sizeof(union sockunion);				break;			case K_IPX:				af = AF_IPX;				aflen = sizeof(struct sockaddr_ipx);				break;			case K_IFACE:			case K_INTERFACE:				iflag++;				break;			case K_NOSTATIC:				flags &= ~RTF_STATIC;				break;			case K_LLINFO:				flags |= RTF_LLINFO;				break;			case K_LOCK:				locking = 1;				break;			case K_LOCKREST:				lockrest = 1;				break;			case K_HOST:				forcehost++;				break;			case K_REJECT:				flags |= RTF_REJECT;				break;			case K_BLACKHOLE:				flags |= RTF_BLACKHOLE;				break;			case K_PROTO1:				flags |= RTF_PROTO1;				break;			case K_PROTO2:				flags |= RTF_PROTO2;				break;			case K_CLONING:				flags |= RTF_CLONING;				break;			case K_XRESOLVE:				flags |= RTF_XRESOLVE;				break;			case K_STATIC:				flags |= RTF_STATIC;				break;			case K_IFA:				if (!--argc)					usage(1+*argv);				(void) getaddr(RTA_IFA, *++argv, 0);				break;			case K_IFP:				if (!--argc)					usage(1+*argv);				(void) getaddr(RTA_IFP, *++argv, 0);				break;			case K_GENMASK:				if (!--argc)					usage(1+*argv);				(void) getaddr(RTA_GENMASK, *++argv, 0);				break;			case K_GATEWAY:				if (!--argc)					usage(1+*argv);				(void) getaddr(RTA_GATEWAY, *++argv, 0);				gateway = *argv;				break;			case K_DST:				if (!--argc)					usage(1+*argv);				ishost = getaddr(RTA_DST, *++argv, &hp);				dest = *argv;				break;			case K_LABEL:				if (!--argc)					usage(1+*argv);				(void) getlabel(*++argv);				break;			case K_NETMASK:				if (!--argc)					usage(1+*argv);				(void) getaddr(RTA_NETMASK, *++argv, 0);				/* FALLTHROUGH */			case K_NET:				forcenet++;				break;			case K_PREFIXLEN:				if (!--argc)					usage(1+*argv);				ishost = prefixlen(*++argv);				break;			case K_MPATH:				mpath++;				break;			case K_MTU:			case K_HOPCOUNT:			case K_EXPIRE:			case K_RECVPIPE:			case K_SENDPIPE:			case K_SSTHRESH:			case K_RTT:			case K_RTTVAR:				if (!--argc)					usage(1+*argv);				set_metric(*++argv, key);				break;			default:				usage(1+*argv);			}		} else {			if ((rtm_addrs & RTA_DST) == 0) {				dest = *argv;				ishost = getaddr(RTA_DST, *argv, &hp);			} else if ((rtm_addrs & RTA_GATEWAY) == 0) {				gateway = *argv;				(void) getaddr(RTA_GATEWAY, *argv, &hp);			} else {				int hops = atoi(*argv);				if (hops == 0) {				    if (!qflag && strcmp(*argv, "0") == 0)					printf("%s,%s",					    "old usage of trailing 0",					    "assuming route to if\n");				    else					usage(NULL);				    iflag = 1;				    continue;				} else if (hops > 0 && hops < 10) {				    if (!qflag) {					printf("old usage of trailing digit, ");					printf("assuming route via gateway\n");				    }				    iflag = 0;				    continue;				}				(void) getaddr(RTA_NETMASK, *argv, 0);			}		}	}	if (forcehost)		ishost = 1;	if (forcenet)		ishost = 0;	if (forcenet && !(rtm_addrs & RTA_NETMASK))		errx(1, "netmask missing");	flags |= RTF_UP;	if (mpath)		flags |= RTF_MPATH;	if (ishost)		flags |= RTF_HOST;	if (iflag == 0)		flags |= RTF_GATEWAY;	for (attempts = 1; ; attempts++) {		errno = 0;		if ((ret = rtmsg(*cmd, flags)) == 0)			break;		if (errno != ENETUNREACH && errno != ESRCH)			break;		if (af == AF_INET && *gateway && hp && hp->h_addr_list[1]) {			hp->h_addr_list++;			memcpy(&so_gate.sin.sin_addr, hp->h_addr_list[0],			    hp->h_length);		} else			break;	}	if (*cmd == 'g')		exit(0);	oerrno = errno;	if (!qflag) {		(void) printf("%s %s %s", cmd, ishost? "host" : "net", dest);		if (*gateway) {			(void) printf(": gateway %s", gateway);			if (attempts > 1 && ret == 0 && af == AF_INET)			    (void) printf(" (%s)",				inet_ntoa(so_gate.sin.sin_addr));		}		if (ret == 0)			(void) printf("\n");		if (ret != 0) {			switch (oerrno) {			case ESRCH:				err = "not in table";				break;			case EBUSY:				err = "entry in use";				break;			case ENOBUFS:				err = "routing table overflow";				break;			default:				err = strerror(oerrno);				break;			}			(void) printf(": %s\n", err);		}	}	return (ret != 0);}