VirtualBox

Ignore:
Timestamp:
Feb 18, 2013 5:26:05 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
83847
Message:

Main/Metrics: Generic implentation of link state and stubs for line speed for all platforms (#6345)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/generic/NetIf-generic.cpp

    r44528 r44742  
    2222#include <iprt/path.h>
    2323#include <iprt/param.h>
     24#include <sys/ioctl.h>
     25#include <netinet/in.h>
     26#include <net/if.h>
     27#include <errno.h>
     28
     29#if defined(RT_OS_SOLARIS)
     30# include <sys/sockio.h>
     31#endif
    2432
    2533#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN)
     
    358366}
    359367
     368/**
     369 * Obtain the current state of the interface.
     370 *
     371 * @returns VBox status code.
     372 *
     373 * @param   pcszIfName  Interface name.
     374 * @param   penmState   Where to store the retrieved state.
     375 */
     376int NetIfGetState(const char *pcszIfName, NETIFSTATUS *penmState)
     377{
     378    int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
     379    if (sock < 0)
     380        return VERR_OUT_OF_RESOURCES;
     381    struct ifreq Req;
     382    memset(&Req, 0, sizeof(Req));
     383    strncpy(Req.ifr_name, pcszIfName, sizeof(Req.ifr_name) - 1);
     384    if (ioctl(sock, SIOCGIFFLAGS, &Req) < 0)
     385    {
     386        Log(("NetIfGetState: ioctl(SIOCGIFFLAGS) -> %d\n", errno));
     387        *penmState = NETIF_S_UNKNOWN;
     388    }
     389    else
     390        *penmState = (Req.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN;
     391    return VINF_SUCCESS;
     392}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette