bugfix: reference to local var was erroneously returned
[vde.git] / ipn / test / test2.c
blob741dba6b43ebb3bdabc68175ca145ee2fa89ab69
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 char buf[256];
44 struct sockaddr_un sun={.sun_family=AF_IPN,.sun_path="/tmp/sockipn"};
45 main()
47 //int s=socket(AF_IPN,SOCK_RAW,IPN_BROADCAST);
48 int s=socket(AF_IPN,SOCK_RAW,IPN_VDESWITCH);
49 int err;
50 int len;
51 int flags=IPN_FLAG_LOSSLESS;
52 int size=128;
53 int mode=0770;
54 struct ifreq ifr;
55 if (s< 0)
56 perror("socket");
57 printf("s=%d\n",s);
59 err=setsockopt(s,0,IPN_SO_FLAGS,&flags,sizeof(flags));
60 if (err<0)
61 perror("setsockopt");
62 err=setsockopt(s,0,IPN_SO_MSGPOOLSIZE,&size,sizeof(size));
63 if (err<0)
64 perror("setsockopt");
65 err=setsockopt(s,0,IPN_SO_MODE,&mode,sizeof(mode));
66 if (err<0)
67 perror("setsockopt");
69 err=bind(s,(struct sockaddr *)&sun,sizeof(sun));
70 if (err<0)
71 perror("bind");
73 err=connect(s,NULL,0);
75 memset(&ifr, 0, sizeof(ifr));
76 strncpy(ifr.ifr_name, "ipn0", IFNAMSIZ);
77 ifr.ifr_flags=IPN_NODEFLAG_TAP;
78 err=ioctl(s, IPN_CONN_NETDEV, (void *) &ifr);
79 if (err<0)
80 perror("connect");
81 while ((len=read(0,buf,256)) > 0) {
82 /*err=write(s,buf,len);
83 if (err<0)
84 perror("write sock");*/
86 if (len < 0)
87 perror("read stdin");
88 close(s);