aboutsummaryrefslogtreecommitdiffstats
path: root/src/tcp.h
blob: 550b42ada9a2d49e69254787ab04520a633f908c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* public things from tcp.c */

#ifndef _TCP_H_
#define _TCP_H_

extern int tcp_fd;		/* current socket file descriptor */
extern int tcp_main_fd;		/* main session socket */
extern int tcp_max_fd;		/* highest used fd */

extern int tcp_count;		/* number of open connections */
extern int tcp_attachcount;	/* number of spawned or attached commands */

extern int conn_max_index;	/* 1 + highest used conn_list[] index */


/* multiple connections control */

/* state of telnet connection */
#define NORMAL		0
#define ALTNORMAL	1
#define GOT_N		2
#define GOT_R		3
#define GOTIAC		4
#define GOTWILL		5
#define GOTWONT		6
#define GOTDO		7
#define GOTDONT		8
#define GOTSB		9
#define GOTSBIAC       10

/* connection flags: */
/* ACTIVE:	display remote output	*/
/* SPAWN:	spawned cmd, not a mud	*/
/* IDEDITOR:	sent #request editor	*/
/* IDPROMPT:	sent #request prompt	*/
#define ACTIVE	 1
#define SPAWN	 2
#define IDEDITOR 4
#define IDPROMPT 8

typedef struct {
    char *id;			/* session id */
    char *host;			/* address of remote host */
    int port;			/* port number of remote host */
    int fd;			/* fd number */
    char *fragment;		/* for SPAWN connections: unprocessed text */
    char flags;
    char state;
    char old_state;
} connsess;

extern connsess conn_list[MAX_CONNECTS];     /* connection list */

extern byte conn_table[MAX_FDSCAN];	     /* fd -> index translation table */

#define CONN_LIST(n) conn_list[conn_table[n]]
#define CONN_INDEX(n) conn_list[n]

extern fd_set fdset;               /* set of descriptors to select() on */

int  tcp_connect(const char *addr, int port);
int  tcp_read(int fd, char *buffer, int maxsize);
void tcp_raw_write(int fd, const char *data, int len);
void tcp_write_escape_iac(int fd, const char *data, int len);
void tcp_write_tty_size(void);
void tcp_write(int fd, char *data);
void tcp_main_write(char *data);
void tcp_flush(void);
void tcp_set_main(int fd);
void tcp_open(char *id, char *initstring, char *host, int port);
int  tcp_find(char *id);
void tcp_show(void);
void tcp_close(char *id);
void tcp_togglesnoop(char *id);
void tcp_spawn(char *id, char *cmd);
int  tcp_unIAC(char *data, int len);

#endif /* _TCP_H_ */