VirtualBox

Ignore:
Timestamp:
Oct 2, 2012 1:22:31 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
81089
Message:

Main/Metrics: Alternative way to get link speed for old kernels (#6345)

File:
1 edited

Legend:

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

    r42994 r43507  
    7777    Utf8Str strName(interfaceName);
    7878    return NetIfAdpCtl(strName.c_str(), pszAddr, pszOption, pszMask);
     79}
     80
     81int NetIfAdpCtlOut(const char * pcszName, const char * pcszCmd, char *pszBuffer, size_t cBufSize)
     82{
     83    char szAdpCtl[RTPATH_MAX];
     84    int rc = RTPathExecDir(szAdpCtl, sizeof(szAdpCtl) - sizeof("/" VBOXNETADPCTL_NAME " ") - strlen(pcszCmd));
     85    if (RT_FAILURE(rc))
     86    {
     87        LogRel(("NetIfAdpCtlStream: Failed to get program path, rc=%Rrc\n", rc));
     88        return VERR_INVALID_PARAMETER;
     89    }
     90    strcat(szAdpCtl, "/" VBOXNETADPCTL_NAME " ");
     91    if (pcszName && strlen(pcszName) <= RTPATH_MAX - strlen(szAdpCtl) - 1 - strlen(pcszCmd))
     92    {
     93        strcat(szAdpCtl, pcszName);
     94        strcat(szAdpCtl, " ");
     95        strcat(szAdpCtl, pcszCmd);
     96    }
     97    else
     98    {
     99        LogRel(("NetIfAdpCtlStream: Command line is too long: %s%s %s\n", szAdpCtl, pcszName, pcszCmd));
     100        return VERR_INVALID_PARAMETER;
     101    }
     102    if (strlen(szAdpCtl) < RTPATH_MAX - sizeof(" 2>&1"))
     103        strcat(szAdpCtl, " 2>&1");
     104    FILE *fp = popen(szAdpCtl, "r");
     105    if (fp)
     106    {
     107        if (fgets(pszBuffer, cBufSize, fp))
     108        {
     109            if (!strncmp(VBOXNETADPCTL_NAME ":", pszBuffer, sizeof(VBOXNETADPCTL_NAME)))
     110            {
     111                LogRel(("NetIfAdpCtlStream: %s", pszBuffer));
     112                rc = VERR_INTERNAL_ERROR;
     113            }
     114        }
     115        else
     116        {
     117            LogRel(("NetIfAdpCtlStream: No output from " VBOXNETADPCTL_NAME));
     118            rc = VERR_INTERNAL_ERROR;
     119        }
     120        pclose(fp);
     121    }
     122    return rc;
    79123}
    80124
Note: See TracChangeset for help on using the changeset viewer.

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