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 = {
25 .SendPacket = NativeNic_SendPacket,
26 .WaitForPacket = NativeNic_WaitForPacket
30 int NativeNic_AddDev(char *DevDesc)
33 // Parse descriptor into mac address and path
34 // 123456789ABC:tun:ifname
35 // 123456789ABC:unix:/path
36 // 123456789ABC:file:/path
37 // 123456789ABC:tcp:host_desc
38 char *colonpos = strchr(DevDesc, ':');
41 if( UnHex(macaddr, 6, DevDesc) != 6 )
44 char *class = colonpos + 1;
45 colonpos = strchr(class, ':');
47 if( strncmp(class, "tun:", 4) == 0 ) {
48 ptr = NetTest_OpenTap(colonpos+1);
50 else if( strncmp(class, "unix:", 5) == 0 ) {
51 ptr = NetTest_OpenUnix(colonpos+1);
54 Log_Warning("NIC", "Unknown opener '%.*s'", colonpos-class, class);
59 IPStack_Adapter_Add(&gNativeNIC_AdapterType, ptr, macaddr);
64 void NativeNic_int_FreePacket(void *Ptr, size_t pkt_length, size_t Unused, const void *DataPtr)
66 free( (void*)DataPtr );
69 tIPStackBuffer *NativeNic_WaitForPacket(void *Ptr)
71 char *buf = malloc( MTU );
74 len = NetTest_ReadPacket(Ptr, MTU, buf);
76 tIPStackBuffer *ret = IPStack_Buffer_CreateBuffer(1);
77 IPStack_Buffer_AppendSubBuffer(ret, len, 0, buf, NativeNic_int_FreePacket, Ptr);
79 Debug_HexDump("NativeNic: RX", buf, len);
84 int NativeNic_SendPacket(void *Ptr, tIPStackBuffer *Buffer)
86 size_t len = IPStack_Buffer_GetLength(Buffer);
92 // Serialise into stack
94 IPStack_Buffer_GetData(Buffer, buf, len);
96 Debug_HexDump("NativeNic: TX", buf, len);
98 NetTest_WritePacket(Ptr, len, buf);