summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2000-07-12 16:41:47 +0000
committerjhb <jhb@FreeBSD.org>2000-07-12 16:41:47 +0000
commit16f88d4b690af7f1a6b7b9cfd5721f7a60c53fa7 (patch)
treecec87519e709e6252618b7ed0fa1ef460708aeac /sbin
parenta0611dac11da5a5f15fc55fbaf0375b9c7574662 (diff)
downloadFreeBSD-src-16f88d4b690af7f1a6b7b9cfd5721f7a60c53fa7.zip
FreeBSD-src-16f88d4b690af7f1a6b7b9cfd5721f7a60c53fa7.tar.gz
Add support to the 'ether' address family to support setting of addresses.
This allows you to set ether addresses with 'ifconfig ether'. Also, use some saner socket address families that allow several special case tests to be removed.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ifconfig/ifconfig.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 52d403d..3642464 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -227,7 +227,7 @@ typedef void af_getaddr __P((const char *, int));
typedef void af_getprefix __P((const char *, int));
af_status in_status, ipx_status, at_status, ether_status;
-af_getaddr in_getaddr, ipx_getaddr, at_getaddr;
+af_getaddr in_getaddr, ipx_getaddr, at_getaddr, ether_getaddr;
#ifdef INET6
af_status in6_status;
@@ -268,13 +268,14 @@ struct afswtch {
{ "ns", AF_NS, xns_status, xns_getaddr, NULL,
SIOCDIFADDR, SIOCAIFADDR, C(ridreq), C(addreq) },
#endif
- { "ether", AF_INET, ether_status, NULL, NULL }, /* XXX not real!! */
+ { "ether", AF_LINK, ether_status, ether_getaddr, NULL,
+ 0, SIOCSIFLLADDR, NULL, C(ridreq) },
#if 0 /* XXX conflicts with the media command */
#ifdef USE_IF_MEDIA
- { "media", AF_INET, media_status, NULL, NULL, }, /* XXX not real!! */
+ { "media", AF_UNSPEC, media_status, NULL, NULL, }, /* XXX not real!! */
#endif
#ifdef USE_VLANS
- { "vlan", AF_INET, media_status, NULL, NULL, }, /* XXX not real!! */
+ { "vlan", AF_UNSPEC, vlan_status, NULL, NULL, }, /* XXX not real!! */
#endif
#endif
{ 0, 0, 0, 0 }
@@ -541,7 +542,7 @@ ifconfig(argc, argv, afp)
if (afp == NULL)
afp = &afs[0];
- ifr.ifr_addr.sa_family = afp->af_af;
+ ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
@@ -653,7 +654,7 @@ setifaddr(addr, param, s, afp)
* and the flags may change when the address is set.
*/
setaddr++;
- if (doalias == 0)
+ if (doalias == 0 && afp->af_af != AF_LINK)
clearaddr = 1;
(*afp->af_getaddr)(addr, (doalias >= 0 ? ADDR : RIDADDR));
}
@@ -869,7 +870,7 @@ status(afp, addrcount, sdl, ifm, ifam)
} else
allfamilies = 0;
- ifr.ifr_addr.sa_family = afp->af_af;
+ ifr.ifr_addr.sa_family = afp->af_af == AF_LINK ? AF_INET : afp->af_af;
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0)
@@ -908,26 +909,12 @@ status(afp, addrcount, sdl, ifm, ifam)
&info);
if (!allfamilies) {
- if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family &&
-#ifdef USE_IF_MEDIA
- afp->af_status != media_status &&
-#endif
-#ifdef USE_VLANS
- afp->af_status != vlan_status &&
-#endif
- afp->af_status != ether_status) {
+ if (afp->af_af == info.rti_info[RTAX_IFA]->sa_family) {
p = afp;
(*p->af_status)(s, &info);
}
} else for (p = afs; p->af_name; p++) {
- if (p->af_af == info.rti_info[RTAX_IFA]->sa_family &&
-#ifdef USE_IF_MEDIA
- p->af_status != media_status &&
-#endif
-#ifdef USE_VLANS
- p->af_status != vlan_status &&
-#endif
- p->af_status != ether_status)
+ if (p->af_af == info.rti_info[RTAX_IFA]->sa_family)
(*p->af_status)(s, &info);
}
addrcount--;
@@ -1402,6 +1389,24 @@ at_getaddr(addr, which)
sat->sat_addr.s_node = node;
}
+void
+ether_getaddr(addr, which)
+ const char *addr;
+ int which;
+{
+ struct ether_addr *ea;
+ struct sockaddr *sea = &ridreq.ifr_addr;
+
+ ea = ether_aton(addr);
+ if (ea == NULL)
+ errx(1, "malformed ether address");
+ if (which == MASK)
+ errx(1, "Ethernet does not use netmasks");
+ sea->sa_family = AF_LINK;
+ sea->sa_len = ETHER_ADDR_LEN;
+ bcopy(ea, sea->sa_data, ETHER_ADDR_LEN);
+}
+
/* XXX FIXME -- should use strtoul for better parsing. */
void
setatrange(range, dummy, s, afp)
OpenPOWER on IntegriCloud