Initial release MARS_NWE-PCAP 0.4 - Native Administration, Print and Login Edition
This commit is contained in:
19
tests/test_ipc.c
Normal file
19
tests/test_ipc.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include "wire.h"
|
||||
#include "shim.h"
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
#include <sys/wait.h>
|
||||
#include <poll.h>
|
||||
static int op(void){int fd=mars_socket(AF_IPX,SOCK_DGRAM,AF_IPX);assert(fd>=0);return fd;}
|
||||
static int bindp(int fd,int port,struct sockaddr_ipx *a){memset(a,0,sizeof *a);a->sipx_family=AF_IPX;a->sipx_port=htons(port);int r=mars_bind(fd,(void*)a,sizeof *a);if(!r){socklen_t n=sizeof *a;assert(!mars_getsockname(fd,(void*)a,&n));}return r;}
|
||||
int main(int argc,char **argv){if(argc==2){int fd=atoi(argv[1]);struct pollfd p={fd,POLLIN,0};assert(poll(&p,1,3000)==1);struct sockaddr_ipx a;socklen_t l=sizeof a;char buf[32];assert(mars_recvfrom(fd,buf,sizeof buf,0,(void*)&a,&l)==4);assert(!memcmp(buf,"ping",4)&&a.sipx_type==17);assert(mars_sendto(fd,"pong",4,0,(void*)&a,sizeof a)==4);return 0;}
|
||||
int ctl=op();struct sockaddr_ipx a,b;assert(bindp(ctl,0x451,&a)<0&&errno==EADDRNOTAVAIL);struct ifreq r={0};struct sockaddr_ipx v={.sipx_family=AF_IPX,.sipx_network=htonl(0x12345678),.sipx_special=IPX_INTERNAL,.sipx_action=IPX_CRTITF,.sipx_node={0,0,0,0,0,1}};memcpy(&r.ifr_addr,&v,sizeof v);assert(!mars_ioctl(ctl,SIOCSIFADDR,&r));for(int k=1;k<=4;k++){memset(&r,0,sizeof r);strcpy(r.ifr_name,"test0");v.sipx_network=htonl(0x100+k);v.sipx_type=k;v.sipx_special=IPX_SPECIAL_NONE;memcpy(&r.ifr_addr,&v,sizeof v);assert(!mars_ioctl(ctl,SIOCSIFADDR,&r));}struct rtentry rt={0};v.sipx_network=htonl(0x200);memcpy(&rt.rt_dst,&v,sizeof v);v.sipx_network=htonl(0x101);v.sipx_node[0]=2;memcpy(&rt.rt_gateway,&v,sizeof v);assert(!mars_ioctl(ctl,SIOCADDRT,&rt));assert(!mars_ioctl(ctl,SIOCDELRT,&rt));close(ctl);
|
||||
int x=op(),y=op(),z=op();assert(!bindp(x,0x451,&a));assert(a.sipx_network==htonl(0x12345678));assert(!bindp(y,0,&b));struct sockaddr_ipx tmp;assert(bindp(z,0x451,&tmp)<0&&errno==EADDRINUSE);close(z);pid_t pid=fork();assert(pid>=0);if(!pid){close(y);char arg[20];snprintf(arg,sizeof arg,"%d",x);execl(argv[0],argv[0],arg,NULL);_exit(1);}close(x);a.sipx_type=17;assert(mars_sendto(y,"ping",4,0,(void*)&a,sizeof a)==4);struct pollfd pp={y,POLLIN,0};assert(poll(&pp,1,4000)==1);char buf[16];socklen_t l=sizeof a;assert(mars_recvfrom(y,buf,sizeof buf,0,(void*)&a,&l)==4);assert(!memcmp(buf,"pong",4)&&ntohs(a.sipx_port)==0x451);int status;waitpid(pid,&status,0);assert(WIFEXITED(status)&&!WEXITSTATUS(status));close(y);int again=op();assert(!bindp(again,0x451,&tmp));close(again);puts("PASS: internal interface, all external interface registrations, route add/delete, bind conflict, ephemeral port, fork/exec and rebind");return 0;}
|
||||
Reference in New Issue
Block a user