tstIntNet-1.cpp revision 22ee5e5e59ef3b94fcf7640c56836bcb68b042aa
/* $Id$ */
/** @file
* VBox - Testcase for internal networking, simple NetFlt trunk creation.
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static int g_cErrors = 0;
/**
* Does packet sniffing for a given period of time.
*
* @param hIf The interface handle.
* @param pSession The session.
* @param pBuf The shared interface buffer.
* @param cMillies The time period, ms.
* @param pFileRaw The file to write the raw data to (optional).
* @param pFileText The file to write a textual packet summary to (optional).
*/
static void doPacketSniffing(INTNETIFHANDLE hIf, PSUPDRVSESSION pSession, PINTNETBUF pBuf, uint32_t cMillies,
{
/*
* Write the raw file header.
*/
/*
* The loop.
*/
for (;;)
{
/*
* Wait for a packet to become available.
*/
if (cElapsedMillies >= cMillies)
break;
if (rc == VERR_TIMEOUT)
break;
if (RT_FAILURE(rc))
{
g_cErrors++;
break;
}
/*
* Process the receive buffer.
*/
while (INTNETRingGetReadable(pRingBuf) > 0)
{
{
if (pFileRaw)
{
}
if (pFileText)
}
else
{
g_cErrors++;
}
/* Advance to the next frame. */
}
}
"%3RU64.%09u: stopped. cRecvs=%RU64 cbRecv=%RU64 cLost=%RU64 cOYs=%RU64 cNYs=%RU64\n",
pBuf->cStatRecvs.c,
pBuf->cbStatRecv.c,
pBuf->cStatYieldsOk.c,
);
}
{
/*
* Init the runtime and parse the arguments.
*/
RTR3Init(false, 0);
static RTOPTIONDEF const s_aOptions[] =
{
};
#ifdef RT_OS_DARWIN
const char *pszIf = "en0";
#elif defined(RT_OS_LINUX)
const char *pszIf = "eth0";
#else
const char *pszIf = "em0";
#endif
bool fPromiscuous = false;
const char *pszNetwork = "tstIntNet-1";
bool fSniffer = false;
bool fXmitTest = false;
int rc;
int ch;
int iArg = 1;
switch (ch)
{
case 'd':
{
RTPrintf("tstIntNet-1: warning duration overflowed\n");
}
break;
case 'f':
if (RT_FAILURE(rc))
{
return 1;
}
break;
case 'i':
{
RTPrintf("tstIntNet-1: Interface name is too long (max %d chars): %s\n", INTNET_MAX_TRUNK_NAME - 1, pszIf);
return 1;
}
break;
case 'n':
{
RTPrintf("tstIntNet-1: Network name is too long (max %d chars): %s\n", INTNET_MAX_NETWORK_NAME - 1, pszNetwork);
return 1;
}
break;
case 'p':
fPromiscuous = true;
break;
case 'r':
break;
case 's':
break;
case 'S':
fSniffer = true;
break;
case 't':
else
{
if (RT_FAILURE(rc))
{
return 1;
}
}
break;
case 'x':
fXmitTest = true;
break;
case '?':
case 'h':
RTPrintf("syntax: tstIntNet-1 [-pSt] [-d <secs>] [-f <file>] [-r <size>] [-s <size>]\n");
return 1;
default:
if (RT_SUCCESS(ch))
else
return 1;
}
{
return 1;
}
RTPrintf("tstIntNet-1: TESTING...\n");
/*
* Open the session, load ring-0 and issue the request.
*/
if (RT_FAILURE(rc))
{
return 1;
}
char szPath[RTPATH_MAX];
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
/*
* Create the request, picking the network and trunk names from argv[2]
* and argv[1] if present.
*/
/*
* Issue the request.
*/
if (RT_SUCCESS(rc))
{
/*
* Get the ring-3 address of the shared interface buffer.
*/
if (RT_SUCCESS(rc))
{
RTPrintf("tstIntNet-1: pBuf=%p cbBuf=%d cbSend=%d cbRecv=%d\n",
if (fPromiscuous)
{
PromiscReq.fPromiscuous = true;
if (RT_SUCCESS(rc))
RTPrintf("tstIntNet-1: interface in promiscuous mode\n");
}
if (RT_SUCCESS(rc))
{
/*
* Either enter sniffing mode or do a timeout thing.
*/
if (fSniffer)
else
}
else
{
RTPrintf("tstIntNet-1: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE,) failed, rc=%Rrc\n", rc);
g_cErrors++;
}
}
else
{
RTPrintf("tstIntNet-1: SUPCallVMMR0Ex(,VMMR0_DO_INTNET_IF_GET_RING3_BUFFER,) failed, rc=%Rrc\n", rc);
g_cErrors++;
}
}
else
{
g_cErrors++;
}
SUPTerm(false /* not forced */);
/* close open files */
if (pFileRaw)
/*
* Summary.
*/
if (!g_cErrors)
RTPrintf("tstIntNet-1: SUCCESS\n");
else
return !!g_cErrors;
}