/* * console - get console output * * This connects to the consoled on the local machine and copies * everything received from consoled to standard output. * * It dies if it gets a read error or EOF on its connection to * consoled, a write error on its stdout, or if it gets any of * the usual "please die" signals. */ char service_name[256] = "console"; #include #include #include #include /* grrr broken include files grrr */ #include #include char *malloc(); /*extern*/ char **argvec; int sock; /* **** BEGIN DISTRIBUTION KLUDGES **** */ /* since I can't use the %m format in code sent out to the net */ char *errno_msg(e) int e; { static char badbuf[256]; extern int sys_nerr; extern char *sys_errlist[]; if ((e < 0) || (e >= sys_nerr)) { sprintf(&badbuf[0],"Error %d",e); return(&badbuf[0]); } return(sys_errlist[e]); } /* **** END DISTRIBUTION KLUDGES **** */ init() { struct servent *sp; struct sockaddr_in sin; bzero((char *)&sin,sizeof(sin)); /* shouldn't be necessary, but Sun kernel insists on it */ sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */ sp = getservbyname(&service_name[0],"tcp"); if (sp == 0) { fprintf(stderr,"%s: can't find %s/tcp service\n",argvec[0],&service_name[0]); exit(1); } sin.sin_port = sp->s_port; sock = socket(AF_INET,SOCK_STREAM,0); if (connect(sock,(struct sockaddr *)&sin,sizeof(sin)) < 0) { fprintf(stderr,"%s: can't connect socket: %s\n",argvec[0],errno_msg(errno)); } } run() { int nr; char buf[256]; while (1) { nr = read(sock,&buf[0],sizeof(buf)); if (nr <= 0) exit(0); if (write(1,&buf[0],nr) != nr) exit(0); } } main(ac,av) int ac; char **av; { argvec=av; init(); run(); }