|
|
1.1 root 1: /* spyon.c */
2:
3: /* Synchronet for *nix node spy */
4:
5: /* $Id: spyon.c,v 1.3 2004/08/10 03:49:03 deuce Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include <unistd.h>
39: #include "sockwrap.h" /* Must go before <sys/un.h> */
40: #include <sys/un.h>
41: #include <stdio.h>
42: #include <string.h>
43: #include "sockwrap.h"
44: #include "spyon.h"
45: #include "cterm.h"
46: #include "ciolib.h"
47:
48: int spyon(char *sockname) {
49: SOCKET spy_sock=INVALID_SOCKET;
50: struct sockaddr_un spy_name;
51: socklen_t spy_len;
52: unsigned char key;
53: unsigned char buf;
54: int i;
55: fd_set rd;
56: BOOL b;
57: int retval=0;
58: char ANSIbuf[32];
59: int parsing=0;
60: int telnet_strip=0;
61: struct text_info ti;
62: char *scrn;
63:
64: /* ToDo Test for it actually being a socket! */
65: /* Well, it will fail to connect won't it? */
66:
67: if((spy_sock=socket(PF_UNIX,SOCK_STREAM,0))==INVALID_SOCKET) {
68: printf("ERROR %d creating local spy socket", errno);
69: return(SPY_NOSOCKET);
70: }
71:
72: spy_name.sun_family=AF_UNIX;
73: SAFECOPY(spy_name.sun_path,sockname);
74: spy_len=SUN_LEN(&spy_name);
75: if(connect(spy_sock,(struct sockaddr *)&spy_name,spy_len)) {
76: return(SPY_NOCONNECT);
77: }
78: i=1;
79:
80: gettextinfo(&ti);
81: scrn=(char *)malloc(ti.screenwidth*ti.screenheight*2);
82: gettext(1,1,ti.screenwidth,ti.screenheight,scrn);
83: textcolor(YELLOW);
84: textbackground(BLUE);
85: clrscr();
86: gotoxy(1,ti.screenheight);
87: cputs("Local spy mode... press CTRL-C to return to monitor");
88: clreol();
89: cterm_init(ti.screenheight-1,ti.screenwidth,1,1,0,NULL);
90: while(spy_sock!=INVALID_SOCKET) {
91: struct timeval tv;
92: tv.tv_sec=0;
93: tv.tv_usec=100;
94: FD_ZERO(&rd);
95: FD_SET(spy_sock,&rd);
96: if((select(spy_sock+1,&rd,NULL,NULL,&tv))<0) {
97: close(spy_sock);
98: spy_sock=INVALID_SOCKET;
99: retval=SPY_SELECTFAILED;
100: break;
101: }
102: if(!socket_check(spy_sock,NULL,&b,0)) {
103: close(spy_sock);
104: spy_sock=INVALID_SOCKET;
105: retval=SPY_SOCKETLOST;
106: break;
107: }
108: if(spy_sock != INVALID_SOCKET && FD_ISSET(spy_sock,&rd)) {
109: if((i=read(spy_sock,&buf,1))==1) {
110: if(telnet_strip) {
111: telnet_strip++;
112: if(buf==255 && telnet_strip==2) {
113: telnet_strip=0;
114: cterm_write(&buf,1,NULL,0);
115: }
116: if(telnet_strip==3)
117: telnet_strip=0;
118: }
119: else
120: if(buf==255)
121: telnet_strip=1;
122: else
123: cterm_write(&buf,1,NULL,0);
124: }
125: else if(i<0) {
126: close(spy_sock);
127: spy_sock=INVALID_SOCKET;
128: retval=SPY_SOCKETLOST;
129: break;
130: }
131: }
132: if(kbhit()) {
133: key=getch();
134: /* Check for control keys */
135: switch(key) {
136: case 0: /* Extended keys */
137: case 0xff:
138: getch();
139: break;
140: case 3: /* CTRL-C */
141: close(spy_sock);
142: spy_sock=INVALID_SOCKET;
143: retval=SPY_CLOSED;
144: break;
145: default:
146: write(spy_sock,&key,1);
147: }
148: }
149: }
150: puttext(1,1,ti.screenwidth,ti.screenheight,scrn);
151: window(ti.winleft,ti.wintop,ti.winright,ti.winbottom);
152: textattr(ti.attribute);
153: gotoxy(ti.curx,ti.cury);
154: return(retval);
155: }
156:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.