#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
+#include <sys/socket.h>
+#include <sys/un.h>
// === CODE ===
void *NetTest_OpenTap(const char *Name)
return (void*)(intptr_t)fd;
}
+void *NetTest_OpenUnix(const char *Path)
+{
+ int fd = socket(AF_UNIX, SOCK_DGRAM, 0);
+ struct sockaddr_un sa = {AF_UNIX, ""};
+ struct sockaddr_un sa_local = {AF_UNIX, ""};
+ strcpy(sa.sun_path, Path);
+ if( connect(fd, (struct sockaddr*)&sa, sizeof(sa)) ) {
+ perror("NetTest_OpenUnix - connect");
+ close(fd);
+ return NULL;
+ }
+ if( bind(fd, (struct sockaddr*)&sa_local, sizeof(sa)) ) {
+ perror("NetTest_OpenUnix - bind");
+ close(fd);
+ return NULL;
+ }
+
+ {
+ char somenulls[] = { 0,0,0,0,0,0, 0,0,0,0,0, 0,0};
+ write(fd, somenulls, sizeof(somenulls));
+ }
+
+ return (void*)(intptr_t)fd;
+}
+
size_t NetTest_WritePacket(void *Handle, size_t Size, const void *Data)
{
- return write( (intptr_t)Handle, Data, Size);
+ int ret = write( (intptr_t)Handle, Data, Size);
+ if( ret < 0 ) {
+ perror("NetTest_WritePacket - write");
+ return 0;
+ }
+ return ret;
}
size_t NetTest_ReadPacket(void *Handle, size_t MaxSize, void *Data)