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
[])
32 struct sockaddr_un datain
;
33 /*struct sockaddr_un dataout;*/
37 struct vde_open_args open_args
={.port
=0,.group
=NULL
,.mode
=0700};
39 /*printf("argc = %d\n",argc);
41 printf("argv %d -%s-\n",i,argv[i]);*/
42 if (argc
< 4 && argv
[0][0] != '-') {
43 fprintf(stderr
,"vdetap must be activated by libvdetap e.g.\n"
44 " sh%% export LD_PRELOAD=%s/libvdetap.so\n"
45 " csh%% setenv LD_PRELOAD %s/libvdetap.so\n", LIBEXECDIR
, LIBEXECDIR
);
50 for (i
=3;i
<FD_SETSIZE
;i
++)
53 if((fddata
= socket(AF_UNIX
, SOCK_DGRAM
, 0)) < 0){
58 open_args
.port
=atoi(argv
[5]);
59 open_args
.group
=argv
[6];
60 sscanf(argv
[7],"%i",&open_args
.mode
);
61 //fprintf(stderr,"|%d|%s|%o|\n",open_args.port,open_args.group,open_args.mode);
62 asprintf(&descr
,"tuntaplib %s/%s",argv
[4],argv
[3]);
65 conn
=vde_open(argv
[2],descr
,&open_args
);
67 pollv
[1].fd
=vde_datafd(conn
);
69 result
=poll(pollv
,2,-1);
70 if (pollv
[0].revents
& POLLHUP
|| pollv
[1].revents
& POLLHUP
)
72 if (pollv
[0].revents
& POLLIN
) {
73 nx
=read(fd
,bufin
,sizeof(bufin
));
74 /*fprintf(stderr,"RX from pgm %d\n",nx);*/
75 //send(connected_fd,bufin,nx,0);
76 vde_send(conn
,bufin
,nx
,0);
78 if (pollv
[1].revents
& POLLIN
) {
79 datainsize
=sizeof(datain
);
80 nx
=vde_recv(conn
,bufin
,BUFSIZE
,0);
81 /*fprintf(stderr,"TX to pgm %d\n",nx);*/