Wirefilter: new markov mode (see man page)
[vde.git] / ipn / test / test4x.c
blobfe4c13d667ada91b8161d795fb0fda5365269d11
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>
10 #define AF_IPN AF_NETBEUI
11 #define PF_IPN AF_IPN
12 #define IPN_ANY 0
13 #define IPN_BROADCAST 1
14 #define IPN_HUB 1
15 #define IPN_VDESWITCH 2
16 #define IPN_VDESWITCH_L3 3
18 #define IPN_SO_PREBIND 0x80
19 #define IPN_SO_PORT 0
20 #define IPN_SO_DESCR 1
21 #define IPN_SO_MTU (IPN_SO_PREBIND | 0)
22 #define IPN_SO_NUMNODES (IPN_SO_PREBIND | 1)
23 #define IPN_SO_MSGPOOLSIZE (IPN_SO_PREBIND | 2)
24 #define IPN_SO_FLAGS (IPN_SO_PREBIND | 3)
25 #define IPN_SO_MODE (IPN_SO_PREBIND | 4)
27 /* Ioctl defines */
28 #define IPN_SETPERSIST_NETDEV _IOW('I', 200, int)
29 #define IPN_CLRPERSIST_NETDEV _IOW('I', 201, int)
30 #define IPN_CONN_NETDEV _IOW('I', 202, int)
31 #define IPN_JOIN_NETDEV _IOW('I', 203, int)
32 #define IPN_SETPERSIST _IOW('I', 204, int)
34 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
35 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
37 #define IPN_PORTNO_ANY -1
39 #define IPN_DESCRLEN 32
41 #define IPN_FLAG_LOSSLESS 1
43 /*#define IPNTYPE IPN_BROADCAST*/
44 #define IPNTYPE IPN_VDESWITCH
46 char buf[256];
47 struct sockaddr_un sun={.sun_family=AF_IPN,.sun_path="/tmp/sockipn"};
48 main()
50 int s=socket(AF_IPN,SOCK_RAW,IPNTYPE);
51 int s2=socket(AF_IPN,SOCK_RAW,IPNTYPE);
52 int err;
53 int len;
54 int flags=IPN_FLAG_LOSSLESS;
55 int size=128;
56 int mode=0770;
57 struct ifreq ifr;
58 if (s< 0)
59 perror("socket");
60 printf("s=%d\n",s);
62 err=setsockopt(s,0,IPN_SO_FLAGS,&flags,sizeof(flags));
63 if (err<0)
64 perror("setsockopt");
65 err=setsockopt(s,0,IPN_SO_MSGPOOLSIZE,&size,sizeof(size));
66 if (err<0)
67 perror("setsockopt");
68 err=setsockopt(s,0,IPN_SO_MODE,&mode,sizeof(mode));
69 if (err<0)
70 perror("setsockopt");
72 err=bind(s,(struct sockaddr *)&sun,sizeof(sun));
73 if (err<0)
74 perror("bind");
75 err=bind(s2,(struct sockaddr *)&sun,sizeof(sun));
76 if (err<0)
77 perror("bind2");
79 err=connect(s,NULL,0);
81 memset(&ifr, 0, sizeof(ifr));
82 strncpy(ifr.ifr_name, "eth1", IFNAMSIZ);
83 ifr.ifr_flags=IPN_NODEFLAG_GRAB;
84 err=ioctl(s, IPN_CONN_NETDEV, (void *) &ifr);
85 if (err<0)
86 perror("connect");
87 memset(&ifr, 0, sizeof(ifr));
88 strncpy(ifr.ifr_name, "ipn1", IFNAMSIZ);
89 ifr.ifr_flags=IPN_NODEFLAG_TAP;
90 err=ioctl(s2, IPN_CONN_NETDEV, (void *) &ifr);
91 if (err<0)
92 perror("connect2");
94 while ((len=read(0,buf,256)) > 0) {
95 //err=write(s,buf,len);
96 if (err<0)
97 perror("write sock");
99 if (len < 0)
100 perror("read stdin");
101 close(s);