My Project

- Main Page
- Data Structures
- Files

- File List
- Globals

libtelnet.h
Go to the documentation of this file.
1
42 #if !defined(LIBTELNET_INCLUDE)
43 #define LIBTELNET_INCLUDE 1
44
45 /* standard C headers necessary for the libtelnet API */
46 #include <stdarg.h>
47
48 /* C++ support */
49 #if defined(__cplusplus)
50 extern "C" {
51 #endif
52
53 /* printf type checking feature in GCC and some other compilers */
54 #if __GNUC__
55 # define TELNET_GNU_PRINTF(f,a) __attribute__((format(printf, f, a)))
56 # define TELNET_GNU_SENTINEL __attribute__((sentinel))
57 #else
58 # define TELNET_GNU_PRINTF(f,a)
59 # define TELNET_GNU_SENTINEL
60 #endif
61
63 typedef struct telnet_t telnet_t;
64
66 typedef union telnet_event_t telnet_event_t;
67
69 typedef struct telnet_telopt_t telnet_telopt_t;
70
74 #define TELNET_IAC 255
75 #define TELNET_DONT 254
76 #define TELNET_DO 253
77 #define TELNET_WONT 252
78 #define TELNET_WILL 251
79 #define TELNET_SB 250
80 #define TELNET_GA 249
81 #define TELNET_EL 248
82 #define TELNET_EC 247
83 #define TELNET_AYT 246
84 #define TELNET_AO 245
85 #define TELNET_IP 244
86 #define TELNET_BREAK 243
87 #define TELNET_DM 242
88 #define TELNET_NOP 241
89 #define TELNET_SE 240
90 #define TELNET_EOR 239
91 #define TELNET_ABORT 238
92 #define TELNET_SUSP 237
93 #define TELNET_EOF 236
94
99 #define TELNET_TELOPT_BINARY 0
100 #define TELNET_TELOPT_ECHO 1
101 #define TELNET_TELOPT_RCP 2
102 #define TELNET_TELOPT_SGA 3
103 #define TELNET_TELOPT_NAMS 4
104 #define TELNET_TELOPT_STATUS 5
105 #define TELNET_TELOPT_TM 6
106 #define TELNET_TELOPT_RCTE 7
107 #define TELNET_TELOPT_NAOL 8
108 #define TELNET_TELOPT_NAOP 9
109 #define TELNET_TELOPT_NAOCRD 10
110 #define TELNET_TELOPT_NAOHTS 11
111 #define TELNET_TELOPT_NAOHTD 12
112 #define TELNET_TELOPT_NAOFFD 13
113 #define TELNET_TELOPT_NAOVTS 14
114 #define TELNET_TELOPT_NAOVTD 15
115 #define TELNET_TELOPT_NAOLFD 16
116 #define TELNET_TELOPT_XASCII 17
117 #define TELNET_TELOPT_LOGOUT 18
118 #define TELNET_TELOPT_BM 19
119 #define TELNET_TELOPT_DET 20
120 #define TELNET_TELOPT_SUPDUP 21
121 #define TELNET_TELOPT_SUPDUPOUTPUT 22
122 #define TELNET_TELOPT_SNDLOC 23
123 #define TELNET_TELOPT_TTYPE 24
124 #define TELNET_TELOPT_EOR 25
125 #define TELNET_TELOPT_TUID 26
126 #define TELNET_TELOPT_OUTMRK 27
127 #define TELNET_TELOPT_TTYLOC 28
128 #define TELNET_TELOPT_3270REGIME 29
129 #define TELNET_TELOPT_X3PAD 30
130 #define TELNET_TELOPT_NAWS 31
131 #define TELNET_TELOPT_TSPEED 32
132 #define TELNET_TELOPT_LFLOW 33
133 #define TELNET_TELOPT_LINEMODE 34
134 #define TELNET_TELOPT_XDISPLOC 35
135 #define TELNET_TELOPT_ENVIRON 36
136 #define TELNET_TELOPT_AUTHENTICATION 37
137 #define TELNET_TELOPT_ENCRYPT 38
138 #define TELNET_TELOPT_NEW_ENVIRON 39
139 #define TELNET_TELOPT_MSSP 70
140 #define TELNET_TELOPT_COMPRESS2 86
141 #define TELNET_TELOPT_ZMP 93
142 #define TELNET_TELOPT_EXOPL 255
143
144 #define TELNET_TELOPT_MCCP2 86
145
150 #define TELNET_TTYPE_IS 0
151 #define TELNET_TTYPE_SEND 1
152
157 #define TELNET_ENVIRON_IS 0
158 #define TELNET_ENVIRON_SEND 1
159 #define TELNET_ENVIRON_INFO 2
160 #define TELNET_ENVIRON_VAR 0
161 #define TELNET_ENVIRON_VALUE 1
162 #define TELNET_ENVIRON_ESC 2
163 #define TELNET_ENVIRON_USERVAR 3
164
169 #define TELNET_MSSP_VAR 1
170 #define TELNET_MSSP_VAL 2
171
176 #define TELNET_FLAG_PROXY (1<<0)
177
178 #define TELNET_PFLAG_DEFLATE (1<<7)
179
184 enum telnet_error_t {
185 TELNET_EOK = 0,
186 TELNET_EBADVAL,
187 TELNET_ENOMEM,
188 TELNET_EOVERFLOW,
189 TELNET_EPROTOCOL,
190 TELNET_ECOMPRESS
191 };
192 typedef enum telnet_error_t telnet_error_t;
197 enum telnet_event_type_t {
198 TELNET_EV_DATA = 0,
199 TELNET_EV_SEND,
200 TELNET_EV_IAC,
201 TELNET_EV_WILL,
202 TELNET_EV_WONT,
203 TELNET_EV_DO,
204 TELNET_EV_DONT,
205 TELNET_EV_SUBNEGOTIATION,
206 TELNET_EV_COMPRESS,
207 TELNET_EV_ZMP,
208 TELNET_EV_TTYPE,
209 TELNET_EV_ENVIRON,
210 TELNET_EV_MSSP,
211 TELNET_EV_WARNING,
212 TELNET_EV_ERROR
213 };
214 typedef enum telnet_event_type_t telnet_event_type_t;
219 struct telnet_environ_t {
220 unsigned char type;
221 char *var;
222 char *value;
223 };
224
228 union telnet_event_t {
237 enum telnet_event_type_t type;
238
242 struct data_t {
243 enum telnet_event_type_t _type;
244 const char *buffer;
245 size_t size;
246 } data;
247
251 struct error_t {
252 enum telnet_event_type_t _type;
253 const char *file;
254 const char *func;
255 const char *msg;
256 int line;
257 telnet_error_t errcode;
258 } error;
259
263 struct iac_t {
264 enum telnet_event_type_t _type;
265 unsigned char cmd;
266 } iac;
267
271 struct negotiate_t {
272 enum telnet_event_type_t _type;
273 unsigned char telopt;
274 } neg;
275
279 struct subnegotiate_t {
280 enum telnet_event_type_t _type;
281 const char *buffer;
282 size_t size;
283 unsigned char telopt;
284 } sub;
285
289 struct zmp_t {
290 enum telnet_event_type_t _type;
291 const char **argv;
292 size_t argc;
293 } zmp;
294
298 struct ttype_t {
299 enum telnet_event_type_t _type;
300 unsigned char cmd;
301 const char* name;
302 } ttype;
303
307 struct compress_t {
308 enum telnet_event_type_t _type;
309 unsigned char state;
311 } compress;
312
316 struct environ_t {
317 enum telnet_event_type_t _type;
318 const struct telnet_environ_t *values;
319 size_t size;
320 unsigned char cmd;
321 } environ;
322
326 struct mssp_t {
327 enum telnet_event_type_t _type;
328 const struct telnet_environ_t *values;
329 size_t size;
330 } mssp;
331 };
332
345 typedef void (*telnet_event_handler_t)(telnet_t *telnet,
346 telnet_event_t *event, void *user_data);
347
351 struct telnet_telopt_t {
352 short telopt;
353 unsigned char us;
354 unsigned char him;
355 };
356
360 struct telnet_t;
361
375 extern telnet_t* telnet_init(const telnet_telopt_t *telopts,
376 telnet_event_handler_t eh, unsigned char flags, void *user_data);
377
387 extern void telnet_free(telnet_t *telnet);
388
401 extern void telnet_recv(telnet_t *telnet, const char *buffer,
402 size_t size);
403
410 extern void telnet_iac(telnet_t *telnet, unsigned char cmd);
411
423 extern void telnet_negotiate(telnet_t *telnet, unsigned char cmd,
424 unsigned char opt);
425
433 extern void telnet_send(telnet_t *telnet,
434 const char *buffer, size_t size);
435
446 extern void telnet_begin_sb(telnet_t *telnet,
447 unsigned char telopt);
448
457 #define telnet_finish_sb(telnet) telnet_iac((telnet), TELNET_SE)
458
472 extern void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt,
473 const char *buffer, size_t size);
474
487 extern void telnet_begin_compress2(telnet_t *telnet);
488
503 extern int telnet_printf(telnet_t *telnet, const char *fmt, ...)
504 TELNET_GNU_PRINTF(2, 3);
505
511 extern int telnet_vprintf(telnet_t *telnet, const char *fmt, va_list va);
512
524 extern int telnet_raw_printf(telnet_t *telnet, const char *fmt, ...)
525 TELNET_GNU_PRINTF(2, 3);
526
532 extern int telnet_raw_vprintf(telnet_t *telnet, const char *fmt, va_list va);
533
547 extern void telnet_begin_newenviron(telnet_t *telnet, unsigned char type);
548
560 extern void telnet_newenviron_value(telnet_t* telnet, unsigned char type,
561 const char *string);
562
571 #define telnet_finish_newenviron(telnet) telnet_finish_sb((telnet))
572
580 extern void telnet_ttype_send(telnet_t *telnet);
581
612 extern void telnet_ttype_is(telnet_t *telnet, const char* ttype);
613
621 extern void telnet_send_zmp(telnet_t *telnet, size_t argc, const char **argv);
622
631 extern void telnet_send_zmpv(telnet_t *telnet, ...) TELNET_GNU_SENTINEL;
632
638 extern void telnet_send_vzmpv(telnet_t *telnet, va_list va);
639
646 extern void telnet_begin_zmp(telnet_t *telnet, const char *cmd);
647
654 extern void telnet_zmp_arg(telnet_t *telnet, const char *arg);
655
664 #define telnet_finish_zmp(telnet) telnet_finish_sb((telnet))
665
666 /* C++ support */
667 #if defined(__cplusplus)
668 } /* extern "C" */
669 #endif
670
671 #endif /* !defined(LIBTELNET_INCLUDE) */
telnet_event_t::subnegotiate_t::telopt
unsigned char telopt
Definition: libtelnet.h:283
TELNET_EV_DONT
Definition: libtelnet.h:204
telnet_event_t::data_t
Definition: libtelnet.h:242
telnet_iac
void telnet_iac(telnet_t *telnet, unsigned char cmd)
Send a telnet command.
telnet_event_t::negotiate_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:272
TELNET_GNU_PRINTF
#define TELNET_GNU_PRINTF(f, a)
Definition: libtelnet.h:58
telnet_telopt_t
Definition: libtelnet.h:351
TELNET_EV_WILL
Definition: libtelnet.h:201
telnet_begin_newenviron
void telnet_begin_newenviron(telnet_t *telnet, unsigned char type)
Begin a new set of NEW-ENVIRON values to request or send.
telnet_event_t::compress_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:308
telnet_event_handler_t
void(* telnet_event_handler_t)(telnet_t *telnet, telnet_event_t *event, void *user_data)
event handler
Definition: libtelnet.h:345
telnet_send
void telnet_send(telnet_t *telnet, const char *buffer, size_t size)
TELNET_EV_WONT
Definition: libtelnet.h:202
telnet_event_t::subnegotiate_t::buffer
const char * buffer
Definition: libtelnet.h:281
TELNET_EV_SUBNEGOTIATION
Definition: libtelnet.h:205
telnet_event_t::environ_t
Definition: libtelnet.h:316
telnet_event_t::zmp_t
Definition: libtelnet.h:289
telnet_event_t::mssp_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:327
telnet_event_t::negotiate_t::telopt
unsigned char telopt
Definition: libtelnet.h:273
TELNET_EBADVAL
Definition: libtelnet.h:186
TELNET_EOK
Definition: libtelnet.h:185
telnet_event_t::error_t
Definition: libtelnet.h:251
telnet_environ_t
Definition: libtelnet.h:219
telnet_event_t::mssp_t
Definition: libtelnet.h:326
telnet_event_t::subnegotiate_t
Definition: libtelnet.h:279
telnet_event_t::environ_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:317
telnet_telopt_t::telopt
short telopt
Definition: libtelnet.h:352
TELNET_EOVERFLOW
Definition: libtelnet.h:188
TELNET_ENOMEM
Definition: libtelnet.h:187
telnet_raw_printf
int telnet_raw_printf(telnet_t *telnet, const char *fmt,...) TELNET_GNU_PRINTF(2
Send formatted data (no newline escaping).
telnet_t
struct telnet_t telnet_t
Definition: libtelnet.h:63
telnet_newenviron_value
void telnet_newenviron_value(telnet_t *telnet, unsigned char type, const char *string)
Send a NEW-ENVIRON variable name or value.
TELNET_EV_WARNING
Definition: libtelnet.h:211
telnet_event_t::iac_t::cmd
unsigned char cmd
Definition: libtelnet.h:265
telnet_event_t::data_t::buffer
const char * buffer
Definition: libtelnet.h:244
telnet_environ_t::type
unsigned char type
Definition: libtelnet.h:220
telnet_event_t::error_t::func
const char * func
Definition: libtelnet.h:254
telnet_telopt_t::him
unsigned char him
Definition: libtelnet.h:354
TELNET_EV_DATA
Definition: libtelnet.h:198
telnet_event_t::error_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:252
TELNET_EV_MSSP
Definition: libtelnet.h:210
telnet_event_t::data_t::size
size_t size
Definition: libtelnet.h:245
telnet_subnegotiation
void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt, const char *buffer, size_t size)
Shortcut for sending a complete subnegotiation buffer.
telnet_event_t::zmp_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:290
telnet_free
void telnet_free(telnet_t *telnet)
Free up any memory allocated by a state tracker.
telnet_event_t::compress_t
Definition: libtelnet.h:307
telnet_event_t::data_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:243
telnet_zmp_arg
void telnet_zmp_arg(telnet_t *telnet, const char *arg)
Send a ZMP command argument.
telnet_ttype_is
void telnet_ttype_is(telnet_t *telnet, const char *ttype)
Send the TERMINAL-TYPE IS command.
telnet_event_t::error_t::file
const char * file
Definition: libtelnet.h:253
telnet_environ_t::value
char * value
Definition: libtelnet.h:222
telnet_event_t::iac_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:264
TELNET_EV_COMPRESS
Definition: libtelnet.h:206
telnet_printf
int telnet_printf(telnet_t *telnet, const char *fmt,...) TELNET_GNU_PRINTF(2
Send formatted data.
telnet_event_t::ttype_t
Definition: libtelnet.h:298
TELNET_EV_SEND
Definition: libtelnet.h:199
telnet_begin_zmp
void telnet_begin_zmp(telnet_t *telnet, const char *cmd)
Begin sending a ZMP command.
telnet_event_t::ttype_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:299
telnet_event_t::environ_t::values
const struct telnet_environ_t * values
Definition: libtelnet.h:318
telnet_event_t::negotiate_t
Definition: libtelnet.h:271
TELNET_ECOMPRESS
Definition: libtelnet.h:190
telnet_event_t::environ_t::size
size_t size
Definition: libtelnet.h:319
telnet_negotiate
void telnet_negotiate(telnet_t *telnet, unsigned char cmd, unsigned char opt)
Send negotiation command.
telnet_raw_vprintf
int int telnet_raw_vprintf(telnet_t *telnet, const char *fmt, va_list va)
Send formatted data (no newline escaping).
telnet_begin_compress2
void telnet_begin_compress2(telnet_t *telnet)
Begin sending compressed data.
TELNET_EV_TTYPE
Definition: libtelnet.h:208
telnet_ttype_send
void telnet_ttype_send(telnet_t *telnet)
Send the TERMINAL-TYPE SEND command.
telnet_event_t::iac_t
Definition: libtelnet.h:263
telnet_send_vzmpv
void telnet_send_vzmpv(telnet_t *telnet, va_list va)
Send a ZMP command.
telnet_recv
void telnet_recv(telnet_t *telnet, const char *buffer, size_t size)
Push a byte buffer into the state tracker.
telnet_event_t::zmp_t::argv
const char ** argv
Definition: libtelnet.h:291
telnet_event_t::mssp_t::values
const struct telnet_environ_t * values
Definition: libtelnet.h:328
telnet_event_type_t
telnet_event_type_t
Definition: libtelnet.h:197
telnet_event_t::subnegotiate_t::size
size_t size
Definition: libtelnet.h:282
TELNET_EV_ERROR
Definition: libtelnet.h:212
telnet_event_t
Definition: libtelnet.h:228
telnet_environ_t::var
char * var
Definition: libtelnet.h:221
telnet_vprintf
int int telnet_vprintf(telnet_t *telnet, const char *fmt, va_list va)
Send formatted data.
TELNET_EV_ZMP
Definition: libtelnet.h:207
TELNET_EV_IAC
Definition: libtelnet.h:200
telnet_begin_sb
void telnet_begin_sb(telnet_t *telnet, unsigned char telopt)
Begin a sub-negotiation command.
telnet_telopt_t::us
unsigned char us
Definition: libtelnet.h:353
telnet_event_t::error_t::line
int line
Definition: libtelnet.h:256
telnet_event_t::zmp_t::argc
size_t argc
Definition: libtelnet.h:292
telnet_event_t::error_t::msg
const char * msg
Definition: libtelnet.h:255
telnet_event_t::environ_t::cmd
unsigned char cmd
Definition: libtelnet.h:320
TELNET_EPROTOCOL
Definition: libtelnet.h:189
telnet_event_t::subnegotiate_t::_type
enum telnet_event_type_t _type
Definition: libtelnet.h:280
TELNET_EV_ENVIRON
Definition: libtelnet.h:209
telnet_send_zmp
void telnet_send_zmp(telnet_t *telnet, size_t argc, const char **argv)
Send a ZMP command.
telnet_send_zmpv
void telnet_send_zmpv(telnet_t *telnet,...) TELNET_GNU_SENTINEL
Send a ZMP command.
telnet_event_t::ttype_t::cmd
unsigned char cmd
Definition: libtelnet.h:300
TELNET_EV_DO
Definition: libtelnet.h:203
telnet_event_t::error_t::errcode
telnet_error_t errcode
Definition: libtelnet.h:257
telnet_event_t::type
enum telnet_event_type_t type
Event type.
Definition: libtelnet.h:237
telnet_event_t::compress_t::state
unsigned char state
Definition: libtelnet.h:309
TELNET_GNU_SENTINEL
#define TELNET_GNU_SENTINEL
Definition: libtelnet.h:59
telnet_error_t
telnet_error_t
Definition: libtelnet.h:184
telnet_init
telnet_t * telnet_init(const telnet_telopt_t *telopts, telnet_event_handler_t eh, unsigned char flags, void *user_data)
Initialize a telnet state tracker.
telnet_event_t::mssp_t::size
size_t size
Definition: libtelnet.h:329
telnet_event_t::ttype_t::name
const char * name
Definition: libtelnet.h:301