Initial release MARS_NWE-PCAP 0.4 - Native Administration, Print and Login Edition

This commit is contained in:
2026-11-26 20:22:04 +00:00
commit 7ba7f59b08
51 changed files with 1966 additions and 0 deletions

12
tests/test_raw.c Normal file
View File

@@ -0,0 +1,12 @@
#define _GNU_SOURCE
#include <assert.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int rawprint(const char *,const char *);
int main(void){assert(rawprint("invalid-host","/dev/null")<0);int fd=socket(AF_INET,SOCK_STREAM,0);assert(fd>=0);int one=1;setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&one,sizeof one);struct sockaddr_in a={.sin_family=AF_INET,.sin_port=htons(9100),.sin_addr.s_addr=htonl(INADDR_LOOPBACK)};if(bind(fd,(struct sockaddr*)&a,sizeof a)){perror("test requires unused local port 9100");return 77;}assert(!listen(fd,1));char p[]="/tmp/mars-raw-XXXXXX";int f=mkstemp(p);assert(f>=0);unsigned char data[]={0,1,27,255,65,10};assert(write(f,data,sizeof data)==sizeof data);close(f);pid_t child=fork();assert(child>=0);if(!child){close(fd);_exit(rawprint("127.0.0.1",p)?1:0);}int s=accept(fd,NULL,NULL);assert(s>=0);unsigned char buf[16];size_t off=0;ssize_t n;while((n=read(s,buf+off,sizeof buf-off))>0)off+=n;assert(off==sizeof data&&!memcmp(data,buf,off));close(s);close(fd);int status;assert(waitpid(child,&status,0)==child&&WIFEXITED(status)&&!WEXITSTATUS(status));unlink(p);puts("PASS: RAW TCP 9100 exact binary bytes over local TCP");return 0;}