VBoxNetAdp-darwin.cpp revision 36ec4b6f42e209d010ade084a96f46ce763345ea
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * VBoxNetAdp - Virtual Network Adapter Driver (Host), Darwin Specific Code.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Copyright (C) 2008 Sun Microsystems, Inc.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * This file is part of VirtualBox Open Source Edition (OSE), as
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * available from http://www.virtualbox.org. This file is free software;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * you can redistribute it and/or modify it under the terms of the GNU
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * General Public License (GPL) as published by the Free Software
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Foundation, in version 2 as it comes in the "COPYING" file of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Clara, CA 95054 USA or visit http://www.sun.com if you need
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * additional information or have any questions.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl/*******************************************************************************
9512fe850e98fdd448c638ca63fdd92a8a510255ahl* Header Files *
9512fe850e98fdd448c638ca63fdd92a8a510255ahl*******************************************************************************/
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * Deal with conflicts first.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * PVM - BSD mess, that FreeBSD has correct a long time ago.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl * iprt/types.h before sys/param.h - prevents UINT32_C and friends.
#include "../VBoxNetAdpInternal.h"
#if defined(RT_OS_WINDOWS)
# define OSDBGPRINT(a)
static int VBoxNetAdpDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess);
if (pIfNet)
* Taken from VBoxNetAdp-darwin.cpp.
if (!err)
if (!err)
return pPkt;
return NULL;
* Taken from VBoxNetAdp-darwin.cpp.
unsigned cSegs = 0;
cSegs++;
else if ( !cSegs
&& pvFrame
cSegs++;
#ifdef PADD_RUNT_FRAMES_FROM_HOST
cSegs++;
* Taken from VBoxNetAdp-darwin.cpp.
DECLINLINE(void) vboxNetAdpDarwinMBufToSG(PVBOXNETADP pThis, mbuf_t pMBuf, void *pvFrame, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc)
unsigned iSeg = 0;
if (cbSeg)
Assert(pvStart && pvSeg && offSeg < mbuf_maxlen(pMBuf) && offSegEnd <= mbuf_maxlen(pMBuf)); NOREF(offSegEnd);
AssertMsgFailed(("pvFrame=%p pvStart=%p pvSeg=%p offSeg=%p cbSeg=%#zx offSegEnd=%p offFrame=%p maxlen=%#zx\n",
iSeg++;
else if ( !iSeg
&& pvFrame
iSeg++;
#ifdef PADD_RUNT_FRAMES_FROM_HOST
while (iSrc > 0)
iDst--;
iSrc--;
iDst = 0;
iDst++;
u_int32_t i;
for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
u_int32_t i;
for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
static errno_t vboxNetAdpDarwinAddProto(ifnet_t pIface, protocol_family_t Family, const struct ifnet_demux_desc *pDemuxDesc, u_int32_t nDesc)
if (pIfNet)
if (pMBuf)
if (err)
return rc;
if (pIfNet)
return VINF_SUCCESS;
return VINF_SUCCESS;
int rc;
return rc;
if (!err)
if (!err)
err = ifnet_set_flags(pThis->u.s.pIface, IFF_RUNNING | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST, 0xFFFF);
if (!err)
return VINF_SUCCESS;
u_int32_t i;
if (err)
for (i = 0; i < VBOXNETADP_MAX_FAMILIES; i++)
if (err)
if (err)
int rc;
if (ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Invalid))
return rc;
return VERR_OUT_OF_RESOURCES;
if (!ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Active))
return VERR_INTNET_FLT_IF_BUSY;
return rc;
* Device open. Called on open /dev/vboxnetctl
static int VBoxNetAdpDarwinIOCtl(dev_t Dev, u_long iCmd, caddr_t pData, int fFlags, struct proc *pProcess)
OSDBGPRINT(("VBoxNetAdpDarwinIOCtl: param len %#x < req size %#x; iCmd=%#lx\n", cbReq, sizeof(VBOXNETADPREQ), iCmd));
return EINVAL;
return VINF_SUCCESS;
int rc;
if (g_nCtlDev < 0)
if (!g_hCtlDev)
return KMOD_RETURN_SUCCESS;
RTR0Term();
return KMOD_RETURN_FAILURE;
return KMOD_RETURN_FAILURE;
RTR0Term();
return KMOD_RETURN_SUCCESS;