2 * Acess2 Networking Test Suite (NetTest)
3 * - By John Hodge (thePowersGang)
11 //#include <linux/if.h>
12 #include <linux/if_tun.h>
17 #include <sys/socket.h>
21 void *NetTest_OpenTap(const char *Name)
26 memset(&ifr, 0, sizeof(ifr));
27 ifr.ifr_flags = IFF_TAP|IFF_NO_PI;
31 if( strlen(Name) > IFNAMSIZ )
33 strncpy(ifr.ifr_name, Name, IFNAMSIZ);
36 int fd = open("/dev/net/tun", O_RDWR);
39 perror("NetTest_OpenTap - open");
43 if( (rv = ioctl(fd, TUNSETIFF, &ifr)) )
45 perror("NetTest_OpenTap - ioctl(TUNSETIFF)");
46 fprintf(stderr, "Opening TUN/TAP device '%s'\n", Name);
51 return (void*)(intptr_t)fd;
54 void *NetTest_OpenUnix(const char *Path)
56 int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
57 struct sockaddr_un sa = {AF_UNIX, ""};
58 struct sockaddr_un sa_local = {AF_UNIX, ""};
59 strcpy(sa.sun_path, Path);
60 if( connect(fd, (struct sockaddr*)&sa, sizeof(sa)) ) {
61 perror("NetTest_OpenUnix - connect");
65 if( bind(fd, (struct sockaddr*)&sa_local, sizeof(sa)) ) {
66 perror("NetTest_OpenUnix - bind");
72 char somenulls[] = { 0,0,0,0,0,0, 0,0,0,0,0, 0,0};
73 write(fd, somenulls, sizeof(somenulls));
76 return (void*)(intptr_t)fd;
79 size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data)
81 int ret = write( (intptr_t)Handle, Data, Size);
83 perror("NetTest_WritePacket - write");
89 size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data)
91 return read( (intptr_t)Handle, Data, MaxSize);