X-Git-Url: https://git.saurik.com/apple/network_cmds.git/blobdiff_plain/7ba0088d6898d7fd2873f736f1f556673a8be855..7902cf7ebc800a8fa50568a473e718c925f2af80:/ifconfig.tproj/ifconfig.c diff --git a/ifconfig.tproj/ifconfig.c b/ifconfig.tproj/ifconfig.c index 39f344a..8d71e86 100644 --- a/ifconfig.tproj/ifconfig.c +++ b/ifconfig.tproj/ifconfig.c @@ -42,11 +42,13 @@ static const char copyright[] = static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94"; #endif static const char rcsid[] = - "$Id: ifconfig.c,v 1.4 2002/03/05 20:35:12 lindak Exp $"; + "$Id: ifconfig.c,v 1.5.28.1 2004/04/14 00:27:17 lindak Exp $"; #endif /* not lint */ #include +#define KERNEL_PRIVATE #include +#undef KERNEL_PRIVATE #include #include #include @@ -86,6 +88,8 @@ static const char rcsid[] = #include #include +struct ether_addr *ether_aton __P((const char *)); + #include "ifconfig.h" /* wrapper for KAME-special getnameinfo() */ @@ -164,8 +168,10 @@ c_func2 setip6lifetime; #endif c_func setifipdst; c_func setifflags, setifmetric, setifmtu, setiflladdr; +c_func clone_destroy; +void clone_create(void); #define NEXTARG 0xffffff #define NEXTARG2 0xfffffe @@ -231,10 +237,8 @@ struct cmd { {"create", 0, clone_create }, {"plumb", 0, clone_create }, #endif -#ifndef __APPLE__ {"destroy", 0, clone_destroy }, {"unplumb", 0, clone_destroy }, -#endif #ifdef USE_IEEE80211 { "ssid", NEXTARG, set80211ssid }, { "nwid", NEXTARG, set80211ssid }, @@ -357,23 +361,21 @@ void usage() { #ifndef INET6 - fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: ifconfig interface address_family [address [dest_address]]", - " [parameters]", - " ifconfig -C", - " ifconfig interface create", - " ifconfig -a [-d] [-m] [-u] [address_family]", - " ifconfig -l [-d] [-u] [address_family]", - " ifconfig [-d] [-m] [-u]"); + fprintf(stderr, "%s", + "usage: ifconfig interface address_family [address [dest_address]]\n" + " [parameters]\n" + " ifconfig interface create\n" + " ifconfig -a [-d] [-m] [-u] [address_family]\n" + " ifconfig -l [-d] [-u] [address_family]\n" + " ifconfig [-d] [-m] [-u]\n"); #else - fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n", - "usage: ifconfig [-L] interface address_family [address [dest_address]]", - " [parameters]", - " ifconfig -C", - " ifconfig interface create", - " ifconfig -a [-L] [-d] [-m] [-u] [address_family]", - " ifconfig -l [-d] [-u] [address_family]", - " ifconfig [-L] [-d] [-m] [-u]"); + fprintf(stderr, "%s", + "usage: ifconfig [-L] interface address_family [address [dest_address]]\n" + " [parameters]\n" + " ifconfig interface create\n" + " ifconfig -a [-L] [-d] [-m] [-u] [address_family]\n" + " ifconfig -l [-d] [-u] [address_family]\n" + " ifconfig [-L] [-d] [-m] [-u]\n"); #endif exit(1); } @@ -475,9 +477,7 @@ main(argc, argv) */ if (argc > 0 && (strcmp(argv[0], "create") == 0 || strcmp(argv[0], "plumb") == 0)) { -#ifndef __APPLE__ clone_create(); -#endif argc--, argv++; if (argc == 0) exit(0); @@ -696,7 +696,7 @@ ifconfig(argc, argv, afp) } #define RIDADDR 0 #define ADDR 1 -#define MASK 2 +#define NMASK 2 #define DSTADDR 3 /*ARGSUSED*/ @@ -806,7 +806,7 @@ setifnetmask(addr, dummy, s, afp) if (*afp->af_getaddr == NULL) return; setmask++; - (*afp->af_getaddr)(addr, MASK); + (*afp->af_getaddr)(addr, NMASK); } #ifdef INET6 @@ -818,7 +818,7 @@ setifprefixlen(addr, dummy, s, afp) const struct afswtch *afp; { if (*afp->af_getprefix) - (*afp->af_getprefix)(addr, MASK); + (*afp->af_getprefix)(addr, NMASK); explicit_prefix = 1; } @@ -1465,7 +1465,7 @@ in_getaddr(s, which) struct netent *np; sin->sin_len = sizeof(*sin); - if (which != MASK) + if (which != NMASK) sin->sin_family = AF_INET; if (which == ADDR) { @@ -1475,7 +1475,7 @@ in_getaddr(s, which) /* address is `name/masklen' */ int masklen; int ret; - struct sockaddr_in *min = sintab[MASK]; + struct sockaddr_in *min = sintab[NMASK]; *p = '\0'; ret = sscanf(p+1, "%u", &masklen); if(ret != 1 || (masklen < 0 || masklen > 32)) { @@ -1517,14 +1517,14 @@ in6_getaddr(s, which) newaddr &= 1; sin->sin6_len = sizeof(*sin); - if (which != MASK) + if (which != NMASK) sin->sin6_family = AF_INET6; if (which == ADDR) { char *p = NULL; if((p = strrchr(s, '/')) != NULL) { *p = '\0'; - in6_getprefix(p + 1, MASK); + in6_getprefix(p + 1, NMASK); explicit_prefix = 1; } } @@ -1553,7 +1553,7 @@ in6_getprefix(plen, which) if ((len < 0) || (len > 128)) errx(1, "%s: bad value", plen); sin->sin6_len = sizeof(*sin); - if (which != MASK) + if (which != NMASK) sin->sin6_family = AF_INET6; if ((len == 0) || (len == 128)) { memset(&sin->sin6_addr, 0xff, sizeof(struct in6_addr)); @@ -1611,7 +1611,7 @@ ether_getaddr(addr, which) ea = ether_aton(addr); if (ea == NULL) errx(1, "malformed ether address"); - if (which == MASK) + if (which == NMASK) errx(1, "Ethernet does not use netmasks"); sea->sa_family = AF_LINK; sea->sa_len = ETHER_ADDR_LEN; @@ -1680,3 +1680,33 @@ sec2str(total) } #endif /*INET6*/ +void +clone_create(void) +{ + int s; + + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s == -1) + err(1, "socket"); + + memset(&ifr, 0, sizeof(ifr)); + (void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + if (ioctl(s, SIOCIFCREATE, &ifr) < 0) + err(1, "SIOCIFCREATE"); + + if (strcmp(name, ifr.ifr_name) != 0) { + printf("%s\n", ifr.ifr_name); + strlcpy(name, ifr.ifr_name, sizeof(name)); + } + + close(s); +} + +void +clone_destroy(const char *val, int d, int s, const struct afswtch *rafp) +{ + + (void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + if (ioctl(s, SIOCIFDESTROY, &ifr) < 0) + err(1, "SIOCIFDESTROY"); +}