2 * Acess2 Networking Test Suite (NetTest)
3 * - By John Hodge (thePowersGang)
6 * - Acess -> TAP Wrapper
9 #include <IPStack/include/adapters_api.h>
13 static const int MTU = 1520;
16 void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr);
17 tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr);
18 int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer);
21 tIPStack_AdapterType gNativeNIC_AdapterType = {
23 .Type = 0, // TODO: Differentiate differnet wire protos and speeds
24 .Flags = 0, // TODO: IP checksum offloading, MAC checksum offloading etc
25 .SendPacket = NativeNic_SendPacket,
26 .WaitForPacket = NativeNic_WaitForPacket
30 int NativeNic_AddDev(char *DevDesc)
33 char *colonpos = strchr(DevDesc, ':');
36 if( UnHex(macaddr, 6, DevDesc) != 6 )
38 void *ptr = NetTest_OpenTap(colonpos+1);
41 IPStack_Adapter_Add(&gNativeNIC_AdapterType, ptr, macaddr);
46 void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr)
48 free( (void*)DataPtr );
51 tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr)
53 char *buf = malloc( MTU );
56 len = NetTest_ReadPacket(Ptr, MTU, buf);
58 tIPStackBuffer *ret = IPStack_Buffer_CreateBuffer(1);
59 IPStack_Buffer_AppendSubBuffer(ret, len, 0, buf, NativeNic_int_FreePacket, Ptr);
63 int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer)
65 size_t len = IPStack_Buffer_GetLength(Buffer);
71 // Serialise into stack
73 IPStack_Buffer_GetData(Buffer, buf, len);
75 NetTest_WritePacket(Ptr, len, buf);