tagging vde-2 version 2.3.2
[vde.git] / 2.3.2 / src / unixterm.c
blob91c43ec0c58cd3f6c31c87df45eb18308485d5df
1 /* Copyright 2005 Renzo Davoli VDE-2
2 * Licensed under the GPLv2
4 * Minimal terminal emulator on a UNIX stream socket
5 */
7 #include <stdio.h>
8 #include <fcntl.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <sys/socket.h>
12 #include <sys/un.h>
14 #include <config.h>
15 #include <vde.h>
16 #include <vdecommon.h>
18 #define BUFSIZE 1024
19 char buf[BUFSIZE];
21 int main(int argc,char *argv[])
23 struct sockaddr_un sun;
24 int fd;
25 int rv;
26 static struct pollfd pfd[]={
27 {STDIN_FILENO,POLLIN | POLLHUP,0},
28 {STDIN_FILENO,POLLIN | POLLHUP,0}};
29 static int fileout[]={STDOUT_FILENO,STDOUT_FILENO};
30 sun.sun_family=PF_UNIX;
31 snprintf(sun.sun_path,sizeof(sun.sun_path),"%s",argv[1]);
32 if((fd=socket(PF_UNIX,SOCK_STREAM,0))<0) {
33 perror("Socket opening error");
34 exit(-1);
36 if ((rv=connect(fd,(struct sockaddr *)(&sun),sizeof(sun))) < 0) {
37 perror("Socket connecting error");
38 exit(-1);
40 pfd[1].fd=fileout[0]=fd;
41 while(1) {
42 int m,i,n=poll(pfd,2,-1);
43 for(i=0;n>0;i++) {
44 if(pfd[i].revents & POLLHUP)
45 exit(0);
46 if(pfd[i].revents & POLLIN) {
47 n--;
48 if((m=read(pfd[i].fd,buf,BUFSIZE)) == 0)
49 exit(0);
50 write(fileout[i],buf,m);