telnet.h
上传用户:tigerk9
上传日期:2020-03-10
资源大小:237k
文件大小:11k
源码类别:

Telnet客户端

开发平台:

Visual C++

  1. #ifndef ___TELNET_H
  2. #define ___TELNET_H
  3. /*
  4. * Copyright (c) 1983 Regents of the University of California.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms are permitted provided
  8. * that: (1) source distributions retain this entire copyright notice and
  9. * comment, and (2) distributions including binaries display the following
  10. * acknowledgement:  ``This product includes software developed by the
  11. * University of California, Berkeley and its contributors'' in the
  12. * documentation or other materials provided with the distribution and in
  13. * all advertising materials mentioning features or use of this software.
  14. * Neither the name of the University nor the names of its contributors may
  15. * be used to endorse or promote products derived from this software without
  16. * specific prior written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * @(#)telnet.h 5.12 (Berkeley) 3/5/91
  22. */
  23. // This file modified 5/15/98 by Paul Brannan.
  24. // Added (unsigned char) to the #defines.
  25. // Formatted for readability.
  26. /*
  27. * Definitions for the TELNET protocol.
  28. */
  29. #define IAC (unsigned char)255 /* interpret as command: */
  30. #define DONT (unsigned char)254 /* you are not to use option */
  31. #define DO (unsigned char)253 /* please, you use option */
  32. #define WONT (unsigned char)252 /* I won't use option */
  33. #define WILL (unsigned char)251 /* I will use option */
  34. #define SB (unsigned char)250 /* interpret as subnegotiation */
  35. #define GA (unsigned char)249 /* you may reverse the line */
  36. #define EL (unsigned char)248 /* erase the current line */
  37. #define EC (unsigned char)247 /* erase the current character */
  38. #define AYT (unsigned char)246 /* are you there */
  39. #define AO (unsigned char)245 /* abort output--but let prog finish */
  40. #define IP (unsigned char)244 /* interrupt process--permanently */
  41. #define BREAK (unsigned char)243 /* break */
  42. #define DM (unsigned char)242 /* data mark--for connect. cleaning */
  43. #define NOP (unsigned char)241 /* nop */
  44. #define SE (unsigned char)240 /* end sub negotiation */
  45. #define EOR     (unsigned char)239             /* end of record (transparent mode) */
  46. #define ABORT (unsigned char)238 /* Abort process */
  47. #define SUSP (unsigned char)237 /* Suspend process */
  48. #define xEOF (unsigned char)236 /* End of file: EOF is already used... */
  49. #define SYNCH (unsigned char)242 /* for telfunc calls */
  50. #ifdef TELCMDS
  51. char *telcmds[] = {
  52. "EOF", "SUSP", "ABORT", "EOR",
  53. "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
  54. "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0,
  55. };
  56. #else
  57. extern char *telcmds[];
  58. #endif
  59. #define TELCMD_FIRST xEOF
  60. #define TELCMD_LAST IAC
  61. #define TELCMD_OK(x) ((x) <= TELCMD_LAST && (x) >= TELCMD_FIRST)
  62. #define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
  63. /* telnet options */
  64. #define TELOPT_BINARY (unsigned char)0 /* 8-bit data path */
  65. #define TELOPT_ECHO (unsigned char)1 /* echo */
  66. #define TELOPT_RCP (unsigned char)2 /* prepare to reconnect */
  67. #define TELOPT_SGA (unsigned char)3 /* suppress go ahead */
  68. #define TELOPT_NAMS (unsigned char)4 /* approximate message size */
  69. #define TELOPT_STATUS (unsigned char)5 /* give status */
  70. #define TELOPT_TM (unsigned char)6 /* timing mark */
  71. #define TELOPT_RCTE (unsigned char)7 /* remote controlled transmission and echo */
  72. #define TELOPT_NAOL (unsigned char)8 /* negotiate about output line width */
  73. #define TELOPT_NAOP (unsigned char)9 /* negotiate about output page size */
  74. #define TELOPT_NAOCRD (unsigned char)10 /* negotiate about CR disposition */
  75. #define TELOPT_NAOHTS (unsigned char)11 /* negotiate about horizontal tabstops */
  76. #define TELOPT_NAOHTD (unsigned char)12 /* negotiate about horizontal tab disposition */
  77. #define TELOPT_NAOFFD (unsigned char)13 /* negotiate about formfeed disposition */
  78. #define TELOPT_NAOVTS (unsigned char)14 /* negotiate about vertical tab stops */
  79. #define TELOPT_NAOVTD (unsigned char)15 /* negotiate about vertical tab disposition */
  80. #define TELOPT_NAOLFD (unsigned char)16 /* negotiate about output LF disposition */
  81. #define TELOPT_XASCII (unsigned char)17 /* extended ascic character set */
  82. #define TELOPT_LOGOUT (unsigned char)18 /* force logout */
  83. #define TELOPT_BM (unsigned char)19 /* byte macro */
  84. #define TELOPT_DET (unsigned char)20 /* data entry terminal */
  85. #define TELOPT_SUPDUP (unsigned char)21 /* supdup protocol */
  86. #define TELOPT_SUPDUPOUTPUT (unsigned char)22 /* supdup output */
  87. #define TELOPT_SNDLOC (unsigned char)23 /* send location */
  88. #define TELOPT_TTYPE (unsigned char)24 /* terminal type */
  89. #define TELOPT_EOR (unsigned char)25 /* end or record */
  90. #define TELOPT_TUID (unsigned char)26 /* TACACS user identification */
  91. #define TELOPT_OUTMRK (unsigned char)27 /* output marking */
  92. #define TELOPT_TTYLOC (unsigned char)28 /* terminal location number */
  93. #define TELOPT_3270REGIME (unsigned char)29 /* 3270 regime */
  94. #define TELOPT_X3PAD (unsigned char)30 /* X.3 PAD */
  95. #define TELOPT_NAWS (unsigned char)31 /* window size */
  96. #define TELOPT_TSPEED (unsigned char)32 /* terminal speed */
  97. #define TELOPT_LFLOW (unsigned char)33 /* remote flow control */
  98. #define TELOPT_LINEMODE (unsigned char)34 /* Linemode option */
  99. #define TELOPT_XDISPLOC (unsigned char)35 /* X Display Location */
  100. #define TELOPT_ENVIRON (unsigned char)36 /* Environment variables */
  101. #define TELOPT_AUTHENTICATION (unsigned char)37 /* Authenticate */
  102. #define TELOPT_ENCRYPT (unsigned char)38 /* Encryption option */
  103. #define TELOPT_EXOPL (unsigned char)255 /* extended-options-list */
  104. #define NTELOPTS (1+TELOPT_ENCRYPT)
  105. #ifdef TELOPTS
  106. char *telopts[NTELOPTS+1] = {
  107. "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
  108. "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
  109. "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
  110. "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
  111. "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
  112. "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
  113. "TACACS UID", "OUTPUT MARKING", "TTYLOC",
  114. "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
  115. "LINEMODE", "XDISPLOC", "ENVIRON", "AUTHENTICATION",
  116. "ENCRYPT",
  117. 0,
  118. };
  119. #define TELOPT_FIRST TELOPT_BINARY
  120. #define TELOPT_LAST TELOPT_ENCRYPT
  121. #define TELOPT_OK(x) ((x) <= TELOPT_LAST && (x) >= TELOPT_FIRST)
  122. #define TELOPT(x) telopts[(x)-TELOPT_FIRST]
  123. #endif
  124. /* sub-option qualifiers */
  125. #define TELQUAL_IS (unsigned char)0 /* option is... */
  126. #define TELQUAL_SEND (unsigned char)1 /* send option */
  127. #define TELQUAL_INFO (unsigned char)2 /* ENVIRON: informational version of IS */
  128. #define TELQUAL_REPLY (unsigned char)2 /* AUTHENTICATION: client version of IS */
  129. #define TELQUAL_NAME (unsigned char)3 /* AUTHENTICATION: client version of IS */
  130. /*
  131. * LINEMODE suboptions
  132. */
  133. #define LM_MODE 1
  134. #define LM_FORWARDMASK 2
  135. #define LM_SLC 3
  136. #define MODE_EDIT 0x01
  137. #define MODE_TRAPSIG 0x02
  138. #define MODE_ACK 0x04
  139. #define MODE_SOFT_TAB 0x08
  140. #define MODE_LIT_ECHO 0x10
  141. #define MODE_MASK 0x1f
  142. /* Not part of protocol, but needed to simplify things... */
  143. #define MODE_FLOW 0x0100
  144. #define MODE_ECHO 0x0200
  145. #define MODE_INBIN 0x0400
  146. #define MODE_OUTBIN 0x0800
  147. #define MODE_FORCE 0x1000
  148. #define SLC_SYNCH 1
  149. #define SLC_BRK 2
  150. #define SLC_IP 3
  151. #define SLC_AO 4
  152. #define SLC_AYT 5
  153. #define SLC_EOR 6
  154. #define SLC_ABORT 7
  155. #define SLC_EOF 8
  156. #define SLC_SUSP 9
  157. #define SLC_EC 10
  158. #define SLC_EL 11
  159. #define SLC_EW 12
  160. #define SLC_RP 13
  161. #define SLC_LNEXT 14
  162. #define SLC_XON 15
  163. #define SLC_XOFF 16
  164. #define SLC_FORW1 17
  165. #define SLC_FORW2 18
  166. #define NSLC 18
  167. /*
  168. * For backwards compatability, we define SLC_NAMES to be the
  169. * list of names if SLC_NAMES is not defined.
  170. */
  171. #define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", 
  172. "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", 
  173. "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0,
  174. #ifdef SLC_NAMES
  175. //char *slc_names[] = {
  176. // SLC_NAMELIST
  177. //};
  178. #else
  179. extern char *slc_names[];
  180. #define SLC_NAMES SLC_NAMELIST
  181. #endif
  182. #define SLC_NAME_OK(x) ((x) >= 0 && (x) < NSLC)
  183. #define SLC_NAME(x) slc_names[x]
  184. #define SLC_NOSUPPORT 0
  185. #define SLC_CANTCHANGE 1
  186. #define SLC_VARIABLE 2
  187. #define SLC_DEFAULT 3
  188. #define SLC_LEVELBITS 0x03
  189. #define SLC_FUNC 0
  190. #define SLC_FLAGS 1
  191. #define SLC_VALUE 2
  192. #define SLC_ACK 0x80
  193. #define SLC_FLUSHIN 0x40
  194. #define SLC_FLUSHOUT 0x20
  195. #define ENV_VALUE 0
  196. #define ENV_VAR 1
  197. #define ENV_ESC 2
  198. /*
  199. * AUTHENTICATION suboptions
  200. */
  201. /*
  202. * Who is authenticating who ...
  203. */
  204. #define AUTH_WHO_CLIENT 0 /* Client authenticating server */
  205. #define AUTH_WHO_SERVER 1 /* Server authenticating client */
  206. #define AUTH_WHO_MASK 1
  207. /*
  208. * amount of authentication done
  209. */
  210. #define AUTH_HOW_ONE_WAY 0
  211. #define AUTH_HOW_MUTUAL 2
  212. #define AUTH_HOW_MASK 2
  213. #define AUTHTYPE_NULL 0
  214. #define AUTHTYPE_KERBEROS_V4 1
  215. #define AUTHTYPE_KERBEROS_V5 2
  216. #define AUTHTYPE_SPX 3
  217. #define AUTHTYPE_MINK 4
  218. #define AUTHTYPE_CNT 5
  219. #define AUTHTYPE_TEST 99
  220. #ifdef AUTH_NAMES
  221. char *authtype_names[] = {
  222. "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0,
  223. };
  224. #else
  225. extern char *authtype_names[];
  226. #endif
  227. #define AUTHTYPE_NAME_OK(x) ((x) >= 0 && (x) < AUTHTYPE_CNT)
  228. #define AUTHTYPE_NAME(x) authtype_names[x]
  229. /*
  230. * ENCRYPTion suboptions
  231. */
  232. #define ENCRYPT_IS 0 /* I pick encryption type ... */
  233. #define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
  234. #define ENCRYPT_REPLY 2 /* Initial setup response */
  235. #define ENCRYPT_START 3 /* Am starting to send encrypted */
  236. #define ENCRYPT_END 4 /* Am ending encrypted */
  237. #define ENCRYPT_REQSTART 5 /* Request you start encrypting */
  238. #define ENCRYPT_REQEND 6 /* Request you send encrypting */
  239. #define ENCRYPT_ENC_KEYID 7
  240. #define ENCRYPT_DEC_KEYID 8
  241. #define ENCRYPT_CNT 9
  242. #define ENCTYPE_ANY 0
  243. #define ENCTYPE_DES_CFB64 1
  244. #define ENCTYPE_DES_OFB64 2
  245. #define ENCTYPE_CNT 3
  246. #ifdef ENCRYPT_NAMES
  247. char *encrypt_names[] = {
  248. "IS", "SUPPORT", "REPLY", "START", "END",
  249. "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
  250. 0,
  251. };
  252. char *enctype_names[] = {
  253. "ANY", "DES_CFB64",  "DES_OFB64",  0,
  254. };
  255. #else
  256. extern char *encrypt_names[];
  257. extern char *enctype_names[];
  258. #endif
  259. #define ENCRYPT_NAME_OK(x) ((x) >= 0 && (x) < ENCRYPT_CNT)
  260. #define ENCRYPT_NAME(x) encrypt_names[x]
  261. #define ENCTYPE_NAME_OK(x) ((x) >= 0 && (x) < ENCTYPE_CNT)
  262. #define ENCTYPE_NAME(x) enctype_names[x]
  263. //////////////////////////////////////////////////////
  264. //////////////////////////////////////////////////////
  265. #endif