VBoxNetAdpCtl.cpp revision aafe9fe588edab292546a0e4c1f7eb377fd35df4
/* $Id$ */
/** @file
* Apps - VBoxAdpCtl, Configuration tool for vboxnetX adapters.
*/
/*
* Copyright (C) 2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#ifdef RT_OS_SOLARIS
#endif
/* @todo Error codes must be moved to some header file */
#define ADPCTLERR_NO_CTL_DEV 3
#define ADPCTLERR_IOCTL_FAILED 4
/* @todo These are duplicates from src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h */
#define VBOXNETADP_CTL_DEV_NAME "/dev/vboxnetctl"
#define VBOXNETADP_NAME "vboxnet"
#define VBOXNETADP_MAX_NAME_LEN 32
typedef struct VBoxNetAdpReq
{
char szName[VBOXNETADP_MAX_NAME_LEN];
typedef VBOXNETADPREQ *PVBOXNETADPREQ;
#define VBOXADPCTL_IFCONFIG_PATH "/sbin/ifconfig"
#ifdef RT_OS_LINUX
#define VBOXADPCTL_DEL_CMD "del"
#else
#define VBOXADPCTL_DEL_CMD "delete"
#endif
static void showUsage(void)
{
}
{
const char * const argv[] =
{
pcszArg1, /* [address family] */
pcszArg2, /* address */
pcszArg3, /* ['netmask'] */
pcszArg4, /* [network mask] */
pcszArg5, /* [network mask] */
NULL /* terminator */
};
int rc = EXIT_SUCCESS;
switch (childPid)
{
case -1: /* Something went wrong. */
perror("fork() failed");
rc = EXIT_FAILURE;
break;
case 0: /* Child process. */
rc = EXIT_FAILURE;
break;
default: /* Parent process. */
break;
}
return rc;
}
#define MAX_ADDRESSES 128
#define MAX_ADDRLEN 64
static bool removeAddresses(const char *pszAdapterName)
{
if (!fp)
return false;
int cAddrs;
{
#if 0 /* Don't use this! assert() breaks the mac build. Use IPRT or be a rectangular building thing. */
#endif
/* We are concerned with IPv6 address lines only. */
continue;
#ifdef RT_OS_LINUX
/* Skip "addr:". */
continue;
#endif
/* Skip link-local addresses. */
continue;
}
for (int i = 0; i < cAddrs; i++)
{
return false;
}
return true;
}
{
if (fd == -1)
{
return ADPCTLERR_NO_CTL_DEV;
}
if (rc == -1)
{
}
return rc;
}
{
const char *pszAdapterName;
const char *pszAddress;
const char *pszNetworkMask = NULL;
int rc = EXIT_SUCCESS;
bool fRemove = false;
switch (argc)
{
case 5:
{
showUsage();
return 1;
}
pszOption = "netmask";
break;
case 4:
{
showUsage();
return 1;
}
fRemove = true;
break;
case 3:
{
}
break;
case 2:
{
if (rc == 0)
return rc;
}
/* Fall through */
default:
/* Fall through */
case 1:
showUsage();
return 1;
}
{
return 2;
}
if (fRemove)
{
else
{
#ifdef RT_OS_LINUX
#else
#endif
}
}
else
{
{
/*
* Before we set IPv6 address we'd like to remove
* all previously assigned addresses except the
* self-assigned one.
*/
if (!removeAddresses(pszAdapterName))
rc = EXIT_FAILURE;
else
}
else
}
return rc;
}