VirtualBox

Changeset 43994 in vbox for trunk/src/apps/adpctl


Ignore:
Timestamp:
Nov 29, 2012 8:58:17 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82378
Message:

Main/Metrics: Do not collect data for unplugged host interfaces (#6345)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/apps/adpctl/VBoxNetAdpCtl.cpp

    r43516 r43994  
    301301                }
    302302                struct ifreq IfReq;
     303                struct ethtool_value EthToolVal;
    303304                struct ethtool_cmd EthToolReq;
    304305                int fd = socket(AF_INET, SOCK_DGRAM, 0);
     
    310311                    return ADPCTLERR_SOCKET_FAILED;
    311312                }
     313                /* Get link status first. */
     314                memset(&EthToolVal, 0, sizeof(EthToolVal));
    312315                memset(&IfReq, 0, sizeof(IfReq));
    313316                snprintf(IfReq.ifr_name, sizeof(IfReq.ifr_name), "%s", pszAdapterName);
    314                 EthToolReq.cmd = ETHTOOL_GSET;
    315                 IfReq.ifr_data = (caddr_t)&EthToolReq;
     317
     318                EthToolVal.cmd = ETHTOOL_GLINK;
     319                IfReq.ifr_data = (caddr_t)&EthToolVal;
    316320                rc = ioctl(fd, SIOCETHTOOL, &IfReq);
    317321                if (rc == 0)
    318322                {
    319                     printf("%u", EthToolReq.speed);
     323                    if (EthToolVal.data)
     324                    {
     325                        memset(&IfReq, 0, sizeof(IfReq));
     326                        snprintf(IfReq.ifr_name, sizeof(IfReq.ifr_name), "%s", pszAdapterName);
     327                        EthToolReq.cmd = ETHTOOL_GSET;
     328                        IfReq.ifr_data = (caddr_t)&EthToolReq;
     329                        rc = ioctl(fd, SIOCETHTOOL, &IfReq);
     330                        if (rc == 0)
     331                        {
     332                            printf("%u", EthToolReq.speed);
     333                        }
     334                        else
     335                        {
     336                            fprintf(stderr, "VBoxNetAdpCtl: Error while retrieving link "
     337                                    "speed for %s: ", pszAdapterName);
     338                            perror("VBoxNetAdpCtl: ioctl failed");
     339                            rc = ADPCTLERR_IOCTL_FAILED;
     340                        }
     341                    }
     342                    else
     343                        printf("0");
    320344                }
    321345                else
    322346                {
    323347                    fprintf(stderr, "VBoxNetAdpCtl: Error while retrieving link "
    324                             "speed for %s: ", pszAdapterName);
     348                            "status for %s: ", pszAdapterName);
    325349                    perror("VBoxNetAdpCtl: ioctl failed");
    326350                    rc = ADPCTLERR_IOCTL_FAILED;
    327351                }
     352
    328353                close(fd);
    329354                return rc;
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