Changeset 25841 in vbox
- Timestamp:
- Jan 14, 2010 6:35:33 PM (15 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ConsoleImpl2.cpp
r25839 r25841 99 99 # include <HostNetworkInterfaceImpl.h> 100 100 # include <netif.h> 101 # include <stdlib.h> 101 102 #endif 102 103 … … 2855 2856 else 2856 2857 { 2857 #ifdef RT_OS_SOLARIS 2858 /* Grab the IP number from the 'vboxnetX' instance number */ 2859 const char *pszInstance = pszHifName; 2860 pszInstance += sizeof("vboxnet") - 1; 2861 int Instance = VBOXNET_IPV4NETPREFIX_DEFAULT + atoi(pszInstance); 2862 char szDefaultIPV4Addr[sizeof(VBOXNET_IPV4ADDR_DEFAULT) + 1]; 2863 RTStrPrintf(szDefaultIPV4Addr, sizeof(szDefaultIPV4Addr), "%s%d.%d", VBOXNET_IPV4NET_DEFAULT, Instance, VBOXNET_IPV4NETHOST_DEFAULT); 2864 hrc = hostInterface->EnableStaticIpConfig(Bstr(szDefaultIPV4Addr), 2858 /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */ 2859 hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHifName)), 2865 2860 Bstr(VBOXNET_IPV4MASK_DEFAULT)); 2866 #else2867 hrc = hostInterface->EnableStaticIpConfig(Bstr(VBOXNET_IPV4ADDR_DEFAULT),2868 Bstr(VBOXNET_IPV4MASK_DEFAULT));2869 #endif2870 2861 } 2871 2862 -
trunk/src/VBox/Main/HostNetworkInterfaceImpl.cpp
r25149 r25841 26 26 #include "netif.h" 27 27 28 #ifndef RT_OS_WINDOWS 29 #include <arpa/inet.h> 30 # ifdef RT_OS_FREEBSD 31 # include <netinet/in.h> /* INADDR_NONE */ 32 # endif 33 #endif /* RT_OS_WINDOWS */ 28 #ifdef RT_OS_FREEBSD 29 # include <netinet/in.h> /* INADDR_NONE */ 30 #endif /* RT_OS_FREEBSD */ 34 31 35 32 // constructor / destructor … … 220 217 if (m.IPAddress == 0) 221 218 { 222 Bstr(VBOXNET_IPV4ADDR_DEFAULT).detachTo(aIPAddress);219 getDefaultIPv4Address(mInterfaceName).detachTo(aIPAddress); 223 220 return S_OK; 224 221 } … … 561 558 hrc = mVBox->GetExtraData(Bstr(Utf8StrFmt("HostOnly/%ls/IPNetMask", mInterfaceName.raw())), tmpMask.asOutParam()); 562 559 if (tmpAddr.isEmpty()) 563 tmpAddr = Bstr(VBOXNET_IPV4ADDR_DEFAULT);560 tmpAddr = getDefaultIPv4Address(mInterfaceName); 564 561 if (tmpMask.isEmpty()) 565 562 tmpMask = Bstr(VBOXNET_IPV4MASK_DEFAULT); -
trunk/src/VBox/Main/include/netif.h
r25829 r25841 27 27 #include <iprt/asm.h> 28 28 29 #define VBOXNET_IPV4ADDR_DEFAULT "192.168.56.1" 30 #define VBOXNET_IPV4NET_DEFAULT "192.168." 31 #define VBOXNET_IPV4NETPREFIX_DEFAULT 56 32 #define VBOXNET_IPV4NETHOST_DEFAULT 1 29 #ifndef RT_OS_WINDOWS 30 #include <arpa/inet.h> 31 #include <stdio.h> 32 #endif /* RT_OS_WINDOWS */ 33 34 #define VBOXNET_IPV4ADDR_DEFAULT 0x0138A8C0 /* 192.168.56.1 */ 33 35 #define VBOXNET_IPV4MASK_DEFAULT "255.255.255.0" 34 36 … … 143 145 } 144 146 147 DECLINLINE(Bstr) getDefaultIPv4Address(Bstr bstrIfName) 148 { 149 /* Get the index from the name */ 150 int iInstance; 151 if (sscanf(Utf8Str(bstrIfName).raw(), "vboxnet%d", &iInstance) != 1) 152 return Bstr("0.0.0.0"); 153 154 in_addr tmp; 155 #if defined(RT_OS_WINDOWS) 156 tmp.S_un.S_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16); 157 #else 158 tmp.s_addr = VBOXNET_IPV4ADDR_DEFAULT + (iInstance << 16); 159 #endif 160 char *addr = inet_ntoa(tmp); 161 return Bstr(addr); 162 } 163 145 164 #endif /* ___netif_h */ 146 165 /* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note:
See TracChangeset
for help on using the changeset viewer.