HostNetworkInterfaceImpl.cpp revision 280704ef57afc4bfa7cb0f6a6d2f212dbf3ead34
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2008 Oracle Corporation
*
* 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.
*/
#include "HostNetworkInterfaceImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "netif.h"
#ifdef RT_OS_FREEBSD
#endif /* RT_OS_FREEBSD */
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
}
{
}
{
return BaseFinalConstruct();
}
void HostNetworkInterface::FinalRelease()
{
uninit ();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the host object.
*
* @returns COM result indicator
* @param aInterfaceName name of the network interface
* @param aGuid GUID of the host network interface
*/
HRESULT HostNetworkInterface::init(Bstr aInterfaceName, Guid aGuid, HostNetworkInterfaceType_T ifType)
{
LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization */
return S_OK;
}
#ifdef VBOX_WITH_HOSTNETIF_API
{
if (RT_SUCCESS(rc))
{
m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&info.IPv6NetMask);
#ifdef RT_OS_WINDOWS
#else /* !RT_OS_WINDOWS */
#endif /* !RT_OS_WINDOWS */
return S_OK;
}
}
/**
* Initializes the host object.
*
* @returns COM result indicator
* @param aInterfaceName name of the network interface
* @param aGuid GUID of the host network interface
*/
HRESULT HostNetworkInterface::init (Bstr aInterfaceName, HostNetworkInterfaceType_T ifType, PNETIFINFO pIf)
{
// LogFlowThisFunc(("aInterfaceName={%ls}, aGuid={%s}\n",
// aInterfaceName.raw(), aGuid.toString().raw()));
// ComAssertRet(aInterfaceName, E_INVALIDARG);
// ComAssertRet(!aGuid.isEmpty(), E_INVALIDARG);
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
m.realIPV6PrefixLength = m.IPV6NetworkMaskPrefixLength = composeIPv6PrefixLenghFromAddress(&pIf->IPv6NetMask);
#ifdef RT_OS_WINDOWS
#else /* !RT_OS_WINDOWS */
#endif /* !RT_OS_WINDOWS */
/* Confirm a successful initialization */
return S_OK;
}
#endif
// IHostNetworkInterface properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns the name of the host network interface.
*
* @returns COM status code
* @param aInterfaceName address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Returns the GUID of the host network interface.
*
* @returns COM status code
* @param aGuid address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
*aDhcpEnabled = m.dhcpEnabled;
return S_OK;
}
/**
* Returns the IP address of the host network interface.
*
* @returns COM status code
* @param aIPAddress address of result pointer
*/
{
AutoCaller autoCaller(this);
if (m.IPAddress == 0)
{
return S_OK;
}
#if defined(RT_OS_WINDOWS)
#else
#endif
if (addr)
{
return S_OK;
}
return E_FAIL;
}
/**
* Returns the netwok mask of the host network interface.
*
* @returns COM status code
* @param aNetworkMask address of result pointer
*/
{
AutoCaller autoCaller(this);
if (m.networkMask == 0)
{
return S_OK;
}
#if defined(RT_OS_WINDOWS)
#else
#endif
if (addr)
{
return S_OK;
}
return E_FAIL;
}
{
#if defined(RT_OS_WINDOWS)
*aIPV6Supported = FALSE;
#else
*aIPV6Supported = TRUE;
#endif
return S_OK;
}
/**
* Returns the IP V6 address of the host network interface.
*
* @returns COM status code
* @param aIPV6Address address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Returns the IP V6 network mask of the host network interface.
*
* @returns COM status code
* @param aIPV6Mask address of result pointer
*/
STDMETHODIMP HostNetworkInterface::COMGETTER(IPV6NetworkMaskPrefixLength) (ULONG *aIPV6NetworkMaskPrefixLength)
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Returns the hardware address of the host network interface.
*
* @returns COM status code
* @param aHardwareAddress address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Returns the encapsulation protocol type of the host network interface.
*
* @returns COM status code
* @param aType address of result pointer
*/
{
AutoCaller autoCaller(this);
*aType = m.mediumType;
return S_OK;
}
/**
* Returns the current state of the host network interface.
*
* @returns COM status code
* @param aStatus address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
/**
* Returns network interface type
*
* @returns COM status code
* @param aType address of result pointer
*/
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
AutoCaller autoCaller(this);
{
if (m.IPAddress)
{
if (RT_SUCCESS(rc))
{
m.realIPAddress = 0;
if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(), NULL)))
return E_FAIL;
if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(), NULL)))
return E_FAIL;
return S_OK;
}
}
else
return S_OK;
}
if (ip != INADDR_NONE)
{
mask = 0xFFFFFF;
else
if (mask != INADDR_NONE)
{
return S_OK;
if (RT_SUCCESS(rc))
{
m.realIPAddress = ip;
m.realNetworkMask = mask;
if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(), Bstr(aIPAddress).raw())))
return E_FAIL;
if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(), Bstr(aNetMask).raw())))
return E_FAIL;
return S_OK;
}
else
{
}
}
}
return E_FAIL;
#endif
}
STDMETHODIMP HostNetworkInterface::EnableStaticIpConfigV6 (IN_BSTR aIPV6Address, ULONG aIPV6MaskPrefixLength)
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
if (!aIPV6Address)
return E_INVALIDARG;
if (aIPV6MaskPrefixLength > 128)
return E_INVALIDARG;
AutoCaller autoCaller(this);
{
if (aIPV6MaskPrefixLength == 0)
aIPV6MaskPrefixLength = 64;
rc = NetIfEnableStaticIpConfigV6(mVBox, this, m.IPV6Address.raw(), aIPV6Address, aIPV6MaskPrefixLength);
if (RT_FAILURE(rc))
{
}
else
{
if (FAILED(mVBox->SetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", mInterfaceName.raw()).raw(), Bstr(aIPV6Address).raw())))
return E_FAIL;
return E_FAIL;
}
}
return S_OK;
#endif
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
AutoCaller autoCaller(this);
if (RT_FAILURE(rc))
{
}
return S_OK;
#endif
}
{
#ifndef VBOX_WITH_HOSTNETIF_API
return E_NOTIMPL;
#else
AutoCaller autoCaller(this);
if (RT_FAILURE(rc))
{
}
return S_OK;
#endif
}
{
AutoCaller autoCaller(this);
#if !defined(RT_OS_WINDOWS)
/* If IPv4 address hasn't been initialized */
{
HRESULT hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPAddress", mInterfaceName.raw()).raw(), tmpAddr.asOutParam());
hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw()).raw(), tmpMask.asOutParam());
}
if (m.IPV6Address.isEmpty())
{
HRESULT hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6Address", mInterfaceName.raw()).raw(), m.IPV6Address.asOutParam());
if (!m.IPV6Address.isEmpty())
{
hrc = mVBox->GetExtraData(BstrFmt("HostOnly/%ls/IPV6PrefixLen", mInterfaceName.raw()).raw(), tmpPrefixLen.asOutParam());
else
m.IPV6NetworkMaskPrefixLength = 64;
}
}
#endif
return S_OK;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */