VBoxNetAdpCtl.cpp revision 613e5cf233371122e87263c07af8f122a17d0224
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * Apps - VBoxAdpCtl, Configuration tool for vboxnetX adapters.
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * available from http://www.virtualbox.org. This file is free software;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * additional information or have any questions.
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync/*******************************************************************************
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync* Header Files *
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync*******************************************************************************/
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync/* @todo Error codes must be moved to some header file */
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync/* @todo These are duplicates from src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#define VBOXNETADP_CTL_ADD _IOR('v', 1, VBOXNETADPREQ)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync#define VBOXNETADP_CTL_REMOVE _IOW('v', 2, VBOXNETADPREQ)
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsyncstatic void showUsage(void)
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync fprintf(stderr, "Usage: VBoxNetAdpCtl <adapter> <address> ([netmask <address>] | remove)\n");
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync fprintf(stderr, " | VBoxNetAdpCtl <adapter> remove\n");
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsyncstatic int executeIfconfig(const char *pcszAdapterName, const char *pcszArg1,
9c11b89c71ca727d975c39f2719063501ddcd03dvboxsync const char * const argv[] =
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync case 0: /* Child process. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync if (execv(VBOXADPCTL_IFCONFIG_PATH, (char * const*)argv) == -1)
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync default: /* Parent process. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsyncstatic bool removeAddresses(const char *pszAdapterName)
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync snprintf(szCmd, sizeof(szCmd), VBOXADPCTL_IFCONFIG_PATH " %s", pszAdapterName);
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync return false;
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync for (cAddrs = 0; cAddrs < MAX_ADDRESSES && fgets(szBuf, sizeof(szBuf), fp);)
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync#if 0 /* Don't use this! assert() breaks the mac build. Use IPRT or be a rectangular building thing. */
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync /* We are concerned with IPv6 address lines only. */
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync /* Skip "addr:". */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync /* Skip link-local addresses. */
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync strncpy(aszAddresses[cAddrs++], pszWord, MAX_ADDRLEN-1);
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync for (int i = 0; i < cAddrs; i++)
ad81f667a6be22bee5e7628bf8cfb849723734c6vboxsync if (executeIfconfig(pszAdapterName, "inet6", VBOXADPCTL_DEL_CMD, aszAddresses[i]) != EXIT_SUCCESS)
3667b9956dd95cfba687d4dc23dabb9a49c1feadvboxsync return false;
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync return true;
72c49feb12a449819b130e1b2255fb785e7c9fb1vboxsync perror("VBoxNetAdpCtl: failed to open " VBOXNETADP_CTL_DEV_NAME);
1d398d1aa90bdac2b68d4f434283746c5838a96dvboxsync perror("VBoxNetAdpCtl: ioctl failed for " VBOXNETADP_CTL_DEV_NAME);
29bdc01040c07a3dd482a94a2cb8f0a90f8587a7vboxsync bool fRemove = false;
fc0e1701814ea969173fadb20fef6833b04fb2bcvboxsync fprintf(stderr, "Invalid argument: %s\n\n", argv[3]);
showUsage();
fRemove = true;
if (rc == 0)
return rc;
showUsage();
if (fRemove)
#ifdef RT_OS_LINUX
return rc;