Changeset 20481 in vbox
- Timestamp:
- Jun 11, 2009 7:30:12 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/linux/NetIf-linux.cpp
r19433 r20481 32 32 #include <net/if.h> 33 33 #include <net/if_arp.h> 34 #include <net/route.h> 34 35 #include <netinet/in.h> 35 36 #include <stdio.h> … … 40 41 #include "netif.h" 41 42 #include "Logging.h" 43 44 static int getDefaultIfaceName(char *pszName) 45 { 46 FILE *fp = fopen("/proc/net/route", "r"); 47 char szBuf[1024]; 48 char szIfName[17]; 49 char szAddr[129]; 50 char szGateway[129]; 51 char szMask[129]; 52 int iTmp; 53 int iFlags; 54 55 while (fgets(szBuf, sizeof(szBuf)-1, fp)) 56 { 57 int n = sscanf(szBuf, "%16s %128s %128s %X %d %d %d %128s %d %d %d\n", 58 szIfName, szAddr, szGateway, &iFlags, &iTmp, &iTmp, &iTmp, 59 szMask, &iTmp, &iTmp, &iTmp); 60 if (n < 10 || !(iFlags & RTF_UP)) 61 continue; 62 63 if (strcmp(szAddr, "00000000") == 0 && strcmp(szMask, "00000000") == 0) 64 { 65 fclose(fp); 66 strncpy(pszName, szIfName, 16); 67 pszName[16] = 0; 68 return VINF_SUCCESS; 69 } 70 } 71 return VERR_INTERNAL_ERROR; 72 } 42 73 43 74 static int getInterfaceInfo(int iSocket, const char *pszName, PNETIFINFO pInfo) … … 122 153 int NetIfList(std::list <ComObjPtr <HostNetworkInterface> > &list) 123 154 { 124 int rc = VINF_SUCCESS; 155 char szDefaultIface[256]; 156 int rc = getDefaultIfaceName(szDefaultIface); 157 if (RT_FAILURE(rc)) 158 { 159 Log(("NetIfList: Failed to find default interface.\n")); 160 szDefaultIface[0] = 0; 161 } 125 162 int sock = socket(AF_INET, SOCK_DGRAM, 0); 126 163 if (sock >= 0) … … 154 191 155 192 if (SUCCEEDED(IfObj->init(Bstr(pszName), enmType, &Info))) 156 list.push_back(IfObj); 193 { 194 if (strcmp(pszName, szDefaultIface) == 0) 195 list.push_front(IfObj); 196 else 197 list.push_back(IfObj); 198 } 157 199 } 158 200
Note:
See TracChangeset
for help on using the changeset viewer.