static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
#endif
static const char rcsid[] =
- "$Id: ifconfig.c,v 1.5 2003/07/02 01:22:29 lindak Exp $";
+ "$Id: ifconfig.c,v 1.5.28.1 2004/04/14 00:27:17 lindak Exp $";
#endif /* not lint */
#include <sys/param.h>
+#define KERNEL_PRIVATE
#include <sys/ioctl.h>
+#undef KERNEL_PRIVATE
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
+struct ether_addr *ether_aton __P((const char *));
+
#include "ifconfig.h"
/* wrapper for KAME-special getnameinfo() */
#endif
c_func setifipdst;
c_func setifflags, setifmetric, setifmtu, setiflladdr;
+c_func clone_destroy;
+void clone_create(void);
#define NEXTARG 0xffffff
#define NEXTARG2 0xfffffe
{"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 },
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 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 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);
}
*/
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);
}
#define RIDADDR 0
#define ADDR 1
-#define MASK 2
+#define NMASK 2
#define DSTADDR 3
/*ARGSUSED*/
if (*afp->af_getaddr == NULL)
return;
setmask++;
- (*afp->af_getaddr)(addr, MASK);
+ (*afp->af_getaddr)(addr, NMASK);
}
#ifdef INET6
const struct afswtch *afp;
{
if (*afp->af_getprefix)
- (*afp->af_getprefix)(addr, MASK);
+ (*afp->af_getprefix)(addr, NMASK);
explicit_prefix = 1;
}
struct netent *np;
sin->sin_len = sizeof(*sin);
- if (which != MASK)
+ if (which != NMASK)
sin->sin_family = AF_INET;
if (which == ADDR) {
/* 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)) {
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;
}
}
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));
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;
}
#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");
+}