chrdev persistence + ioctl renumbering (following the IOR/IOW scheme)
[vde.git] / ipn / test / test4x.c
blobeb75c417488736af0120ce8cf700e9815f32d5d0
1 #include <stdio.h>
2 #include <errno.h>
3 #include <sys/types.h>
4 #include <sys/socket.h>
5 #include <sys/un.h>
6 #include <sys/ioctl.h>
7 #include <linux/if.h>
8 #include <linux/if_tun.h>
9 #include <af_ipn.h>
11 /*#define IPNTYPE IPN_BROADCAST*/
12 #define IPNTYPE IPN_VDESWITCH
14 char buf[256];
15 struct sockaddr_un sun={.sun_family=AF_IPN,.sun_path="/tmp/sockipn"};
16 main()
18 int s=socket(AF_IPN,SOCK_RAW,IPNTYPE);
19 int s2=socket(AF_IPN,SOCK_RAW,IPNTYPE);
20 int err;
21 int len;
22 int flags=IPN_FLAG_LOSSLESS;
23 int size=128;
24 int mode=0770;
25 struct ifreq ifr;
26 if (s< 0)
27 perror("socket");
28 printf("s=%d\n",s);
30 err=setsockopt(s,0,IPN_SO_FLAGS,&flags,sizeof(flags));
31 if (err<0)
32 perror("setsockopt");
33 err=setsockopt(s,0,IPN_SO_MSGPOOLSIZE,&size,sizeof(size));
34 if (err<0)
35 perror("setsockopt");
36 err=setsockopt(s,0,IPN_SO_MODE,&mode,sizeof(mode));
37 if (err<0)
38 perror("setsockopt");
40 err=bind(s,(struct sockaddr *)&sun,sizeof(sun));
41 if (err<0)
42 perror("bind");
43 err=bind(s2,(struct sockaddr *)&sun,sizeof(sun));
44 if (err<0)
45 perror("bind2");
47 err=connect(s,NULL,0);
49 memset(&ifr, 0, sizeof(ifr));
50 strncpy(ifr.ifr_name, "eth1", IFNAMSIZ);
51 ifr.ifr_flags=IPN_NODEFLAG_GRAB;
52 err=ioctl(s, IPN_CONN_NETDEV, (void *) &ifr);
53 if (err<0)
54 perror("connect");
55 memset(&ifr, 0, sizeof(ifr));
56 strncpy(ifr.ifr_name, "ipn1", IFNAMSIZ);
57 ifr.ifr_flags=IPN_NODEFLAG_TAP;
58 err=ioctl(s2, IPN_CONN_NETDEV, (void *) &ifr);
59 if (err<0)
60 perror("connect2");
62 while ((len=read(0,buf,256)) > 0) {
63 //err=write(s,buf,len);
64 if (err<0)
65 perror("write sock");
67 if (len < 0)
68 perror("read stdin");
69 close(s);