Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 1 | ===================================================================== |
| 2 | libtelnet - TELNET protocol handling library |
| 3 | ===================================================================== |
| 4 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 5 | http://github.com/elanthis/libtelnet |
| 6 | |
| 7 | Sean Middleditch |
| 8 | sean@sourcemud.org |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 9 | |
| 10 | --------------------------------------------------------------------- |
| 11 | The author or authors of this code dedicate any and all copyright |
| 12 | interest in this code to the public domain. We make this dedication |
| 13 | for the benefit of the public at large and to the detriment of our |
| 14 | heirs and successors. We intend this dedication to be an overt act of |
| 15 | relinquishment in perpetuity of all present and future rights to this |
| 16 | code under copyright law. |
| 17 | --------------------------------------------------------------------- |
| 18 | |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 19 | I. INTRODUCTION |
| 20 | ===================================================================== |
| 21 | |
| 22 | libtelnet provides safe and correct handling of the core TELNET |
Sean Middleditch | 8b78896 | 2009-03-16 01:06:27 -0400 | [diff] [blame] | 23 | protocol. In addition to the base TELNET protocol, libtelnet also |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 24 | implements the Q method of TELNET option negotiation. libtelnet can |
| 25 | be used for writing servers, clients, or proxies. |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 26 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 27 | For more information on the TELNET protocol, see: |
| 28 | |
| 29 | http://www.faqs.org/rfcs/rfc854.html |
Sean Middleditch | 8b78896 | 2009-03-16 01:06:27 -0400 | [diff] [blame] | 30 | http://www.faqs.org/rfcs/rfc1143.html |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 31 | |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 32 | II. LIBTELNET API |
| 33 | ===================================================================== |
| 34 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 35 | The libtelnet API contains several distinct parts. The first part is |
| 36 | the basic initialization and deinitialization routines. The second |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 37 | part is a single function for pushing received data into the telnet |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 38 | processor. The third part is the libtelnet output functions, which |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 39 | generate TELNET commands and ensure data is properly formatted before |
| 40 | sending over the wire. The final part is the event handler |
| 41 | interface. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 42 | |
| 43 | IIa. Initialization |
| 44 | |
Sean Middleditch | bfc641e | 2009-03-22 16:26:06 -0400 | [diff] [blame] | 45 | Using libtelnet requires the initialization of a telnet_t structure |
| 46 | which stores all current state for a single TELNET connection. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 47 | |
Sean Middleditch | bfc641e | 2009-03-22 16:26:06 -0400 | [diff] [blame] | 48 | Initializing a telnet_t structure requires several pieces of data. |
| 49 | One of these is the telopt support table, which specifies which |
| 50 | TELNET options your application supports both locally and remotely. |
| 51 | This table is comprised of telnet_telopt_t structures, one for each |
| 52 | supported option. Each entry specifies the option supported, |
| 53 | whether the option is supported locally or remotely. |
| 54 | |
| 55 | struct telnet_telopt_t { |
| 56 | short telopt; |
| 57 | unsigned char us; |
| 58 | unsigned char him; |
| 59 | }; |
| 60 | |
| 61 | The us field denotes whether your application supporst the telopt |
| 62 | locally. It should be set to TELNET_WILL if you support it and to |
| 63 | TELNET_WONT if you don't. The him field denotes whether the telopt |
| 64 | is supported on the remote end, and should be TELNET_DO if yes and |
| 65 | TELNET_DONT if not. |
| 66 | |
| 67 | When definition the telopt table you must include an end marker |
| 68 | entry, which is simply an entry with telopt set to -1. For |
| 69 | example: |
| 70 | |
| 71 | static const telnet_telopt_t my_telopts[] = { |
| 72 | { TELNET_TELOPT_ECHO, TELNET_WILL, TELNET_DONT }, |
| 73 | { TELNET_TELOPT_TTYPE, TELNET_WILL, TELNET_DONT }, |
| 74 | { TELNET_TELOPT_COMPRESS2, TELNET_WONT, TELNET_DO }, |
| 75 | { TELNET_TELOPT_ZMP, TELNET_WONT, TELNET_DO }, |
| 76 | { TELNET_TELOPT_MSSP, TELNET_WONT, TELNET_DO }, |
| 77 | { TELNET_TELOPT_BINARY, TELNET_WILL, TELNET_DO }, |
| 78 | { TELNET_TELOPT_NAWS, TELNET_WILL, TELNET_DONT }, |
| 79 | { -1, 0, 0 } |
| 80 | }; |
| 81 | |
| 82 | If you need to dynamically alter supported options on a |
| 83 | per-connection basis then you may use a different tables |
| 84 | (dynamically allocated if necessary) per call to telnet_init() or |
| 85 | you share a single constant table like the above example between |
| 86 | all connections if you support a fixed set of options. Most |
| 87 | applications will support only a fixed set of options. |
| 88 | |
| 89 | void telnet_init(telnet_t *telnet, const telnet_telopts_t *telopts, |
| 90 | telnet_event_handler_t handler, unsigned char flags, |
| 91 | void *user_data); |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 92 | The telnet_init() function is responsible for initializing the |
| 93 | data in a telnet_t structure. It must be called immediately after |
| 94 | establishing a connection and before any other libtelnet API calls |
| 95 | are made. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 96 | |
Sean Middleditch | bfc641e | 2009-03-22 16:26:06 -0400 | [diff] [blame] | 97 | The telopts field is the telopt support table as described above. |
| 98 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 99 | The handler parameter must be a function matching the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 100 | telnet_event_handler_t definition. More information about events |
| 101 | can be found in section IId. |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 102 | |
Sean Middleditch | 9f79cc5 | 2009-03-15 13:39:24 -0400 | [diff] [blame] | 103 | The user_data parameter is passed to the event handler whenver it |
| 104 | is invoked. This will usually be a structure container |
| 105 | information about the connection, including a socket descriptor |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 106 | for implementing TELNET_EV_SEND event handling. |
Sean Middleditch | 9f79cc5 | 2009-03-15 13:39:24 -0400 | [diff] [blame] | 107 | |
Sean Middleditch | 08bb05f | 2009-03-15 23:29:46 -0400 | [diff] [blame] | 108 | The flags parameter can be any of the following flag constants |
| 109 | bit-or'd together, or 0 to leave all options disabled. |
| 110 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 111 | TELNET_FLAG_PROXY |
Sean Middleditch | c337ba6 | 2009-03-16 16:47:27 -0400 | [diff] [blame] | 112 | Operate in proxy mode. This disables the RFC1143 support and |
| 113 | enables automatic detection of COMPRESS2 streams. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 114 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 115 | boid telnet_free(telnet_t *telnet); |
| 116 | Releases any internal memory allocated by libtelnet. This must be |
| 117 | called whenever a connection is closed, or you will incur memory |
| 118 | leaks. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 119 | |
| 120 | IIb. Receiving Data |
| 121 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 122 | void telnet_recv(telnet_t *telnet, |
Sean Middleditch | 340a51b | 2009-03-19 02:08:46 -0400 | [diff] [blame] | 123 | const char *buffer, unsigned int size, void *user_data); |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 124 | When your application receives data over the socket from the |
| 125 | remote end, it must pass the received bytes into this function. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 126 | |
| 127 | As the TELNET stream is parsed, events will be generated and |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 128 | passed to the event handler given to telnet_init(). Of particular |
| 129 | interest for data receiving is the TELNET_EV_DATA event, which is |
| 130 | triggered for any regular data such as user input or server |
| 131 | process output. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 132 | |
| 133 | IIc. Sending Data |
| 134 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 135 | All of the output functions will invoke the TELNET_EV_SEND event. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 136 | |
| 137 | Note: it is very important that ALL data sent to the remote end of |
| 138 | the connection be passed through libtelnet. All user input or |
| 139 | process output that you wish to send over the wire should be given |
Sean Middleditch | 4613e68 | 2009-03-16 17:21:48 -0400 | [diff] [blame] | 140 | to one of the following functions. Do NOT send or buffer |
| 141 | unprocessed output data directly! |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 142 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 143 | void telnet_iac(telnet_t *telnet, unsigned char cmd); |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 144 | Sends a single "simple" TELNET command, such as the GO-AHEAD |
| 145 | commands (255 249). |
| 146 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 147 | void telnet_negotiate(telnet_t *telnet, unsigned char cmd, |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 148 | unsigned char opt); |
| 149 | Sends a TELNET negotiation command. The cmd parameter must be one |
| 150 | of TELNET_WILL, TELNET_DONT, TELNET_DO, or TELNET_DONT. The opt |
| 151 | parameter is the option to negotiate. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 152 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 153 | Unless in PROXY mode, the RFC1143 support may delay or ellide the |
| 154 | request entirely, as appropriate. It will ignore duplicate |
| 155 | invocations, such as asking for WILL NAWS when NAWS is already on |
| 156 | or is currently awaiting response from the remote end. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 157 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 158 | void telnet_send(telnet_t *telnet, const char *buffer, size_t size); |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 159 | Sends raw data, which would be either the process output from a |
| 160 | server or the user input from a client. |
| 161 | |
| 162 | For sending regular text is may be more convenient to use |
| 163 | telnet_printf(). |
Sean Middleditch | 90e79da | 2009-03-19 15:17:13 -0400 | [diff] [blame] | 164 | |
| 165 | void telnet_begin_subnegotiation(telnet_t *telnet, unsigned char |
| 166 | telopt); |
| 167 | Sends the header for a TELNET sub-negotiation command for the |
| 168 | specified option. All send data following this command will be |
| 169 | part of the sub-negotiation data until a call is made to |
| 170 | telnet_finish_subnegotiation(). |
| 171 | |
| 172 | You should not use telnet_printf() for sending subnegotiation |
| 173 | data as it will perform newline translations that usually do not |
| 174 | need to be done for subnegotiation data, and may cause problems. |
| 175 | |
| 176 | void telnet_finish_subnegotiation(telnet_t *telnet); |
| 177 | Sends the end marker for a TELNET sub-negotiation command. This |
| 178 | must be called after (and only after) a call has been made to |
| 179 | telnet_begin_subnegotiation() and any negotiation data has been |
| 180 | sent. |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 181 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 182 | void telnet_subnegotiation(telnet_t *telnet, unsigned char telopt, |
| 183 | const char *buffer, unsigned int size); |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 184 | Sends a TELNET sub-negotiation command. The telopt parameter is |
| 185 | the sub-negotiation option. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 186 | |
Sean Middleditch | 90e79da | 2009-03-19 15:17:13 -0400 | [diff] [blame] | 187 | Note that this function is just a shorthand for: |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 188 | telnet_begin_sb(telnet, telopt); |
| 189 | telnet_send(telnet, buffer, size); |
| 190 | telnet_end_sb(telnet); |
Sean Middleditch | 2b4bfc4 | 2009-03-16 01:25:52 -0400 | [diff] [blame] | 191 | |
| 192 | For some subnegotiations that involve a lot of complex formatted |
Sean Middleditch | 90e79da | 2009-03-19 15:17:13 -0400 | [diff] [blame] | 193 | data to be sent, it may be easier to make calls to both |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 194 | telnet_begin_sb() and telnet_finish_sb() and using telnet_send() |
| 195 | or telnet_printf2() to format the data. |
Sean Middleditch | 2b4bfc4 | 2009-03-16 01:25:52 -0400 | [diff] [blame] | 196 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 197 | NOTE: telnet_subnegotiation() does have special behavior in |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 198 | PROXY mode, as in that mode this function will automatically |
Sean Middleditch | 2b4bfc4 | 2009-03-16 01:25:52 -0400 | [diff] [blame] | 199 | detect the COMPRESS2 marker and enable zlib compression. |
| 200 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 201 | int telnet_printf(telnet_t *telnet, const char *fmt, ...); |
| 202 | This functions very similarly to fprintf, except that output is |
| 203 | sent through libtelnet for processing. IAC bytes are properly |
| 204 | escaped, C newlines (\n) are translated into CR LF, and C carriage |
| 205 | returns (\r) are translated into CR NUL, all as required by |
| 206 | RFC854. The return code is the length of the formatted text. |
Sean Middleditch | 4613e68 | 2009-03-16 17:21:48 -0400 | [diff] [blame] | 207 | |
| 208 | NOTE: due to an internal implementation detail, the maximum |
| 209 | lenth of the formatted text is 4096 characters. |
| 210 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 211 | int telnet_printf2(telnet_t *telnet, const char *fmt, ...); |
| 212 | Identical to telnet_printf() except that \r and \n are not |
| 213 | translated. This should be used if you are attempting to send |
| 214 | raw data inside a subnegotiation or if you have already manually |
| 215 | escaped newlines. |
Sean Middleditch | 4613e68 | 2009-03-16 17:21:48 -0400 | [diff] [blame] | 216 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 217 | IId. Event Handling |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 218 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 219 | libtelnet relies on an event-handling mechanism for processing the |
| 220 | parsed TELNET protocol stream as well as for buffering and sending |
| 221 | output data. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 222 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 223 | When you initialize a telnet_t structure with telnet_init() you had |
| 224 | to pass in an event handler function. This function must meet the |
| 225 | following prototype: |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 226 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 227 | void (telnet_t *telnet, telnet_event_t *event, void *user_data); |
Sean Middleditch | 9f79cc5 | 2009-03-15 13:39:24 -0400 | [diff] [blame] | 228 | |
| 229 | The event structure is detailed below. The user_data value is the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 230 | pointer passed to telnet_init(). |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 231 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 232 | struct telnet_event_t { |
Sean Middleditch | 340a51b | 2009-03-19 02:08:46 -0400 | [diff] [blame] | 233 | const char *buffer; |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 234 | unsigned int size; |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 235 | telnet_event_type_t type; |
Sean Middleditch | 812358d | 2009-03-15 23:24:03 -0400 | [diff] [blame] | 236 | unsigned char command; |
| 237 | unsigned char telopt; |
| 238 | unsigned char accept; |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 239 | }; |
| 240 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 241 | The enumeration values of telnet_event_type_t are described in |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 242 | detail below. Whenever the the event handler is invoked, the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 243 | application must look at the event->type value and do any necessary |
| 244 | processing. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 245 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 246 | The only event that MUST be implemented is TELNET_EV_SEND. Most |
| 247 | applications will also always want to implement the event |
| 248 | TELNET_EV_DATA. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 249 | |
| 250 | Here is an example event handler implementation which includes |
| 251 | handlers for several important events. |
| 252 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 253 | void my_event_handler(telnet_t *telnet, telnet_event_t *ev, |
Sean Middleditch | 812358d | 2009-03-15 23:24:03 -0400 | [diff] [blame] | 254 | void *user_data) { |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 255 | struct user_info *user = (struct user_info *)user_data; |
| 256 | |
| 257 | switch (ev->type) { |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 258 | case TELNET_EV_DATA: |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 259 | process_user_input(user, event->buffer, event->size); |
| 260 | break; |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 261 | case TELNET_EV_SEND: |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 262 | write_to_descriptor(user, event->buffer, event->size); |
| 263 | break; |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 264 | case TELNET_EV_ERROR: |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 265 | fatal_error("TELNET error: %s", event->buffer); |
| 266 | break; |
| 267 | } |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 268 | } |
| 269 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 270 | TELNET_EV_DATA: |
| 271 | The DATA event is triggered whenever regular data (not part of any |
| 272 | special TELNET command) is received. For a client, this will be |
| 273 | process output from the server. For a server, this will be input |
| 274 | typed by the user. |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 275 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 276 | The event->buffer value will contain the bytes received and the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 277 | event->size value will contain the number of bytes received. Note |
| 278 | that event->buffer is not NUL terminated! |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 279 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 280 | NOTE: there is no guarantee that user input or server output |
| 281 | will be received in whole lines. If you wish to process data |
| 282 | a line at a time, you are responsible for buffering the data and |
| 283 | checking for line terminators yourself! |
| 284 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 285 | TELNET_EV_SEND: |
| 286 | This event is sent whenever libtelnet has generated data that must |
| 287 | be sent over the wire to the remove end. Generally that means |
| 288 | calling send() or adding the data to your application's output |
| 289 | buffer. |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 290 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 291 | The event->buffer value will contain the bytes to send and the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 292 | event->size value will contain the number of bytes to send. Note |
| 293 | that event->buffer is not NUL terminated, and may include NUL |
| 294 | characters in its data, so always use event->size! |
Sean Middleditch | 3032302 | 2009-03-14 21:45:28 -0400 | [diff] [blame] | 295 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 296 | NOTE: Your SEND event handler must send or buffer the data in |
| 297 | its raw form as provided by libtelnet. If you wish to perform |
| 298 | any kind of preprocessing on data you want to send to the other |
| 299 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 300 | TELNET_EV_IAC: |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 301 | The IAC event is triggered whenever a simple IAC command is |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 302 | received, such as the IAC EOR (end of record, also called go ahead |
| 303 | or GA) command. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 304 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 305 | The command received is in the event->command value. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 306 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 307 | The necessary processing depends on the specific commands; see |
| 308 | the TELNET RFC for more information. |
| 309 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 310 | TELNET_EV_WILL: |
| 311 | TELNET_EV_DO: |
| 312 | The WILL and DO events are sent when a TELNET negotiation command |
| 313 | of the same name is received. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 314 | |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 315 | WILL events are sent by the remote end when they wish to be |
| 316 | allowed to turn an option on on their end, or in confirmation |
| 317 | after you have sent a DO command to them. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 318 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 319 | DO events are sent by the remote end when they wish for you to |
| 320 | turn on an option on your end, or in confirmation after you have |
| 321 | sent a WILL command to them. |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 322 | |
| 323 | In either case, the TELNET option under negotiation will be in |
| 324 | event->telopt field. |
| 325 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 326 | If you support the option and wish for it to be enabled you must |
| 327 | set the event->accept field to 1, unless this event is a |
| 328 | confirmation for a previous WILL/DO command you sent to the remote |
| 329 | end. If you do not set event->field to 1 then libtelnet will send |
| 330 | a rejection command back to the other end. |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 331 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 332 | libtelnet manages some of the pecularities of negotiation for you. |
| 333 | For information on libtelnet's negotiation method, see: |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 334 | |
| 335 | http://www.faqs.org/rfcs/rfc1143.html |
| 336 | |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 337 | Examples: |
| 338 | |
| 339 | You want remote end to use TTYPE, so you send DO TTYPE. |
| 340 | Remote accepts and sends WILL TTYPE. |
| 341 | |
| 342 | Remote end wants you to use SGA, so they send DO_SGA. |
| 343 | You do not support SGA and set event->accept = 0. |
| 344 | |
| 345 | Remote end wants to use ZMP, so they send WILL ZMP. |
| 346 | You support ZMP, so you set event->accept = 1 and enable |
| 347 | local ZMP support. |
| 348 | |
| 349 | You want to use MCCP2, so you send WILL COMPRESS2. |
| 350 | Remote end accepts and sends DO COMPRESS2. |
| 351 | |
| 352 | Note that in PROXY mode libtelnet will do no processing of its |
| 353 | own for you. |
| 354 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 355 | TELNET_EV_WONT: |
| 356 | TELNET_EV_DONT: |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 357 | The WONT and DONT events are sent when the remote end of the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 358 | connection wishes to disable an option, when they are refusing to |
| 359 | a support an option that you have asked for, or in confirmation of |
| 360 | an option you have asked to be disabled. |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 361 | |
| 362 | Most commonly WONT and DONT events are sent as rejections of |
| 363 | features you requested by sending DO or WILL events. Receiving |
| 364 | these events means the TELNET option is not or will not be |
| 365 | supported by the remote end, so give up. |
| 366 | |
| 367 | Sometimes WONT or DONT will be sent for TELNET options that are |
| 368 | already enabled, but the remote end wishes to stop using. You |
| 369 | cannot decline. These events are demands that must be complied |
| 370 | with. libtelnet will always send the appropriate response back |
| 371 | without consulting your application. These events are sent to |
| 372 | allow your application to disable its own use of the features. |
| 373 | |
| 374 | In either case, the TELNET option under negotiation will be in |
| 375 | event->telopt field. |
| 376 | |
| 377 | Note that in PROXY mode libtelnet will do no processing of its |
| 378 | own for you. |
| 379 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 380 | TELNET_EV_SUBNEGOTIATION: |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 381 | Triggered whenever a TELNET sub-negotiation has been received. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 382 | Sub-negotiations include the NAWS option for communicating |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 383 | terminal size to a server, the NEW-ENVIRON and TTYPE options for |
| 384 | negotiating terminal features, and MUD-centric protocols such as |
| 385 | ZMP, MSSP, and MCCP2. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 386 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 387 | The event->telopt value is the option under sub-negotiation. The |
| 388 | remaining data (if any) is passed in event->buffer and |
| 389 | event->size. Note that most subnegotiation commands can include |
| 390 | embedded NUL bytes in the subnegotiation data, and the data |
| 391 | event->buffer is not NUL terminated, so always use the event->size |
| 392 | value! |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 393 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 394 | The meaning and necessary processing for subnegotiations are |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 395 | defined in various TELNET RFCs and other informal specifications. |
| 396 | A subnegotiation should never be sent unless the specific option |
| 397 | has been enabled through the use of the telnet negotiation |
| 398 | feature. |
Sean Middleditch | 8d50fe8 | 2009-03-22 22:35:17 -0400 | [diff] [blame^] | 399 | |
| 400 | TTYPE/ENVIRON/NEW-ENVIRON/MSSP SUPPORT: |
| 401 | These telopts all use a similar format to their subnegotiation |
| 402 | requests. The data is arrnaged as a series of terms, with each |
| 403 | term beginning with a single byte type marker (a small integer in |
| 404 | the range of 0 to 3) followed by zero or more bytes until another |
| 405 | type marker or the end of the subnegotiation data. |
| 406 | |
| 407 | libtelnet parses these. The number of terms found is put in the |
| 408 | ev->argc field. The terms themselves are stored as |
| 409 | NUL-terminated strings in the ev->argv array. The type byte is |
| 410 | always the first byte of these strings, e.g. ev->argv[0][0]. Due |
| 411 | to the fact that 0 is a valid type marker, remember that |
| 412 | accessing the remainder of the term's data as a string must be |
| 413 | done as &ev->argv[term_index][1]. |
| 414 | |
| 415 | Note that libtelnet does not support the ESC byte for ENVIRON/ |
| 416 | NEW-ENVIRON. Data using escaped bytes will not be parsed |
| 417 | correctly. |
Sean Middleditch | b10946c | 2009-03-22 18:21:14 -0400 | [diff] [blame] | 418 | |
| 419 | ZMP SUPPORT: |
| 420 | The event->argc field is the number of ZMP parameters, including |
| 421 | the command name, that have been received. The event->argv field |
| 422 | is an array of strings, one for each ZMP parameter. The command |
| 423 | name will be in event->argv[0]. If the ZMP command could not be |
| 424 | parsed because it was malformed, event->argc will be 0 (zero) and |
| 425 | event->argv will be NULL. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 426 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 427 | TELNET_EV_COMPRESS |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 428 | The COMPRESS event notifies the app that COMPRESS2/MCCP2 |
| 429 | compression has begun or ended. Only servers can send compressed |
| 430 | data, and hence only clients will receive compressed data. |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 431 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 432 | The event->command value will be 1 if compression has started and |
| 433 | will be 0 if compression has ended. |
Sean Middleditch | 1699227 | 2009-03-15 19:42:03 -0400 | [diff] [blame] | 434 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 435 | TELNET_EV_WARNING |
| 436 | The WARNING event is sent whenever something has gone wrong inside |
| 437 | of libtelnet (possibly due to malformed data sent by the other |
| 438 | end) but which recovery is (likely) possible. It may be safe to |
| 439 | continue using the connection, but some data may have been lost or |
| 440 | incorrectly interpreted. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 441 | |
| 442 | The event->buffer value will contain a NUL terminated string |
| 443 | explaining the error, and the event->size value containers the |
| 444 | length of the string. |
| 445 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 446 | TELNET_EV_ERROR |
Sean Middleditch | 1699227 | 2009-03-15 19:42:03 -0400 | [diff] [blame] | 447 | Similar to the WARNING event, the ERROR event is sent whenever |
| 448 | something has gone wrong. ERROR events are non-recoverable, |
| 449 | however, and the application should immediately close the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 450 | connection. Whatever has happened is likely going only to result |
| 451 | in garbage from libtelnet. This is most likely to happen when a |
| 452 | COMPRESS2 stream fails, but other problems can occur. |
Sean Middleditch | 1699227 | 2009-03-15 19:42:03 -0400 | [diff] [blame] | 453 | |
| 454 | The event->buffer value will contain a NUL terminated string |
| 455 | explaining the error, and the event->size value containers the |
| 456 | length of the string. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 457 | |
| 458 | III. INTEGRATING LIBTELNET WITH COMMON MUDS |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 459 | ===================================================================== |
| 460 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 461 | FIXME: fill in some notes about how to splice in libtelnet with |
| 462 | common Diku/Merc/Circle/etc. MUD codebases. |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 463 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 464 | IV. SAFETY AND CORRECTNESS CONSIDERATIONS |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 465 | ===================================================================== |
| 466 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 467 | Your existing application may make heavy use of its own output |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 468 | buffering and transmission commands, including hand-made routines for |
| 469 | sending TELNET commands and sub-negotiation requests. There are at |
| 470 | times subtle issues that need to be handled when communication over |
| 471 | the TELNET protocol, not least of which is the need to escape any |
| 472 | byte value 0xFF with a special TELNET command. |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 473 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 474 | For these reasons, it is very important that applications making use |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 475 | of libtelnet always make use of the libtelnet output functions for |
| 476 | all data being sent over the TELNET connection. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 477 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 478 | In particular, if you are writing a client, all user input must be |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 479 | passed through to telnet_send(). This also includes any input |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 480 | generated automatically by scripts, triggers, or macros. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 481 | |
| 482 | For a server, any and all output -- including ANSI/VT100 escape |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 483 | codes, regular text, newlines, and so on -- must be passed through to |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 484 | telnet_send(). |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 485 | |
| 486 | Any TELNET commands that are to be sent must be given to one of the |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 487 | following: telnet_iac, telnet_negotiate, or telnet_subnegotiation(). |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 488 | |
| 489 | If you are attempting to enable COMPRESS2/MCCP2, you must use the |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 490 | telnet_begin_compress2() function. |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 491 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 492 | V. MCCP2 COMPRESSION |
Sean Middleditch | b9e4864 | 2009-03-12 23:33:27 -0400 | [diff] [blame] | 493 | ===================================================================== |
| 494 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 495 | The MCCP2 (COMPRESS2) TELNET extension allows for the compression of |
| 496 | all traffic sent from server to client. For more information: |
| 497 | |
| 498 | http://www.mudbytes.net/index.php?a=articles&s=mccp |
| 499 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 500 | In order for libtelnet to support MCCP2, zlib must be installed and |
| 501 | enabled when compiling libtelnet. Use -DHAVE_ZLIB to enable zlib |
| 502 | when compiling libtelnet.c and pass -lz to the linker to link in the |
| 503 | zlib shared library. |
| 504 | |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 505 | libtelnet transparently supports MCCP2. For a server to support |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 506 | MCCP2, the application must begin negotiation of the COMPRESS2 option |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 507 | using telnet_negotiate(), for example: |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 508 | |
Sean Middleditch | 4f0c37f | 2009-03-20 23:08:55 -0400 | [diff] [blame] | 509 | telnet_negotiate(&telnet, TELNET_WILL, |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 510 | TELNET_OPTION_COMPRESS2, user_data); |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 511 | |
Sean Middleditch | 5b5bc92 | 2009-03-15 23:02:10 -0400 | [diff] [blame] | 512 | If a favorable DO COMPRESS2 is sent back from the client then the |
| 513 | server application can begin compression at any time by calling |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 514 | telnet_begin_compress2(). |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 515 | |
Sean Middleditch | 637df7f | 2009-03-15 12:57:32 -0400 | [diff] [blame] | 516 | If a connection is in PROXY mode and COMPRESS2 support is enabled |
| 517 | then libtelnet will automatically detect the start of a COMPRESS2 |
| 518 | stream, in either the sending or receiving direction. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 519 | |
Sean Middleditch | 1887735 | 2009-03-22 16:57:44 -0400 | [diff] [blame] | 520 | VI. ZENITH MUD PROTOCOL (ZMP) SUPPORT |
| 521 | ===================================================================== |
| 522 | |
| 523 | The Zenith MUD Protocol allows applications to send messages across |
| 524 | the TELNET connection outside of the normal user input/output data |
| 525 | stream. libtelnet offers some limited support for receiving and |
| 526 | sending ZMP commands to make implementing a full ZMP stack easier. |
| 527 | For more information on ZMP: |
| 528 | |
| 529 | http://zmp.sourcemud.org/ |
| 530 | |
| 531 | For a server to enable ZMP, it must send the WILL ZMP negotitaion: |
| 532 | |
| 533 | telnet_negotiate(&telnet, TELNET_WILL, TELNET_TELOPT_ZMP); |
| 534 | |
| 535 | For a client to support ZMP it must include ZMP in the telopt table |
| 536 | passed to telnet_init(), with the him field set to TELNET_DO: |
| 537 | |
| 538 | { TELNET_TELOPT_ZMP, TELNET_WONT, TELNET_DO }, |
| 539 | |
| 540 | Note that while ZMP is a bi-directional protocol, it is only ever |
| 541 | enabled on the server end of the connection. This automatically |
| 542 | enables the client to send ZMP commands. The client must never |
| 543 | attempt to negotiate ZMP directly using telnet_negotiate(). |
| 544 | |
| 545 | Once ZMP is enabled, any ZMP commands received will automatically be |
Sean Middleditch | b10946c | 2009-03-22 18:21:14 -0400 | [diff] [blame] | 546 | sent to the event handler function with the TELNET_EV_SUBNEGOTIATION |
| 547 | event code. The command will automatically be parsed and the ZMP |
| 548 | parameters will be placed in the event->argv array and the number of |
| 549 | parameters will be placed in the event->argc field. |
| 550 | |
| 551 | NOTE: if an error occured while parsing the ZMP command because it |
| 552 | was malformed, the event->argc field will be equal to 0 and the |
| 553 | event->argv field will be NULL. You should always check for this |
| 554 | before attempting to access the parameter array. |
Sean Middleditch | 1887735 | 2009-03-22 16:57:44 -0400 | [diff] [blame] | 555 | |
| 556 | To send ZMP commands to the remote end, use either telnet_send_zmp() |
| 557 | or telnet_send_zmpv(). |
| 558 | |
| 559 | int telnet_send_zmp(telnet_t *telnet, size_t argv, |
| 560 | const char **argv); |
| 561 | Sends a ZMP command to the remote end. The argc parameter is the |
| 562 | number of ZMP parameters (including the command name!) to be sent. |
| 563 | The argv parameter is an array of strings containing the |
| 564 | parameters. The element in argv[0] is the command name itself. |
| 565 | The argv array must have at least as many elements as the value |
| 566 | argc. |
| 567 | |
| 568 | VII. TELNET PROXY UTILITY |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 569 | ===================================================================== |
| 570 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 571 | The telnet-proxy utility is a small application that serves both as a |
| 572 | testbed for libtelnet and as a powerful debugging tool for TELNET |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 573 | servers and clients. |
| 574 | |
| 575 | To use telnet-proxy, you must first compile it using: |
| 576 | |
| 577 | $ make |
| 578 | |
| 579 | If you do not have zlib installed and wish to disable MCCP2 support |
| 580 | then you must first edit the Makefile and remove the -DHAVE_ZLIB and |
| 581 | the -lz from the compile flags. |
| 582 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 583 | To run telnet-proxy, you simply give it the server's host name or IP |
| 584 | address, the server's port number, and the port number that |
Sean Middleditch | d88f183 | 2009-03-15 01:06:17 -0400 | [diff] [blame] | 585 | telnet-proxy should listen on. For example, to connect to the server |
| 586 | on mud.example.com port 7800 and to listen on port 5000, run: |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 587 | |
Sean Middleditch | d88f183 | 2009-03-15 01:06:17 -0400 | [diff] [blame] | 588 | $ ./telnet-proxy mud.example.com 7800 5000 |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 589 | |
| 590 | You can then connect to the host telnet-proxy is running on (e.g. |
Sean Middleditch | d88f183 | 2009-03-15 01:06:17 -0400 | [diff] [blame] | 591 | 127.0.0.1) on port 500 and you will automatically be proxied into |
| 592 | mud.example.com. |
Sean Middleditch | 892c5f1 | 2009-03-14 13:39:07 -0400 | [diff] [blame] | 593 | |
Sean Middleditch | f65f27d | 2009-03-19 02:32:04 -0400 | [diff] [blame] | 594 | telnet-proxy will display status information about the data passing |
| 595 | through both ends of the tunnel. telnet-proxy can only support a |
| 596 | single tunnel at a time. It will continue running until an error |
| 597 | occurs or a terminating signal is sent to the proxy process. |