1 /* Copyright 2004 Renzo Davoli
2 * Reseased under the GPLv2 */
9 #include <sys/select.h>
10 #include <sys/socket.h>
16 #include <vdecommon.h>
17 #include <libvdeplug.h>
19 #define SWITCH_MAGIC 0xfeedface
25 static unsigned char bufin
[BUFSIZE
];
27 static struct pollfd pollv
[]={{0,POLLIN
|POLLHUP
,0},{0,POLLIN
|POLLHUP
,0}};
29 int main(int argc
,char *argv
[])
34 struct vde_open_args open_args
={.port
=0,.group
=NULL
,.mode
=0700};
36 /*printf("argc = %d\n",argc);
38 printf("argv %d -%s-\n",i,argv[i]);*/
39 if (argc
< 4 && argv
[0][0] != '-') {
40 fprintf(stderr
,"vdetap must be activated by libvdetap e.g.\n"
41 " sh%% export LD_PRELOAD=%s/libvdetap.so\n"
42 " csh%% setenv LD_PRELOAD %s/libvdetap.so\n", LIBEXECDIR
, LIBEXECDIR
);
47 for (i
=3;i
<FD_SETSIZE
;i
++)
50 if((fddata
= socket(AF_UNIX
, SOCK_DGRAM
, 0)) < 0){
55 open_args
.port
=atoi(argv
[5]);
56 open_args
.group
=argv
[6];
57 sscanf(argv
[7],"%i",&open_args
.mode
);
58 //fprintf(stderr,"|%d|%s|%o|\n",open_args.port,open_args.group,open_args.mode);
59 asprintf(&descr
,"tuntaplib %s/%s",argv
[4],argv
[3]);
62 conn
=vde_open(argv
[2],descr
,&open_args
);
64 pollv
[1].fd
=vde_datafd(conn
);
67 if (pollv
[0].revents
& POLLHUP
|| pollv
[1].revents
& POLLHUP
)
69 if (pollv
[0].revents
& POLLIN
) {
70 nx
=read(fd
,bufin
,sizeof(bufin
));
71 /*fprintf(stderr,"RX from pgm %d\n",nx);*/
72 vde_send(conn
,bufin
,nx
,0);
74 if (pollv
[1].revents
& POLLIN
) {
75 nx
=vde_recv(conn
,bufin
,BUFSIZE
,0);
76 /*fprintf(stderr,"TX to pgm %d\n",nx);*/