With VirtualNetwork is it possible to install a virtual network card on a Windows system. A four port switch will be simulated on this network card. Over a API is it possible to send and receive packets on the mac level.
VirtualNetwork is used to simulate and test
netzwork protocols on MAC level dirctly in Windows. It is also possible to run TCP stacks such as
LWIP on a VirtualNetwork
interface. Against the loopback interface which only allows accesses on the ip
level, VirtualNetwork send and receive all packets on the MAC level. The
full network traffic can be recorded with tools such as Wireshark.
The sourcecode contains following files :
Datei Funktion VirtualNetworkTools.h Header for the VirtualNetwork API VirtualNetworkTools.c Source for the VirtualNetwork API SimpleNetwork.cpp A small UDP Stack with ping functionality NtpTools.cpp Plug in for the NTP protocol ScannerTools.cpp Plug in for the SCN protocol Main.cpp Demo program for VirtualNetwork NtpRouter.cpp Router for NTP packets from port 124 to the internet Driver/* Sources of the VirtualNetwork driver System/* Sources for thread and sockets access Install/* Installation documentation
sample code shows the access to a VirtualNetwork interface :The next
BYTE
aPacket[1514];
LPBYTE
pMac;
VnetHandle
hVnet;
unsigned
uTurn;
int
iSize;
int
iRet;
hVnet
=
VnetOpen();
if(!hVnet)
// open a port on the virtual switch
{
printf("can't
open
driver
(err=%i)\n",VnetLastError());
return
-1;
}
pMac
=
VnetMac(hVnet);
printf("connected
to
the
port
%i\n",VnetPort(hVnet));
printf("own
mac:
%02X-%02X-%02X-%02X-%02X-%02X\n",pMac[0],pMac[1],pMac[2],pMac[3],pMac[4],pMac[5]);
memcpy(aPacket+0
,"\xFF\xFF\xFF\xFF\xFF\xFF",6);
memcpy(aPacket+6
,pMac,6);
memcpy(aPacket+12,"\x99\x88\x77\x66",4);
iRet = VnetSend(hVnet,aPacket,16); // send a packet
for(uTurn=0;uTurn<1000;uTurn++)
// loop for receiving packets
{
iSize
=
VnetRecv(hVnet,aPacket,sizeof(aPacket));
if(iSize<=0)continue;
printf("receive
%04i
bytes\n",iSize);
}
VnetClose(hVnet);
printf("connection closed\n");
Extract the LWIP demo from the ZIP file in your MyProjects folder.
Compilie and start the project LwipDemo.dsw.
On the IP address 192.168.99.33 at TCP port 7 is an ECHO server installed.
A WDK (Windows Driver Kit) must be installed.
Start ./Driver/makeall.bat and the *.sys files will be build in ./Driver/obj????/<cpu>/...
Anton Zechner |