/* $Id$ */
/** @file
* Main - NetIfList, Linux implementation.
*/
/*
* Copyright (C) 2008-2012 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <list>
#include <stdio.h>
#include <unistd.h>
#include "HostNetworkInterfaceImpl.h"
#include "netif.h"
#include "Logging.h"
/**
* Obtain the name of the interface used for default routing.
*
* NOTE: There is a copy in Devices/Network/testcase/tstIntNet-1.cpp.
*
* @returns VBox status code.
*
* @param pszName The buffer of IFNAMSIZ+1 length where to put the name.
*/
{
int iTmp;
unsigned uFlags;
if (fp)
{
{
continue;
{
pszName[16] = 0;
return VINF_SUCCESS;
}
}
}
return VERR_INTERNAL_ERROR;
}
{
/*
* I wish I could do simple ioctl here, but older kernels require root
* privileges for any ethtool commands.
*/
/* First, we try to retrieve the speed via sysfs. */
if (fp)
{
uSpeed = 0;
}
if (uSpeed == 10)
{
/* Check the cable is plugged in at all */
unsigned uCarrier = 0;
if (fp)
{
uSpeed = 0;
}
}
if (uSpeed == 0)
{
/* Failed to get speed via sysfs, go to plan B. */
if (RT_SUCCESS(rc))
}
return uSpeed;
}
{
// Zeroing out pInfo is a bad idea as it should contain both short and long names at
// this point. So make sure the structure is cleared by the caller if necessary!
// memset(pInfo, 0, sizeof(*pInfo));
{
{
case ARPHRD_ETHER:
break;
default:
break;
}
/* Generate UUID from name and MAC address. */
RTUuidClear(&uuid);
if (fp)
{
for (;;)
{
"%08x%08x%08x%08x"
" %02x %02x %02x %02x %20s\n",
if (n == EOF)
break;
{
n, uLength));
break;
}
{
}
}
}
/*
* Don't even try to get speed for non-Ethernet interfaces, it only
* produces errors.
*/
else
pInfo->uSpeedMbits = 0;
}
return VINF_SUCCESS;
}
{
if (RT_FAILURE(rc))
{
Log(("NetIfList: Failed to find default interface.\n"));
szDefaultIface[0] = 0;
}
if (sock >= 0)
{
if (fp)
{
{
if (!pszEndOfName)
continue;
*pszEndOfName = 0;
if (RT_FAILURE(rc))
break;
{
else
{
else
}
}
}
}
}
else
return rc;
}
{
if (sock < 0)
return VERR_NOT_IMPLEMENTED;
return rc;
}
/**
* Retrieve the physical link speed in megabits per second. If the interface is
* not up or otherwise unavailable the zero speed is returned.
*
* @returns VBox status code.
*
* @param pcszIfName Interface name.
* @param puMbits Where to store the link speed.
*/
{
if (sock < 0)
return VERR_OUT_OF_RESOURCES;
{
{
return VINF_SUCCESS;
}
}
*puMbits = 0;
return VWRN_NOT_FOUND;
}