{ "inet", AF_INET, in_status, in_getaddr, NULL,
{ "inet", AF_INET, in_status, in_getaddr, in_getprefix,
const char *get_media_type_string __P((int));const char *get_media_subtype_string __P((int));int	get_media_subtype __P((int, const char *));int	get_media_options __P((int, const char *));int	lookup_media_word __P((const struct ifmedia_description *, int,	    const char *));void	print_media_word __P((int, int, int));void	process_media_commands __P((void));void	init_current_media __P((void));/* * XNS support liberally adapted from code written at the University of * Maryland principally by James O'Toole and Chris Torek. */void	in_status __P((int));void 	in_getaddr __P((char *, int));#ifdef INET6void	in6_fillscopeid __P((struct sockaddr_in6 *sin6));void	in6_alias __P((struct in6_ifreq *));void	in6_status __P((int));void 	in6_getaddr __P((char *, int));void 	in6_getprefix __P((char *, int));#endifvoid    at_status __P((int));void    at_getaddr __P((char *, int));void 	xns_status __P((int));void 	xns_getaddr __P((char *, int));void 	ipx_status __P((int));void 	ipx_getaddr __P((char *, int));void 	iso_status __P((int));void 	iso_getaddr __P((char *, int));void	ieee80211_status __P((void));/* Known address families */const struct afswtch {	char *af_name;	short af_af;	void (*af_status)();	void (*af_getaddr)();	void (*af_getprefix)();	u_long af_difaddr;	u_long af_aifaddr;	caddr_t af_ridreq;	caddr_t af_addreq;} afs[] = {#define C(x) ((caddr_t) &x)	{ "inet", AF_INET, in_status, in_getaddr, NULL,	     SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },#ifdef INET6	{ "inet6", AF_INET6, in6_status, in6_getaddr, in6_getprefix,	     SIOCDIFADDR_IN6, SIOCAIFADDR_IN6, C(in6_ridreq), C(in6_addreq) },#endif#ifndef INET_ONLY	/* small version, for boot media */	{ "atalk", AF_APPLETALK, at_status, at_getaddr, NULL,	    SIOCDIFADDR, SIOCAIFADDR, C(addreq), C(addreq) },	{ "ns", AF_NS, xns_status, xns_getaddr, NULL,	     SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },	{ "ipx", AF_IPX, ipx_status, ipx_getaddr, NULL,	     SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },	{ "iso", AF_ISO, iso_status, iso_getaddr, NULL,	     SIOCDIFADDR_ISO, SIOCAIFADDR_ISO, C(iso_ridreq), C(iso_addreq) },#endif	/* INET_ONLY */	{ 0,	0,	    0,		0 }};const struct afswtch *afp;	/*the address family being set or asked about*/intmain(argc, argv)	int argc;	char *argv[];{	register const struct afswtch *rafp;	int aflag = 0;	int ifaliases = 0;	int i;	if (argc < 2) 		usage();	argc--, argv++;	if (!strcmp(*argv, "-a"))		aflag = 1;	else if (!strcmp(*argv, "-A")) {		aflag = 1;		ifaliases = 1;	}	else if (!strcmp(*argv, "-ma") || !strcmp(*argv, "-am")) {		aflag = 1;		mflag = 1;	}	else if (!strcmp(*argv, "-mA") || !strcmp(*argv, "-Am")) {		aflag = 1;		ifaliases = 1;		mflag = 1;	}	else if (!strcmp(*argv, "-m")) {		mflag = 1;		argc--, argv++;		if (argc < 1)			usage();		strncpy(name, *argv, sizeof(name) - 1);	} else		strncpy(name, *argv, sizeof(name) - 1);	argc--, argv++;	if (argc > 0) {		for (afp = rafp = afs; rafp->af_name; rafp++)			if (strcmp(rafp->af_name, *argv) == 0) {				afp = rafp; argc--; argv++;				break;			}		rafp = afp;		af = ifr.ifr_addr.sa_family = rafp->af_af;	}	if (aflag) {		if (argc > 0)			usage();		printif(NULL, ifaliases);		exit(0);	}	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);	if (argc == 0) {		printif(&ifr, 1);		exit(0);	}#ifdef INET6	/* initialization */	in6_addreq.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;	in6_addreq.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;#endif	if (getinfo(&ifr) < 0)		exit(1);	while (argc > 0) {		register const struct cmd *p;		for (p = cmds; p->c_name; p++)			if (strcmp(*argv, p->c_name) == 0)				break;		if (p->c_name == 0 && setaddr)			for (i = setaddr; i > 0; i--) {				p++;				if (p->c_func == NULL)					errx(1, "extra address not accepted");			}		if (p->c_func) {			if (p->c_parameter == NEXTARG) {				if (argv[1] == NULL)					errx(1, "'%s' requires argument",					    p->c_name);				(*p->c_func)(argv[1]);				argc--, argv++;			} else if (p->c_parameter == NEXTARG2) {			        if ((argv[1] == NULL) ||				    (argv[2] == NULL))					errx(1, "'%s' requires 2 arguments",					    p->c_name);				(*p->c_func)(argv[1], argv[2]);				argc -= 2;				argv += 2;			} else				(*p->c_func)(*argv, p->c_parameter);			actions |= p->c_action;		}		argc--, argv++;	}	/* Process any media commands that may have been issued. */	process_media_commands();	if (af == AF_INET6 && explicit_prefix == 0) {		/*		 * Aggregatable address architecture defines all prefixes		 * are 64. So, it is convenient to set prefixlen to 64 if		 * it is not specified.		 */		setifprefixlen("64", 0);		/* in6_getprefix("64", MASK) if MASK is available here... */	}  #ifndef INET_ONLY	switch (af) {	case AF_ISO:		adjust_nsellength();		break;	case AF_NS:		if (setipdst) {			struct nsip_req rq;			int size = sizeof(rq);			rq.rq_ns = addreq.ifra_addr;			rq.rq_ip = addreq.ifra_dstaddr;			if (setsockopt(s, 0, SO_NSIP_ROUTE, &rq, size) < 0)				warn("encapsulation routing");		}		break;	case AF_IPX:		if (setipdst) {			struct ipxip_req rq;			int size = sizeof(rq);			rq.rq_ipx = addreq.ifra_addr;			rq.rq_ip = addreq.ifra_dstaddr;			if (setsockopt(s, 0, SO_IPXIP_ROUTE, &rq, size) < 0)				warn("encapsulation routing");		}		break;	case AF_APPLETALK:		checkatrange((struct sockaddr_at *) &addreq.ifra_addr);		break;	}#endif	/* INET_ONLY */	if (clearaddr) {		int ret;		strncpy(rafp->af_ridreq, name, sizeof ifr.ifr_name);		if ((ret = ioctl(s, rafp->af_difaddr, rafp->af_ridreq)) < 0) {			if (errno == EADDRNOTAVAIL && (doalias >= 0)) {				/* means no previous address for interface */			} else				warn("SIOCDIFADDR");		}	}	if (newaddr) {		strncpy(rafp->af_addreq, name, sizeof ifr.ifr_name);		if (ioctl(s, rafp->af_aifaddr, rafp->af_addreq) < 0)			warn("SIOCAIFADDR");	}	exit(0);}voidgetsock(naf)	int naf;{	static int oaf = -1;	if (oaf == naf)		return;	if (oaf != -1)		close(s);	s = socket(naf, SOCK_DGRAM, 0);	if (s < 0)		oaf = -1;	else		oaf = naf;}intgetinfo(ifr)	struct ifreq *ifr;{	getsock(af);	if (s < 0)		err(1, "socket");	if (ioctl(s, SIOCGIFFLAGS, (caddr_t)ifr) < 0) {		warn("SIOCGIFFLAGS");		return (-1);	}	flags = ifr->ifr_flags;	if (ioctl(s, SIOCGIFMETRIC, (caddr_t)ifr) < 0) {		warn("SIOCGIFMETRIC");		metric = 0;	} else		metric = ifr->ifr_metric;	if (ioctl(s, SIOCGIFMTU, (caddr_t)ifr) < 0)		mtu = 0;	else		mtu = ifr->ifr_mtu;	return (0);}voidprintif(ifrm, ifaliases)	struct ifreq *ifrm;{#ifdef HAVE_IFADDRS_H	struct ifaddrs *ifap, *ifa;	const char *namep;	struct ifreq *ifrp;	int count = 0, noinet = 1;	if (getifaddrs(&ifap) != 0)		err(1, "getifaddrs");	namep = NULL;	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {		if (ifrm && strncmp(ifrm->ifr_name, ifa->ifa_name,		    sizeof(ifrm->ifr_name)))			continue;		strncpy(name, ifa->ifa_name, sizeof(name));		name[sizeof(name) - 1] = '\0';#ifdef INET6		/* quickhack: sizeof(ifr) < sizeof(ifr6) */		if (ifa->ifa_addr->sa_family == AF_INET6) {			ifrp = (struct ifreq *)&ifr6;			memset(&ifr6, 0, sizeof(ifr6));		} else {			ifrp = &ifr;			memset(&ifr, 0, sizeof(ifr));		}#else		ifrp = &ifr;		memset(&ifr, 0, sizeof(ifr));#endif		strncpy(ifrp->ifr_name, ifa->ifa_name, sizeof(ifrp->ifr_name));		/* XXX boundary check? */		memcpy(&ifrp->ifr_addr, ifa->ifa_addr, ifa->ifa_addr->sa_len);		if (ifa->ifa_addr->sa_family == AF_LINK) {			namep = ifa->ifa_name;			if (getinfo(ifrp) < 0)				continue;			status(1);			count++;			noinet = 1;			continue;		}		if (!namep || !strcmp(namep, ifa->ifa_name)) {			register const struct afswtch *p;			if (ifa->ifa_addr->sa_family == AF_INET &&			    ifaliases == 0 && noinet == 0)				continue;			if ((p = afp) != NULL) {				if (ifa->ifa_addr->sa_family == p->af_af)					(*p->af_status)(1);			} else {				for (p = afs; p->af_name; p++) {					if (ifa->ifa_addr->sa_family == p->af_af)						(*p->af_status)(0);				}			}			count++;			if (ifa->ifa_addr->sa_family == AF_INET)				noinet = 0;			continue;		}	}	freeifaddrs(ifap);	if (count == 0) {		fprintf(stderr, "%s: no such interface\n", name);		exit(1);	}#else	char *inbuf = NULL;	struct ifconf ifc;	struct ifreq ifreq, *ifrp;	int i, siz, len = 8192;	int count = 0, noinet = 1;	char ifrbuf[8192];	getsock(af);	if (s < 0)		err(1, "socket");	while (1) {		ifc.ifc_len = len;		ifc.ifc_buf = inbuf = realloc(inbuf, len);		if (inbuf == NULL)			err(1, "malloc");		if (ioctl(s, SIOCGIFCONF, &ifc) < 0)			err(1, "SIOCGIFCONF");		if (ifc.ifc_len + sizeof(ifreq) < len)			break;		len *= 2;	}	ifrp = ifc.ifc_req;	ifreq.ifr_name[0] = '\0';	for (i = 0; i < ifc.ifc_len; ) {		ifrp = (struct ifreq *)((caddr_t)ifc.ifc_req + i);		memcpy(ifrbuf, ifrp, sizeof(*ifrp));		siz = ((struct ifreq *)ifrbuf)->ifr_addr.sa_len;		if (siz < sizeof(ifrp->ifr_addr))			siz = sizeof(ifrp->ifr_addr);		siz += sizeof(ifrp->ifr_name);		i += siz;		/* avoid alignment issue */		if (sizeof(ifrbuf) < siz)			errx(1, "ifr too big");		memcpy(ifrbuf, ifrp, siz);		ifrp = (struct ifreq *)ifrbuf;		if (ifrm && strncmp(ifrm->ifr_name, ifrp->ifr_name,		    sizeof(ifrp->ifr_name)))			continue;		strncpy(name, ifrp->ifr_name, sizeof(ifrp->ifr_name));		if (ifrp->ifr_addr.sa_family == AF_LINK) {			ifreq = ifr = *ifrp;			if (getinfo(&ifreq) < 0)				continue;			status(1);			count++;			noinet = 1;			continue;		}		if (!strncmp(ifreq.ifr_name, ifrp->ifr_name,		    sizeof(ifrp->ifr_name))) {			register const struct afswtch *p;			if (ifrp->ifr_addr.sa_family == AF_INET &&			    ifaliases == 0 && noinet == 0)				continue;			ifr = *ifrp;#ifdef INET6			/* quickhack: sizeof(ifr) < sizeof(ifr6) */			if (ifrp->ifr_addr.sa_family == AF_INET6)				bcopy(ifrp, &ifr6, sizeof(ifr6));#endif			if ((p = afp) != NULL) {				if (ifr.ifr_addr.sa_family == p->af_af)					(*p->af_status)(1);			} else {				for (p = afs; p->af_name; p++) {					if (ifr.ifr_addr.sa_family == p->af_af)						(*p->af_status)(0);				}			}			count++;			if (ifrp->ifr_addr.sa_family == AF_INET)				noinet = 0;			continue;		}	}	free(inbuf);	if (count == 0) {		fprintf(stderr, "%s: no such interface\n", name);		exit(1);	}#endif}#define RIDADDR 0#define ADDR	1#define MASK	2#define DSTADDR	3/*ARGSUSED*/voidsetifaddr(addr, param)	char *addr;	int param;{	/*	 * Delay the ioctl to set the interface addr until flags are all set.	 * The address interpretation may depend on the flags,	 * and the flags may change when the address is set.	 */	setaddr++;	newaddr = 1;	if (doalias == 0)		clearaddr = 1;	(*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR));}voidgifsettunnel(src, dst)	char *src;	char *dst;{	struct addrinfo hints, *srcres, *dstres;	struct ifaliasreq addreq;	int ecode;#ifdef INET6	struct in6_aliasreq in6_addreq;#endif /* INET6 */	memset(&hints, 0, sizeof(hints));	hints.ai_family = afp->af_af;	if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)		errx(1, "error in parsing address string: %s",		     gai_strerror(ecode));	if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)		errx(1, "error in parsing address string: %s",		     gai_strerror(ecode));	if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)		errx(1,		     "source and destination address families do not match");	switch (srcres->ai_addr->sa_family)	{	    case AF_INET:		bzero(&addreq, sizeof(addreq));		strncpy(addreq.ifra_name, name, IFNAMSIZ);		bcopy(srcres->ai_addr, &addreq.ifra_addr,		      srcres->ai_addr->sa_len);		bcopy(dstres->ai_addr, &addreq.ifra_dstaddr,		      dstres->ai_addr->sa_len);		if (ioctl(s, SIOCSIFPHYADDR, (struct ifreq *) &addreq) < 0)		  warn("SIOCSIFPHYADDR");		break;#ifdef INET6	    case AF_INET6:		bzero(&in6_addreq, sizeof(in6_addreq));		strncpy(in6_addreq.ifra_name, name, IFNAMSIZ);		bcopy(srcres->ai_addr, &in6_addreq.ifra_addr,		      srcres->ai_addr->sa_len);		bcopy(dstres->ai_addr, &in6_addreq.ifra_dstaddr,		      dstres->ai_addr->sa_len);		if (ioctl(s, SIOCSIFPHYADDR_IN6,			  (struct ifreq *) &in6_addreq) < 0)		  warn("SIOCSIFPHYADDR");		break;#endif /* INET6 */	    default:		warn("address family not supported");	}	freeaddrinfo(srcres);	freeaddrinfo(dstres);}voidsetifnetmask(addr)	char *addr;{	(*afp->af_getaddr)(addr, MASK);}voidsetifbroadaddr(addr)	char *addr;{	(*afp->af_getaddr)(addr, DSTADDR);}voidsetifipdst(addr)	char *addr;{	in_getaddr(addr, DSTADDR);	setipdst++;	clearaddr = 0;	newaddr = 0;}#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr))/*ARGSUSED*/voidnotealias(addr, param)	char *addr;	int param;{	if (setaddr && doalias == 0 && param < 0)		memcpy(rqtosa(af_ridreq), rqtosa(af_addreq),		    rqtosa(af_addreq)->sa_len);	doalias = param;	if (param < 0) {		clearaddr = 1;		newaddr = 0;	} else		clearaddr = 0;}/*ARGSUSED*/voidnotrailers(vname, value)	char *vname;	int value;{	printf("Note: trailers are no longer sent, but always received\n");}/*ARGSUSED*/voidsetifdstaddr(addr, param)	char *addr;	int param;{	setaddr++;	(*afp->af_getaddr)(addr, DSTADDR);}/* * Note: doing an SIOCIGIFFLAGS scribbles on the union portion * of the ifreq structure, which may confuse other parts of ifconfig. * Make a private copy so we can avoid that. */voidsetifflags(vname, value)	char *vname;	int value;{	struct ifreq my_ifr;	bcopy((char *)&ifr, (char *)&my_ifr, sizeof(struct ifreq));	if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0)		err(1, "SIOCGIFFLAGS");	strncpy(my_ifr.ifr_name, name, sizeof (my_ifr.ifr_name)); 	flags = my_ifr.ifr_flags;	if (value < 0) {		value = -value;		flags &= ~value;	} else		flags |= value;	my_ifr.ifr_flags = flags;	if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&my_ifr) < 0)		err(1, "SIOCSIFFLAGS");}#ifdef INET6voidsetia6flags(vname, value)	char *vname;	int value;{	if (value < 0) {		value = -value;		in6_addreq.ifra_flags &= ~value;	} else		in6_addreq.ifra_flags |= value;}voidsetia6pltime(val, d)	char *val;	int d;{	setia6lifetime("pltime", val);}voidsetia6vltime(val, d)	char *val;	int d;{	setia6lifetime("vltime", val);}voidsetia6lifetime(cmd, val)	char *cmd;	char *val;{	time_t newval, t;	char *ep;	t = time(NULL);	newval = (time_t)strtoul(val, &ep, 0);	if (val == ep)		errx(1, "invalid %s", cmd);	if (afp->af_af != AF_INET6)		errx(1, "%s not allowed for the AF", cmd);	if (strcmp(cmd, "vltime") == 0) {		in6_addreq.ifra_lifetime.ia6t_expire = t + newval;		in6_addreq.ifra_lifetime.ia6t_vltime = newval;	} else if (strcmp(cmd, "pltime") == 0) {		in6_addreq.ifra_lifetime.ia6t_preferred = t + newval;		in6_addreq.ifra_lifetime.ia6t_pltime = newval;	}}#endifvoidsetifmetric(val)	char *val;{	strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));	ifr.ifr_metric = atoi(val);	if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) < 0)		warn("SIOCSIFMETRIC");}voidsetifmtu(val, d)	char *val;	int d;{	(void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));	ifr.ifr_mtu = atoi(val);	if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) < 0)		warn("SIOCSIFMTU");}voidsetifnwid(val, d)	char *val;	int d;{	struct ieee80211_nwid nwid;	memset(&nwid, 0, sizeof(nwid));	(void)strncpy(nwid.i_nwid, val, sizeof(nwid.i_nwid));	nwid.i_len = sizeof(nwid.i_nwid);	(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));	ifr.ifr_data = (caddr_t)&nwid;	if (ioctl(s, SIOCS80211NWID, (caddr_t)&ifr) < 0)		warn("SIOCS80211NWID");}voidieee80211_status(){	struct ieee80211_nwid nwid;	char buf[IEEE80211_NWID_LEN + 1];	memset(&ifr, 0, sizeof(ifr));	ifr.ifr_data = (caddr_t)&nwid;	(void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));	if (ioctl(s, SIOCG80211NWID, (caddr_t)&ifr) == 0) {		strncpy(buf, nwid.i_nwid, sizeof(buf) - 1);		buf[IEEE80211_NWID_LEN] = '\0';		printf("\tnwid %s\n", nwid.i_nwid);	}}voidinit_current_media(){	struct ifmediareq ifmr;	/*	 * If we have not yet done so, grab the currently-selected	 * media.	 */	if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {		(void) memset(&ifmr, 0, sizeof(ifmr));		(void) strncpy(ifmr.ifm_name, name, sizeof(ifmr.ifm_name));		if (ioctl(s, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {			/*			 * If we get E2BIG, the kernel is telling us			 * that there are more, so we can ignore it.			 */			if (errno != E2BIG)				err(1, "SGIOCGIFMEDIA");		}		media_current = ifmr.ifm_current;	}	/* Sanity. */	if (IFM_TYPE(media_current) == 0)		errx(1, "%s: no link type?", name);}voidprocess_media_commands(){	if ((actions & (A_MEDIA|A_MEDIAOPT)) == 0) {		/* Nothing to do. */		return;	}	/*	 * Media already set up, and commands sanity-checked.  Set/clear	 * any options, and we're ready to go.	 */	media_current |= mediaopt_set;	media_current &= ~mediaopt_clear;	strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));	ifr.ifr_media = media_current;	if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)		err(1, "SIOCSIFMEDIA");}voidsetmedia(val, d)	char *val;	int d;{	int type, subtype, inst;	init_current_media();	/* Only one media command may be given. */	if (actions & A_MEDIA)		errx(1, "only one `media' command may be issued");	/* Must not come after mediaopt commands */	if (actions & A_MEDIAOPT)		errx(1, "may not issue `media' after `mediaopt' commands");	/*	 * No need to check if `instance' has been issued; setmediainst()	 * craps out if `media' has not been specified.	 */	type = IFM_TYPE(media_current);	inst = IFM_INST(media_current);	/* Look up the subtype. */	subtype = get_media_subtype(type, val);	/* Build the new current media word. */	media_current = IFM_MAKEWORD(type, subtype, 0, inst);	/* Media will be set after other processing is complete. */}voidsetmediaopt(val, d)	char *val;	int d;{	init_current_media();	/* Can only issue `mediaopt' once. */	if (actions & A_MEDIAOPTSET)		errx(1, "only one `mediaopt' command may be issued");	/* Can't issue `mediaopt' if `instance' has already been issued. */	if (actions & A_MEDIAINST)		errx(1, "may not issue `mediaopt' after `instance'");	mediaopt_set = get_media_options(IFM_TYPE(media_current), val);	/* Media will be set after other processing is complete. */}voidunsetmediaopt(val, d)	char *val;	int d;{	init_current_media();	/* Can only issue `-mediaopt' once. */	if (actions & A_MEDIAOPTCLR)		errx(1, "only one `-mediaopt' command may be issued");	/* May not issue `media' and `-mediaopt'. */	if (actions & A_MEDIA)		errx(1, "may not issue both `media' and `-mediaopt'");	/*	 * No need to check for A_MEDIAINST, since the test for A_MEDIA	 * implicitly checks for A_MEDIAINST.	 */	mediaopt_clear = get_media_options(IFM_TYPE(media_current), val);	/* Media will be set after other processing is complete. */}voidsetmediainst(val, d)	char *val;	int d;{	int type, subtype, options, inst;	init_current_media();	/* Can only issue `instance' once. */	if (actions & A_MEDIAINST)		errx(1, "only one `instance' command may be issued");	/* Must have already specified `media' */	if ((actions & A_MEDIA) == 0)		errx(1, "must specify `media' before `instance'");	type = IFM_TYPE(media_current);	subtype = IFM_SUBTYPE(media_current);	options = IFM_OPTIONS(media_current);	inst = atoi(val);	if (inst < 0 || inst > IFM_INST_MAX)		errx(1, "invalid media instance: %s", val);	media_current = IFM_MAKEWORD(type, subtype, options, inst);	/* Media will be set after other processing is complete. */}const struct ifmedia_description ifm_type_descriptions[] =    IFM_TYPE_DESCRIPTIONS;const struct ifmedia_description ifm_subtype_descriptions[] =    IFM_SUBTYPE_DESCRIPTIONS;const struct ifmedia_description ifm_option_descriptions[] =    IFM_OPTION_DESCRIPTIONS;const char *get_media_type_string(mword)	int mword;{	const struct ifmedia_description *desc;	for (desc = ifm_type_descriptions; desc->ifmt_string != NULL;	     desc++) {		if (IFM_TYPE(mword) == desc->ifmt_word)			return (desc->ifmt_string);	}	return ("<unknown type>");}