Changeset 48180 in vbox for trunk/src/VBox/Devices/Network/testcase/tstIntNet-1.cpp
- Timestamp:
- Aug 30, 2013 7:37:03 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/testcase/tstIntNet-1.cpp
r46904 r48180 596 596 } 597 597 598 #ifdef RT_OS_LINUX 599 #include <stdio.h> 600 #include <net/if.h> 601 #include <net/route.h> 602 /** 603 * Obtain the name of the interface used for default routing. 604 * 605 * NOTE: Copied from Main/src-server/linux/NetIf-linux.cpp 606 * 607 * @returns VBox status code. 608 * 609 * @param pszName The buffer of IFNAMSIZ+1 length where to put the name. 610 */ 611 static int getDefaultIfaceName(char *pszName) 612 { 613 FILE *fp = fopen("/proc/net/route", "r"); 614 char szBuf[1024]; 615 char szIfName[17]; 616 uint32_t uAddr; 617 uint32_t uGateway; 618 uint32_t uMask; 619 int iTmp; 620 unsigned uFlags; 621 622 if (fp) 623 { 624 while (fgets(szBuf, sizeof(szBuf)-1, fp)) 625 { 626 int n = sscanf(szBuf, "%16s %x %x %x %d %d %d %x %d %d %d\n", 627 szIfName, &uAddr, &uGateway, &uFlags, &iTmp, &iTmp, &iTmp, 628 &uMask, &iTmp, &iTmp, &iTmp); 629 if (n < 10 || !(uFlags & RTF_UP)) 630 continue; 631 632 if (uAddr == 0 && uMask == 0) 633 { 634 fclose(fp); 635 strncpy(pszName, szIfName, 16); 636 pszName[16] = 0; 637 return VINF_SUCCESS; 638 } 639 } 640 fclose(fp); 641 } 642 return VERR_INTERNAL_ERROR; 643 } 644 #endif /* RT_OS_LINUX */ 645 598 646 599 647 int main(int argc, char **argv) … … 625 673 const char *pszIf = "en0"; 626 674 #elif defined(RT_OS_LINUX) 627 const char *pszIf = "eth0"; 675 char szIf[IFNAMSIZ+1] = "eth0"; /* Reasonable default */ 676 /* 677 * Try to update the default interface by consulting the routing table. 678 * If we fail we still have our reasonable default. 679 */ 680 getDefaultIfaceName(szIf); 681 const char *pszIf = szIf; 628 682 #elif defined(RT_OS_SOLARIS) 629 683 const char* pszIf = "rge0";
Note:
See TracChangeset
for help on using the changeset viewer.