- Timestamp:
- Dec 13, 2008 6:59:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/solaris/NetIfList-solaris.cpp
r15442 r15446 37 37 38 38 #include <iprt/err.h> 39 39 #include <iprt/ctype.h> 40 #include <list> 41 42 #include "HostNetworkInterfaceImpl.h" 40 43 #include "netif.h" 41 44 42 #include <list> 45 #ifdef VBOX_WITH_HOSTNETIF_API 46 43 47 #include <map> 44 45 #ifdef VBOX_WITH_HOSTNETIF_API 46 48 #include <string> 47 49 #include <fcntl.h> 48 50 #include <unistd.h> … … 61 63 #include <sys/types.h> 62 64 63 static void vboxSolarisAddHostIface(char *pszIface, int Instance, PCRTMAC pMac, void *pvHostNetworkInterfaceList) 65 #include "DynLoadLibSolaris.h" 66 67 static void vboxSolarisAddHostIface(char *pszIface, int Instance, void *pvHostNetworkInterfaceList) 64 68 { 65 69 std::list<ComObjPtr <HostNetworkInterface> > *pList = (std::list<ComObjPtr <HostNetworkInterface> > *)pvHostNetworkInterfaceList; … … 113 117 RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - Ethernet", szNICInstance); 114 118 119 NETIFINFO Info; 120 memset(&Info, 0, sizeof(Info)); 121 int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 122 if (Sock > 0) 123 { 124 struct lifreq IfReq; 125 strcpy(IfReq.lifr_name, szNICInstance); 126 if (ioctl(Sock, SIOCGLIFADDR, &IfReq) >= 0) 127 { 128 memcpy(Info.IPAddress.au8, ((struct sockaddr *)&IfReq.lifr_addr)->sa_data, 129 sizeof(Info.IPAddress.au8)); 130 // SIOCGLIFNETMASK 131 struct arpreq ArpReq; 132 memcpy(&ArpReq.arp_pa, &IfReq.lifr_addr, sizeof(struct sockaddr_in)); 133 134 /* 135 * We might fail if the interface has not been assigned an IP address. 136 * That doesn't matter; as long as it's plumbed we can pick it up. 137 * But, if it has not acquired an IP address we cannot obtain it's MAC 138 * address this way, so we just use all zeros there. 139 */ 140 if (ioctl(Sock, SIOCGARP, &ArpReq) >= 0) 141 memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress)); 142 143 } 144 145 if (ioctl(Sock, SIOCGLIFNETMASK, &IfReq) >= 0) 146 { 147 memcpy(Info.IPNetMask.au8, ((struct sockaddr *)&IfReq.lifr_addr)->sa_data, 148 sizeof(Info.IPNetMask.au8)); 149 } 150 if (ioctl(Sock, SIOCGLIFFLAGS, &IfReq) >= 0) 151 { 152 Info.enmStatus = IfReq.lifr_flags & IFF_UP ? NETIF_S_UP : NETIF_S_DOWN; 153 } 154 close(Sock); 155 } 115 156 /* 116 157 * Construct UUID with interface name and the MAC address if available. … … 121 162 Uuid.Gen.u8ClockSeqHiAndReserved = (Uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80; 122 163 Uuid.Gen.u16TimeHiAndVersion = (Uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000; 123 if (pMac) 124 { 125 Uuid.Gen.au8Node[0] = pMac->au8[0]; 126 Uuid.Gen.au8Node[1] = pMac->au8[1]; 127 Uuid.Gen.au8Node[2] = pMac->au8[2]; 128 Uuid.Gen.au8Node[3] = pMac->au8[3]; 129 Uuid.Gen.au8Node[4] = pMac->au8[4]; 130 Uuid.Gen.au8Node[5] = pMac->au8[5]; 131 } 164 Uuid.Gen.au8Node[0] = Info.MACAddress.au8[0]; 165 Uuid.Gen.au8Node[1] = Info.MACAddress.au8[1]; 166 Uuid.Gen.au8Node[2] = Info.MACAddress.au8[2]; 167 Uuid.Gen.au8Node[3] = Info.MACAddress.au8[3]; 168 Uuid.Gen.au8Node[4] = Info.MACAddress.au8[4]; 169 Uuid.Gen.au8Node[5] = Info.MACAddress.au8[5]; 170 Info.Uuid = Uuid; 132 171 133 172 ComObjPtr<HostNetworkInterface> IfObj; … … 169 208 * Add the interface. 170 209 */ 171 vboxSolarisAddHostIface(szIfaceName, Instance, NULL,pvHostNetworkInterfaceList);210 vboxSolarisAddHostIface(szIfaceName, Instance, pvHostNetworkInterfaceList); 172 211 173 212 /* … … 214 253 return DI_WALK_CONTINUE; 215 254 216 vboxSolarisAddHostIface(di_driver_name(Node), di_instance(Node), NULL,pvHostNetworkInterfaceList);255 vboxSolarisAddHostIface(di_driver_name(Node), di_instance(Node), pvHostNetworkInterfaceList); 217 256 return DI_WALK_CONTINUE; 218 257 } … … 275 314 continue; 276 315 277 NETIFINFO Info; 278 memset(&Info, 0, sizeof(Info)); 316 #if 0 279 317 rc = ioctl(Sock, SIOCGLIFADDR, &(Ifaces[i])); 280 318 if (rc >= 0) 281 319 { 282 memcpy(Info.IPAddress.au8, &Ifaces[i].lifr_addr.sa_data, Info.IPAddress.au8); 320 memcpy(Info.IPAddress.au8, ((struct sockaddr *)&Ifaces[i].lifr_addr)->sa_data, 321 sizeof(Info.IPAddress.au8)); 283 322 // SIOCGLIFNETMASK 284 323 struct arpreq ArpReq; … … 295 334 memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress)); 296 335 297 #if 0298 336 char szNICDesc[LIFNAMSIZ + 256]; 299 337 char *pszIface = Ifaces[i].lifr_name; … … 301 339 302 340 vboxSolarisAddLinkHostIface(pszIface, &list); 341 } 303 342 #endif 304 } 305 306 rc = ioctl(Sock, SIOCGLIFNETMASK, &(Ifaces[i])); 307 if (rc >= 0) 308 { 309 memcpy(Info.IPNetMask.au8, &Ifaces[i].lifr_addr.sa_data, Info.IPNetMask.au8); 310 } 311 rc = ioctl(Sock, SIOCGLIFFLAGS, &(Ifaces[i])); 312 if (rc >= 0) 313 { 314 Info.enmStatus = Ifaces[i].lifr_flags & IFF_UP ? NETIF_S_UP : NETIF_S_DOWN; 315 } 343 316 344 char *pszIface = Ifaces[i].lifr_name; 317 345 vboxSolarisAddLinkHostIface(pszIface, &list);
Note:
See TracChangeset
for help on using the changeset viewer.