-
Notifications
You must be signed in to change notification settings - Fork 21
/
telnet.h
146 lines (132 loc) · 4.23 KB
/
telnet.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*-
* Copyright (c) 1997 Dave Richards <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* and exceptions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the authors may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* 4. The code can not be used by Gary Random, Random Communications, Inc.,
* the employees of Random Communications, Inc. or its subsidiaries,
* including Defiance MUD, without prior written permission from the
* authors.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Telnet Option Block.
*/
typedef struct {
u_char o_us;
u_char o_usq;
u_char o_him;
u_char o_himq;
} opt_t;
/*
* Option States.
*/
#define OS_NO 0
#define OS_YES 1
#define OS_WANTNO 2
#define OS_WANTYES 3
/*
* Option Queue States.
*/
#define OQ_EMPTY 0
#define OQ_OPPOSITE 2
/*
* Options.
*/
#define OP_ECHO 0
#define OP_SGA 1
#define OP_CDM 2
#define OP_GMCP 3
#define OP_MSSP 4
#define OP_CHARSET 5
#define OP_SIZE 6
/*
* Telnet Control Block.
*/
typedef struct {
u_short t_flags;
u_char t_state;
u_char t_opt;
opt_t t_optb[OP_SIZE];
ndesc_t * t_nd;
nqueue_t * t_rawq;
nqueue_t * t_canq; nqueue_t * t_optq;
nqueue_t * t_outq;
void * t_ip;
u_int t_rblen;
u_int t_sblen;
struct task *task;
} telnet_t;
/*
* Telnet Flags.
*/
#define TF_ATTACH 0x0001
#define TF_INPUT 0x0002
#define TF_DISCONNECT 0x0004
#define TF_OVFLCANQ 0x0010
#define TF_OVFLOPTQ 0x0020
#define TF_OVFLOUTQ 0x0040
#define TF_SYNCH 0x0080
#define TF_URGENT 0x0100
#define TF_GA 0x0200
#define TF_ECHO 0x1000
#define TF_SGA 0x2000
#define TF_GMCP 0x4000
/*
* Telnet Input States.
*/
#define TS_DATA 0
#define TS_CR 1
#define TS_IAC 2
#define TS_IAC_SB 3
#define TS_IAC_SB_DATA 4
#define TS_IAC_SB_IAC 5
#define TS_IAC_WILL 6
#define TS_IAC_WONT 7
#define TS_IAC_DO 8
#define TS_IAC_DONT 9
#define TELOPT_CHARSET 42
#define TELOPT_MSSP 70
#define TELOPT_GMCP 201
#define TELOPT_CDM 205
/*
* MSSP Data Block
*/
typedef struct {
u_char *name;
size_t size;
u_char *values[];
} mssp_t;
#define MSSP_VAR 1
#define MSSP_VAL 2
#define CHARSET_REQUEST 1
#define CHARSET_ACCEPTED 2
#define CHARSET_REJECTED 3
void telnet_detach(telnet_t *);
int telnet_output(telnet_t *, u_char *);
int telnet_output_gmcp(telnet_t *, u_char *);
int telnet_output_mssp(telnet_t *, mssp_t *vars[], size_t count);
void telnet_enable_echo(telnet_t *);
void telnet_disable_echo(telnet_t *);
void telnet_enable_gmcp(telnet_t *);
void telnet_disable_gmcp(telnet_t *);
void telnet_init(u_short);