2 * Acess2 Networking Test Suite (NetTest)
3 * - By John Hodge (thePowersGang)
11 //#include <linux/if.h>
12 #include <linux/if_tun.h>
19 void *NetTest_OpenTap(const char *Name)
24 memset(&ifr, 0, sizeof(ifr));
25 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
29 if( strlen(Name) > IFNAMSIZ )
31 strncpy(ifr.ifr_name, Name, IFNAMSIZ);
34 int fd = open("/dev/net/tun", O_RDWR);
37 perror("NetTest_OpenTap - open");
41 if( (rv = ioctl(fd, TUNSETIFF, &ifr)) )
43 perror("NetTest_OpenTap - ioctl(TUNSETIFF)");
44 fprintf(stderr, "Opening TUN/TAP device '%s'\n", Name);
49 return (void*)(intptr_t)fd;
52 size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data)
54 return write( (intptr_t)Handle, Data, Size);
57 size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data)
59 return read( (intptr_t)Handle, Data, MaxSize);