Index: src/VBox/Devices/Network/DrvNAT.cpp =================================================================== --- src/VBox/Devices/Network/DrvNAT.cpp (revision 9562) +++ src/VBox/Devices/Network/DrvNAT.cpp (working copy) @@ -37,7 +37,6 @@ #include "Builtins.h" - /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ Index: src/VBox/Devices/Network/DrvTAP.cpp =================================================================== --- src/VBox/Devices/Network/DrvTAP.cpp (revision 9562) +++ src/VBox/Devices/Network/DrvTAP.cpp (working copy) @@ -43,6 +43,9 @@ #include #include +#ifdef RT_OS_DARWIN +#include +#endif #ifdef RT_OS_SOLARIS # include # include @@ -75,6 +78,7 @@ #include "Builtins.h" + /******************************************************************************* * Structures and Typedefs * *******************************************************************************/ @@ -249,6 +253,38 @@ * Wait for something to become available. */ struct pollfd aFDs[2]; + +#ifdef RT_OS_DARWIN + fd_set r; + fd_set w; + fd_set e; + FD_ZERO(&r); + FD_ZERO(&w); + FD_ZERO(&e); + FD_SET(pData->FileDevice, &r); + FD_SET(pData->PipeRead, &r); + FD_SET(pData->PipeRead, &e); + STAM_PROFILE_ADV_STOP(&pData->StatReceive, a); + errno=0; + struct timeval tv; + tv.tv_sec = 10; + tv.tv_usec = 0; + int rc = select(pData->FileDevice>pData->PipeRead?pData->FileDevice+1:pData->PipeRead+1, + &r, &w, &e, NULL); + aFDs[0].revents = 0; + aFDs[1].revents = 0; + if(rc > 0) { + if(FD_ISSET(pData->FileDevice, &r)) { + aFDs[0].revents|=POLLIN; + } + if(FD_ISSET(pData->PipeRead, &r)) { + aFDs[1].revents|=POLLIN; + } + if(FD_ISSET(pData->PipeRead, &e)) { + aFDs[1].revents|=POLLERR; + } + } +#else aFDs[0].fd = pData->FileDevice; aFDs[0].events = POLLIN | POLLPRI; aFDs[0].revents = 0; @@ -258,6 +294,7 @@ STAM_PROFILE_ADV_STOP(&pData->StatReceive, a); errno=0; int rc = poll(&aFDs[0], ELEMENTS(aFDs), -1 /* infinite */); +#endif /* this might have changed in the meantime */ if (pThread->enmState != PDMTHREADSTATE_RUNNING) @@ -346,7 +383,9 @@ size_t cbRead; RTFileRead(pData->PipeRead, &ch, 1, &cbRead); } - else + else if(rc == 0) { + + } else { /* * poll() failed for some reason. Yield to avoid eating too much CPU. Index: src/VBox/Devices/Makefile.kmk =================================================================== --- src/VBox/Devices/Makefile.kmk (revision 9562) +++ src/VBox/Devices/Makefile.kmk (working copy) @@ -555,7 +555,7 @@ Storage/DrvHostFloppy% \ , $(Drivers_SOURCES)) \ Audio/coreaudio.c -Drivers_SOURCES.darwin = +Drivers_SOURCES.darwin = Network/DrvTAP.cpp endif # darwin ifeq ($(KBUILD_TARGET),freebsd) Index: src/VBox/Devices/Builtins.cpp =================================================================== --- src/VBox/Devices/Builtins.cpp (revision 9562) +++ src/VBox/Devices/Builtins.cpp (working copy) @@ -202,7 +202,7 @@ if (VBOX_FAILURE(rc)) return rc; #endif -#if defined(RT_OS_L4) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || (defined(RT_OS_SOLARIS) && !defined(RT_OS_SOLARIS_10)) || defined(RT_OS_WINDOWS) +#if defined(RT_OS_L4) || defined(RT_OS_LINUX) || defined(RT_OS_OS2) || (defined(RT_OS_SOLARIS) && !defined(RT_OS_SOLARIS_10)) || defined(RT_OS_WINDOWS) || defined(RT_OS_DARWIN) rc = pCallbacks->pfnRegister(pCallbacks, &g_DrvHostInterface); if (VBOX_FAILURE(rc)) return rc; Index: src/VBox/Frontends/VBoxManage/VBoxManage.cpp =================================================================== --- src/VBox/Frontends/VBoxManage/VBoxManage.cpp (revision 9562) +++ src/VBox/Frontends/VBoxManage/VBoxManage.cpp (working copy) @@ -378,7 +378,7 @@ #endif " [-gueststatisticsinterval ]\n" ); - if (fLinux) + if (fLinux || fDarwin) { RTPrintf(" [-tapsetup<1-N> none|]\n" " [-tapterminate<1-N> none|]\n"); @@ -3733,7 +3733,7 @@ std::vector hostifdev (NetworkAdapterCount, 0); std::vector intnet (NetworkAdapterCount, 0); std::vector natnet (NetworkAdapterCount, 0); -#ifdef RT_OS_LINUX +#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) std::vector tapsetup (NetworkAdapterCount, 0); std::vector tapterm (NetworkAdapterCount, 0); #endif @@ -4063,7 +4063,7 @@ } i++; } -#ifdef RT_OS_LINUX +#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) else if (strncmp(argv[i], "-tapsetup", 9) == 0) { unsigned n = parseNum(&argv[i][9], NetworkAdapterCount, "NIC"); @@ -5102,7 +5102,7 @@ { CHECK_ERROR_RET(nic, COMSETTER(NATNetwork)(Bstr(natnet[n])), 1); } -#ifdef RT_OS_LINUX +#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) /* the TAP setup application? */ if (tapsetup[n]) { Index: src/VBox/Main/ConsoleImpl.cpp =================================================================== --- src/VBox/Main/ConsoleImpl.cpp (revision 9562) +++ src/VBox/Main/ConsoleImpl.cpp (working copy) @@ -23,7 +23,6 @@ #if defined(RT_OS_WINDOWS) #elif defined(RT_OS_LINUX) -# include # include # include # include @@ -37,6 +36,7 @@ #elif defined(VBOX_WITH_UNIXY_TAP_NETWORKING) # include # include +# include #endif #include "ConsoleImpl.h" @@ -5066,7 +5066,7 @@ Bstr &tapSetupApplication) { LogFlowThisFunc(("\n")); -#ifdef RT_OS_LINUX +#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) /* Command line to start the script with. */ char szCommand[4096]; /* Result code */ @@ -5310,7 +5310,49 @@ } #elif defined(RT_OS_DARWIN) /** @todo Implement tap networking for Darwin. */ + Bstr tapDeviceName; int rcVBox = VERR_NOT_IMPLEMENTED; + rc = networkAdapter->COMGETTER(HostInterface)(tapDeviceName.asOutParam()); + if (SUCCEEDED(rc)) + { + if (!tapDeviceName.isEmpty()) { + Utf8Str str(tapDeviceName); + rcVBox = RTFileOpen(&maTapFD[slot], str.raw(), + RTFILE_O_READWRITE | RTFILE_O_OPEN | RTFILE_O_DENY_NONE | RTFILE_O_INHERIT); + + if (SUCCEEDED(rc)) + { + Bstr tapSetupApplication; + networkAdapter->COMGETTER(TAPSetupApplication)(tapSetupApplication.asOutParam()); + if (tapSetupApplication.isEmpty()) + { + if (tapDeviceName.isEmpty()) + { + LogRel(("No setup application was supplied for the TAP interface.\n")); + rc = setError(E_FAIL, tr ("No setup application was supplied for the host networking interface")); + } + } + else + { + rc = callTapSetupApplication(true, maTapFD[slot], tapDeviceName, + tapSetupApplication); + } + } + + + if (SUCCEEDED(rc)) + { + + /* + * Here is the right place to communicate the TAP file descriptor and + * the host interface name to the server if/when it becomes really + * necessary. + */ + maTAPDeviceName[slot] = tapDeviceName; + rcVBox = VINF_SUCCESS; + } + } + } #elif defined(RT_OS_FREEBSD) /** @todo Implement tap networking for FreeBSD. */ int rcVBox = VERR_NOT_IMPLEMENTED;