home *** CD-ROM | disk | FTP | other *** search
/ kermit.columbia.edu / kermit.columbia.edu.tar / kermit.columbia.edu / sredird / telnetcpcd-1.09.tar.gz / telnetcpcd-1.09.tar / telnetcpcd.h < prev    next >
C/C++ Source or Header  |  2003-08-12  |  27KB  |  827 lines

  1. /*
  2.     telnetcpcd.h
  3.  
  4.     Copyright (c) 2002,2003 Thomas J Pinkl <tom@pinkl.com>
  5.  
  6.     This is the main header file for the Telnet Com Port Control daemon.
  7.  
  8.     Version 1.00    11/30/2001        
  9.     Version 1.01    12/04/2001        Added LOCKDIR and LOCKTEMPLATE
  10.     Version 1.02    12/13/2001        Added FLOWCONTROL
  11.     Version 1.03    12/18/2001        Added the CPC_xxx symbols.
  12.     Version 1.04    01/14/2002        Added POLLINTERVAL
  13.     Version 1.05    01/25/2002        Added "netinet/in_systm.h" and CRTSCTS,
  14.                                     both for SCO.
  15.     Version 1.06    01/30/2002        Added "sys/termiox.h" for AIX.  Added 
  16.                                     the "mytermios" structure.
  17.     Version 1.07    02/18/2002        Let debugging output go to syslog too.
  18.     Version 1.08    02/22/2002        Changed POLLINTERVAL to MS_POLLINTERVAL 
  19.                                     and added LS_POLLINTERVAL.
  20.     Version 1.09    03/06/2002        Added REPLYPURGEDATA
  21.     Version 1.10    04/22/2002        Updated check_modemstate() prototype.
  22.     Version 1.11    04/24/2002        Added CONNFLUSH and DISCFLUSH.  Removed 
  23.                                     TRACKCARRIER.
  24.     Version 1.12    04/30/2002        Added conditional code around USE_DIGI_TIOCM
  25.                                     which includes <sys/digi.h>.  This is 
  26.                                     intended to be used on SCO OSR5.  NOTE: this
  27.                                     doesn't work; we still cannot read the CD 
  28.                                     signal on OSR5.
  29.     Version 1.13    10/24/2002        Added IDLETIMER.
  30.     Version 1.14    11/25/2002        Added function prototype for msleep().
  31.     Version 1.15    12/03/2002        Added SENDLOGOUT.
  32.     Version 1.16    12/12/2002        Added external globals: noquote, useconds
  33.     Version 1.17    02/05/2003        Changed the default TCP port to the one 
  34.                                     assigned by IANA, 3696.
  35. */
  36.  
  37. #ifndef _TELNETCPCD_H                /* prevent multiple inclusions */
  38. #define _TELNETCPCD_H
  39.  
  40. #ifndef TELNETCPCD_SERVER_TCP_PORT
  41. #define TELNETCPCD_SERVER_TCP_PORT    3696    /* port 3696 was assigned by IANA */
  42. #endif
  43.  
  44. #ifndef SYSLOG_FACILITY
  45. #define SYSLOG_FACILITY        LOG_DAEMON
  46. #endif
  47.  
  48. #include <stdio.h>
  49. #include <unistd.h>
  50. #include <stdlib.h>
  51. #include <sys/types.h>
  52. #include <sys/wait.h>
  53. #include <string.h>
  54. #include <strings.h>
  55. #include <ctype.h>
  56. #include <errno.h>
  57. #include <fcntl.h>
  58. #include <sys/ioctl.h>
  59. #include <memory.h>
  60.  
  61. /*
  62.     on SCO OpenServer 5.0.[45] (and, I assume, later), the _SVID3 
  63.     symbol must be defined in order for TIOCMGET to be defined 
  64.     in <sys/termio.h>.  TIOCMGET is an ioctl command to read modem 
  65.     signals.
  66.  
  67.     tjp, 04/30/2002 - SCO's TIOCMGET doesn't return Carrier Detect.
  68.                       this may have been fixed in 5.0.6a.
  69. */
  70. #ifdef OSR5
  71. #ifndef _SVID3
  72. #define _SVID3
  73. #endif
  74. #endif
  75.  
  76. /*
  77.     AIX uses the termiox interface for hardware flow control
  78. */
  79. #ifdef AIX
  80. #define USE_TERMIOX
  81. #endif
  82.  
  83. #include <termios.h>
  84. #ifdef USE_TERMIOX
  85. #include <sys/termiox.h>
  86. #endif
  87.  
  88. /*
  89.     USE_DIGI_TIOCM was added in an attempt to get SCO OSR5 to read 
  90.     the CD modem signal.  it didn't work.
  91. */
  92. #ifdef USE_DIGI_TIOCM        /* Digiboard specific TIOCMGET/TIOCMSET */
  93. #undef TIOCM_LE
  94. #undef TIOCM_SR
  95. #undef TIOCM_ST
  96. #undef TIOCM_DTR
  97. #undef TIOCM_RTS
  98. #undef TIOCM_CTS
  99. #undef TIOCM_DSR
  100. #undef TIOCM_CAR
  101. #undef TIOCM_RNG
  102. #undef TIOCM_CD
  103. #undef TIOCM_RI
  104. #undef TIOCMGET
  105. #undef TIOCMSET
  106. #undef TIOCMBIC
  107. #undef TIOCMBIS
  108. #undef TIOCMODG
  109. #undef TIOCSDTR
  110. #include <sys/digi.h>
  111. #endif    /* USE_DIGI_TIOCM */
  112.  
  113. #include <pwd.h>
  114. #include <grp.h>
  115. #include <sys/socket.h>
  116. #include <netinet/in_systm.h>
  117. #include <netinet/in.h>
  118. #include <netinet/tcp.h>
  119. #include <netinet/udp.h>
  120. #include <arpa/inet.h>
  121. #include <arpa/telnet.h>
  122. #include <arpa/ftp.h>
  123. #include <netdb.h>
  124. #include <syslog.h>
  125. #include <stdarg.h>
  126. #include <signal.h>
  127. #include <time.h>
  128. #include <search.h>            /* hash table functions */
  129. #include <sys/time.h>        /* for 'struct timeval' */
  130. #include <sys/param.h>
  131. #include <sys/file.h>
  132. #include <sys/stat.h>
  133. #include <sys/ipc.h>
  134. #include <sys/sem.h>
  135.  
  136. #ifdef M_UNIX                /* SCO Unix keeps 'struct winsize' here */
  137. #include <sys/stream.h>
  138. #include <sys/ptem.h>
  139. #endif /* M_UNIX */
  140.  
  141. #ifdef SVR4
  142. #include <sys/stream.h>
  143. #endif    /* SVR4 */
  144. #if defined(M_UNIX) || defined(AIX) || defined(SVR4)
  145. #include <sys/stropts.h>
  146. #endif
  147. #ifndef __linux__
  148. #include <sys/select.h>
  149. #endif /* ! __linux__ */
  150. #ifdef __linux__
  151. #include <sys/time.h>
  152. #endif /* __linux__ */
  153.  
  154. /* for major() and minor */
  155. #ifdef SVR4
  156. #include <sys/mkdev.h>
  157. #else
  158. #include <sys/sysmacros.h>
  159. #endif
  160.  
  161. #ifndef __linux__
  162. extern int errno;
  163. extern int sys_nerr;
  164. extern char *sys_errlist[];
  165. #endif /* ! __linux__ */
  166.  
  167. #ifdef M_UNIX
  168. #ifndef CRTSCTS
  169. #define CRTSCTS    (RTSFLOW|CTSFLOW)
  170. #endif
  171. #endif
  172.  
  173. #ifndef MIN
  174. #define MIN(x,y) (x) > (y) ? (y) : (x)
  175. #endif
  176.  
  177. #ifndef MAX
  178. #define MAX(x,y) (x) > (y) ? (x) : (y)
  179. #endif
  180.  
  181. #define BLOCKING    0x01            /* second arg to create_server_socket() */
  182. #define NONBLOCKING    0x00
  183.  
  184. #ifdef __osf__
  185.     #define ARGV_TYPE        char ** const
  186. #else
  187.     #ifdef M_UNIX
  188.         #define ARGV_TYPE        char **
  189.     #else
  190.         #ifdef __linux__
  191.             #define ARGV_TYPE        char * const *
  192.         #else
  193.             #ifdef AIX
  194.                 #define ARGV_TYPE        char * const *
  195.             #else
  196.                 #define ARGV_TYPE        const char **
  197.             #endif    /* AIX */
  198.         #endif    /* __linux__ */
  199.     #endif    /* M_UNIX */
  200. #endif    /* __osf__ */
  201. #define GETOPT_CAST        ARGV_TYPE
  202.  
  203. /*
  204.     debugging levels
  205. */
  206. #define DBG_ERR            0
  207. #define DBG_INF            3
  208. #define DBG_VINF        6
  209. #define DBG_MEM            7
  210. #define DBG_LV0            0
  211. #define DBG_LV1            1
  212. #define DBG_LV2            2
  213. #define DBG_LV3            3
  214. #define DBG_LV4            4
  215. #define DBG_LV5            5
  216. #define DBG_LV6            6
  217. #define DBG_LV7            7
  218. #define DBG_LV8            8
  219. #define DBG_LV9            9
  220.  
  221. /*
  222.     defaults for uucp locking
  223. */
  224. #define ASCIIPID
  225. #ifdef AIX
  226. #define UUCPLOCK_DIR    "/etc/locks"
  227. #define UUCPLOCK_TMPL    "LCK..%s"
  228. #endif
  229. #ifdef __linux__
  230. #define UUCPLOCK_DIR    "/var/lock"
  231. #define UUCPLOCK_TMPL    "LCK..%s"
  232. #endif
  233. #ifdef SVR4
  234. #define UUCPLOCK_DIR    "/var/spool/locks"
  235. #define UUCPLOCK_TMPL    "LK.%03u.%03u.%03u"
  236. #endif
  237. #ifndef UUCPLOCK_DIR
  238. #define UUCPLOCK_DIR    "/usr/spool/uucp"
  239. #define UUCPLOCK_TMPL    "LCK..%s"
  240. #endif
  241.  
  242. #ifndef PATH_MAX
  243. #define PATH_MAX        255
  244. #endif
  245.  
  246. /*
  247.     symbols for shutdown(2) call
  248. */
  249. #ifndef SHUT_RD
  250. #define SHUT_RD        0x00
  251. #define SHUT_WR        0x01
  252. #define SHUT_RDWR    0x02
  253. #endif
  254.  
  255. /* max # modems */
  256. #define MAX_MODEMS    256
  257.  
  258. /*
  259.     structure to keep track of info on serial devices
  260. */
  261. struct serial_info_t {
  262.     char *device;                /* path name of device */
  263.     char *lockfile;                /* path name of lock file */
  264.     char *description;            /* device description */
  265.     unsigned long speed;        /* baud rate */
  266.     unsigned int databits;        /* data bits */
  267.     unsigned int parity;        /* parity */
  268.     unsigned int stopbits;        /* stop bits (NOT USED) */
  269.     unsigned int flowcontrol;    /* flow control */
  270.     int conn_flush;                /* flush device on connect? */
  271.     int disc_flush;                /* flush device on disconnect? */
  272.     int busy;                    /* modem already in use */
  273. };
  274.  
  275. typedef struct serial_info_t SERIAL_INFO;
  276.  
  277. /*
  278.     terminal control structure
  279. */
  280. struct mytermios_t {
  281.     struct termios ts;
  282. #ifdef USE_TERMIOX
  283.     struct termiox tx;
  284. #endif
  285. };
  286.  
  287. typedef struct mytermios_t MYTERMIOS;
  288.  
  289. /*
  290.     configuration info
  291. */
  292. #define HAVE_CONFIG_T
  293. struct config_t {
  294.     char *directory;                /* directory name */
  295.     char *tmpdir;                    /* tmp directory name */
  296.     char *debuglog;                    /* name of debug log */
  297.     int debuglevel;                    /* level of debugging output */
  298.     char *pidfile;                    /* name of pid file */
  299.     int timeout;                    /* connection timeout in seconds */
  300.     char *user;                        /* user name */
  301.     char *group;                    /* group name */
  302.     uid_t uid;                        /* user id (looked up via user name) */
  303.     gid_t gid;                        /* group id (looked up via group name) */
  304.     char *servertype;                /* server type: concurrent or iterative */
  305.     char *lockdir;                    /* directory for uucp lock files */
  306.     char *locktemplate;                /* filename template for uucp lock files */
  307.     int ms_pollinterval;            /* polling interval in seconds for modemstate changes */
  308.     int ls_pollinterval;            /* polling interval in seconds for linestate changes */
  309.     int reply_purge_data;            /* reply to Purge Data commands? */
  310.     int idletimer;                    /* idle timer */
  311.     int send_logout;                /* send Telnet LOGOUT command? */
  312.     int nmodems;                    /* number of modems */
  313.     SERIAL_INFO *modems[MAX_MODEMS]; /* array of ptrs to SERIAL_INFO's */
  314. };
  315.  
  316. /*
  317.     telnet options 
  318. */
  319. struct telnet_options_t {
  320.     int sent_will:1;
  321.     int sent_do:1;
  322.     int sent_wont:1;
  323.     int sent_dont:1;
  324.     int server:1;
  325.     int client:1;
  326. };
  327.  
  328. typedef struct telnet_options_t TELNET_OPTIONS;
  329.  
  330. #define MAX_TELNET_OPTIONS            256
  331. #define MAX_TELNET_CPC_COMMAND_LEN    256
  332.  
  333. /*
  334.     telnet mode: ASCII or Binary
  335. */
  336. #define ASCII    0x00
  337. #define BINARY    0x01
  338.  
  339. /*
  340.     session state: Suspend or Resume
  341. */
  342. #define SUSPEND    0x00
  343. #define RESUME    0x01
  344.  
  345. /*
  346.     carrier detect state
  347. */
  348. #define NO_CARRIER        0x00
  349. #define GOT_CARRIER        0x01
  350. #define LOST_CARRIER    0x02
  351.  
  352. /*
  353.     Telnet Com Port Control (CPC) option values (from rfc2217)
  354. */
  355. #ifndef TELOPT_COM_PORT_OPTION
  356. #define TELOPT_COM_PORT_OPTION        44
  357. #endif
  358. #ifndef TELOPT_KERMIT
  359. #define TELOPT_KERMIT                47
  360. #endif
  361. #define CPC_SIGNATURE_C2S            0        /* C2S = client to server */
  362. #define CPC_SIGNATURE_S2C            100        /* S2C = server to client */
  363. #define CPC_SET_BAUDRATE_C2S        1
  364. #define CPC_SET_BAUDRATE_S2C        101
  365. #define CPC_SET_DATASIZE_C2S        2
  366. #define CPC_SET_DATASIZE_S2C        102
  367. #define CPC_SET_PARITY_C2S            3
  368. #define CPC_SET_PARITY_S2C            103
  369. #define CPC_SET_STOPSIZE_C2S        4
  370. #define CPC_SET_STOPSIZE_S2C        104
  371. #define CPC_SET_CONTROL_C2S            5
  372. #define CPC_SET_CONTROL_S2C            105
  373. #define CPC_NOTIFY_LINESTATE_C2S    6
  374. #define CPC_NOTIFY_LINESTATE_S2C    106
  375. #define CPC_NOTIFY_MODEMSTATE_C2S    7
  376. #define CPC_NOTIFY_MODEMSTATE_S2C    107
  377. #define CPC_FLOWCONTROL_SUSPEND_C2S    8
  378. #define CPC_FLOWCONTROL_SUSPEND_S2C    108
  379. #define CPC_FLOWCONTROL_RESUME_C2S    9
  380. #define CPC_FLOWCONTROL_RESUME_S2C    109
  381. #define CPC_SET_LINESTATE_MASK_C2S    10
  382. #define CPC_SET_LINESTATE_MASK_S2C    110
  383. #define CPC_SET_MODEMSTATE_MASK_C2S    11
  384. #define CPC_SET_MODEMSTATE_MASK_S2C    111
  385. #define CPC_PURGE_DATA_C2S            12
  386. #define CPC_PURGE_DATA_S2C            112
  387.  
  388. #define CPC_DATASIZE_QUERY            0
  389. #define CPC_DATASIZE_CS5            5
  390. #define CPC_DATASIZE_CS6            6
  391. #define CPC_DATASIZE_CS7            7
  392. #define CPC_DATASIZE_CS8            8
  393.  
  394. #define CPC_PARITY_QUERY            0
  395. #define CPC_PARITY_NONE                1
  396. #define CPC_PARITY_ODD                2
  397. #define CPC_PARITY_EVEN                3
  398. #define CPC_PARITY_MARK                4
  399. #define CPC_PARITY_SPACE            5
  400.  
  401. #define CPC_STOPSIZE_QUERY            0
  402. #define CPC_STOPSIZE_1BIT            1
  403. #define CPC_STOPSIZE_2BITS            2
  404. #define CPC_STOPSIZE_15BITS            3
  405.  
  406. #define CPC_SET_CONTROL_FLOW_QUERY        0
  407. #define CPC_SET_CONTROL_FLOW_NONE        1
  408. #define CPC_SET_CONTROL_FLOW_XONXOFF    2
  409. #define CPC_SET_CONTROL_FLOW_HARDWARE    3
  410. #define CPC_SET_CONTROL_BREAK_QUERY        4
  411. #define CPC_SET_CONTROL_BREAK_ON        5
  412. #define CPC_SET_CONTROL_BREAK_OFF        6
  413. #define CPC_SET_CONTROL_DTR_QUERY        7
  414. #define CPC_SET_CONTROL_DTR_ON            8
  415. #define CPC_SET_CONTROL_DTR_OFF            9
  416. #define CPC_SET_CONTROL_RTS_QUERY        10
  417. #define CPC_SET_CONTROL_RTS_ON            11
  418. #define CPC_SET_CONTROL_RTS_OFF            12
  419. #define CPC_SET_CONTROL_INFLOW_QUERY    13
  420. #define CPC_SET_CONTROL_INFLOW_NONE        14
  421. #define CPC_SET_CONTROL_INFLOW_XONXOFF    15
  422. #define CPC_SET_CONTROL_INFLOW_HARDWARE    16
  423. #define CPC_SET_CONTROL_FLOW_DCD        17
  424. #define CPC_SET_CONTROL_INFLOW_DTR        18
  425. #define CPC_SET_CONTROL_FLOW_DSR        19
  426.  
  427. #define CPC_LINESTATE_TIMEOUT_ERROR        0x80
  428. #define CPC_LINESTATE_TSR_EMPTY            0x40
  429. #define CPC_LINESTATE_THR_EMPTY            0x20
  430. #define CPC_LINESTATE_BREAK_DETECT        0x10
  431. #define CPC_LINESTATE_FRAMING_ERROR        0x08
  432. #define CPC_LINESTATE_PARITY_ERROR        0x04
  433. #define CPC_LINESTATE_OVERRUN_ERROR        0x02
  434. #define CPC_LINESTATE_DATA_READY        0x01
  435.  
  436. #define CPC_MODEMSTATE_CD                0x80
  437. #define CPC_MODEMSTATE_RI                0x40
  438. #define CPC_MODEMSTATE_DSR                0x20
  439. #define CPC_MODEMSTATE_CTS                0x10
  440. #define CPC_MODEMSTATE_DELTA_CD            0x08
  441. #define CPC_MODEMSTATE_TRLEDGE_RI        0x04
  442. #define CPC_MODEMSTATE_DELTA_DSR        0x02
  443. #define CPC_MODEMSTATE_DELTA_CTS        0x01
  444.  
  445. #define CPC_PURGEDATA_RECVBUFF            1
  446. #define CPC_PURGEDATA_XMITBUFF            2
  447. #define CPC_PURGEDATA_BOTH                3
  448.  
  449. struct buffer_t {
  450.     int size;                        /* buffer size */
  451.     int nbuffered;                    /* bytes in buffer */
  452.     int eof;                        /* read() eof flag */
  453.     unsigned char *label;            /* name of buffer */
  454.     unsigned char *buffp;            /* ptr to buffer */
  455.     unsigned char *tailp;            /* ptr past end of buffer */
  456.     unsigned char *readp;            /* read ptr */
  457.     unsigned char *writep;            /* write ptr */
  458. };
  459.  
  460. typedef struct buffer_t BUFFER;
  461.  
  462. /*
  463.     token types.  keep these values unique!
  464.  
  465.     when adding a token type, please modify the tokentype2str() 
  466.     function in config.c
  467. */
  468. #define LONGVALUE        -5
  469. #define BOOLEAN            -4
  470. #define PRINTFSTRING    -3
  471. #define STRING            -2
  472. #define VALUE            -1
  473.  
  474. /*
  475.     token values.  keep these values unique!  they don't really need 
  476.     to be bit masks.
  477.  
  478.     these are used while parsing the config file.  see also kw_table[].
  479. */
  480. #define UNKNOWN            0x00000001        /* keyword is unknown */
  481. #define INVALID            0x00000002        /* missing/invalid value for keyword */
  482. #define COMMENT            0x00000004
  483. #define BLANKLINE        0x00000008
  484. #define DEBUGLOG        0x00000010
  485. #define DEBUGLEVEL        0x00000020
  486. #define DIRECTORY        0x00000040
  487. #define TMPDIR            0x00000080
  488. #define PIDFILE            0x00000100
  489. #define TIMEOUT            0x00000200
  490. #define SERVERTYPE        0x00000400
  491. #define USERNAME        0x00000800
  492. #define GROUP            0x00001000
  493. #define LOCKDIR            0x00002000
  494. #define LOCKTEMPLATE    0x00004000
  495. #define DEVICE            0x00008000
  496. #define SPEED            0x00010000
  497. #define DATABITS        0x00020000
  498. #define PARITY            0x00040000
  499. #define STOPBITS        0x00080000
  500. #define FLOWCONTROL        0x00100000
  501. #define MS_POLLINTERVAL    0x00200000
  502. #define LS_POLLINTERVAL    0x00400000
  503. #define DESCRIPTION        0x00800000
  504. #define REPLYPURGEDATA    0x01000000
  505. #define CONNFLUSH        0x02000000
  506. #define DISCFLUSH        0x04000000
  507. #define IDLETIMER        0x08000000
  508. #define SENDLOGOUT        0x10000000
  509.  
  510. /*
  511.     parity symbols
  512. */
  513. #define PARITY_NONE        0x00
  514. #define PARITY_ODD        0x01
  515. #define PARITY_EVEN        0x02
  516.  
  517. /*
  518.     flow control symbols
  519. */
  520. #define HARDWARE_FLOW    0x04
  521. #define SOFTWARE_FLOW    0x08
  522. #define NO_FLOWCONTROL    0x10
  523.  
  524. /*
  525.     the sizes of various things ... 
  526. */
  527. #define SZ_BUFFER        4096            /* buffer size */
  528. #define SZ_KEYWORD        64                /* config file keyword */
  529.  
  530. /*
  531.     the config file keyword table
  532. */
  533. struct cf_entry {
  534.     char name[SZ_KEYWORD];
  535.     unsigned long token;
  536.     int type;
  537.     char *value;
  538. };
  539. #ifdef INIT_KEYWORDS
  540. struct cf_entry kw_table[] = {
  541.     {"directory",                    DIRECTORY,        STRING,            NULL},
  542.     {"tmp directory",                TMPDIR,            STRING,            NULL},
  543.     {"lock directory",                LOCKDIR,        STRING,            NULL},
  544.     {"lock template",                LOCKTEMPLATE,    STRING,            NULL},
  545.     {"debug log",                    DEBUGLOG,        STRING,            NULL},    
  546.     {"debug level",                    DEBUGLEVEL,        VALUE,            NULL},
  547.     {"pid file",                    PIDFILE,        STRING,            NULL},    
  548.     {"timeout",                        TIMEOUT,        VALUE,            NULL},
  549.     {"user",                        USERNAME,        STRING,            NULL},
  550.     {"username",                    USERNAME,        STRING,            NULL},
  551.     {"group",                        GROUP,            STRING,            NULL},
  552.     {"server type",                    SERVERTYPE,        STRING,            NULL},
  553.     {"modem",                        DEVICE,            STRING,            NULL},
  554.     {"device",                        DEVICE,            STRING,            NULL},
  555.     {"port",                        DEVICE,            STRING,            NULL},
  556.     {"speed",                        SPEED,            LONGVALUE,        NULL},
  557.     {"baudrate",                    SPEED,            LONGVALUE,        NULL},
  558.     {"databits",                    DATABITS,        VALUE,            NULL},
  559.     {"parity",                        PARITY,            STRING,            NULL},
  560.     {"stopbits",                    STOPBITS,        VALUE,            NULL},
  561.     {"flow control",                FLOWCONTROL,    STRING,            NULL},
  562.     {"modemstate poll interval",    MS_POLLINTERVAL,VALUE,            NULL},
  563.     {"linestate poll interval",        LS_POLLINTERVAL,VALUE,            NULL},
  564.     {"description",                    DESCRIPTION,    STRING,            NULL},
  565.     {"reply Purge Data",            REPLYPURGEDATA,    BOOLEAN,        NULL},
  566.     {"flush on connect",            CONNFLUSH,        BOOLEAN,        NULL},
  567.     {"flush on disconnect",            DISCFLUSH,        BOOLEAN,        NULL},
  568.     {"idle timer",                    IDLETIMER,        VALUE,            NULL},
  569.     {"send Telnet LOGOUT",            SENDLOGOUT,        BOOLEAN,        NULL},
  570.     {"",                            UNKNOWN,        STRING,            NULL}    /* this entry must be last */
  571. };
  572. #else
  573. extern struct cf_entry kw_table[];
  574. #endif
  575.  
  576. /*
  577.     global data references
  578. */
  579. extern char *progname;
  580. extern int tcp_port;
  581. extern int signo;
  582. extern struct config_t conf;
  583. extern int noquote;
  584. extern int useconds;
  585.  
  586. /*
  587.     functions in telnetcpcd.c
  588. */
  589. extern void telnetcpcd_init(void);
  590. extern void telnetcpcd_cleanup(void);
  591. /*
  592.     functions in config.c
  593. */
  594. extern int read_config_file(char *,struct config_t *);
  595. extern char *skip_white_space(char *);
  596. extern int kw_init(struct cf_entry kw_table[]);
  597. extern void kw_done(void);
  598. extern unsigned long parse_entry(char *buffer,struct cf_entry *cf);
  599. extern char *tokentype2str(int tokentype);
  600. extern void lowercase(char *str);
  601. extern int save_value(char *value,int type,void *target);
  602. extern int booleantoi(char *value);
  603. extern int valid_baudrate(unsigned long speed);
  604. /*
  605.     functions in signals.c
  606. */
  607. extern void install_signal_handlers(void);
  608. extern void record_parent_signal(int sig);
  609. extern void parent_sighandler(int sig);
  610. extern void sigterm(int);
  611. extern void sighup(int);
  612. extern void sigchild(int);
  613. extern void sigpipe(int);
  614. extern void sigusr1(int);
  615. extern void sigusr2(int);
  616. extern void sigalarm(int);
  617. extern unsigned int set_alarm(int);
  618. extern unsigned int cancel_alarm(int);
  619. extern int alarm_occurred(void);
  620. /*
  621.     functions in server.c
  622. */
  623. extern void server(int);
  624. extern void child_sighandler(int);
  625. extern void handle_pending_signal(void);
  626. extern int get_pending_signal(void);
  627. /*
  628.     functions in uucplocks.c
  629. */
  630. extern char *uucp_lock(char *device,pid_t pid);
  631. extern char *uucp_tmp_filename(pid_t pid);
  632. extern char *uucp_lock_filename(char *device);
  633. extern char *uucp_lock_template(void);
  634. extern int uucp_unlock(char *device);
  635. extern int uucp_verify_lock(char *path,pid_t *ret_pid);
  636. extern int write_pidfile(char *path,int flags,mode_t mode,pid_t pid);
  637. extern void uulog(int level,char *fmt, ...);
  638. /*
  639.     functions in mybasename.c
  640. */
  641. extern char *mybasename(char *path);
  642. /*
  643.     functions in mystrchr.c
  644. */
  645. extern unsigned char *mystrchr(unsigned char *s,int ch,int size);
  646. /*
  647.     functions in buffer.c
  648. */
  649. extern struct buffer_t *bfmalloc(char *label,int size);
  650. extern void bffree(struct buffer_t *buff);
  651. extern int bfread(int fd,struct buffer_t *buff);
  652. extern int bfwrite(int fd,struct buffer_t *buff);
  653. extern int bfeof(struct buffer_t *buff);
  654. extern int bfamount(struct buffer_t *buff);
  655. extern unsigned char *bfpeek(struct buffer_t *buff,int *amount);
  656. extern int bfsize(struct buffer_t *buff);
  657. extern unsigned char *bflabel(struct buffer_t *buff);
  658. extern int bfflush(int fd,struct buffer_t *buff);
  659. extern void bfclear(struct buffer_t *buff);
  660. extern int bfstrcat(struct buffer_t *buff,unsigned char *str);
  661. extern int bfstrncat(struct buffer_t *buff,unsigned char *str,int nbytes);
  662. extern int bfaddch(struct buffer_t *buff,unsigned char ch);
  663. extern unsigned char *bfstrstr(struct buffer_t *buff,unsigned char *str);
  664. extern unsigned char *bfstrchr(struct buffer_t *buff,unsigned char ch);
  665. extern int bfinsch(struct buffer_t *buff,unsigned char *ptr,unsigned char ch);
  666. extern int bfrmstr(struct buffer_t *buff,unsigned char *ptr,int nbytes);
  667. extern void bfdump(struct buffer_t *buff,int verbose);
  668. /*
  669.     functions in debug.c
  670. */
  671. extern FILE *open_debug(char *file,int level,char *program);
  672. extern void close_debug(void);
  673. extern int get_debug_level(void);
  674. extern void set_debug_level(int new_level);
  675. extern FILE *get_debugfp(void);
  676. extern void debug(int level,char *fmt, ...);
  677. extern void debug_perror(char *str);
  678. /*
  679.     functions in mydaemon.c
  680. */
  681. extern void mydaemon(int ignsigcld,char *directory);
  682. extern void daemon_start(int ignsigcld);
  683. extern void reopen_stdfds(void);
  684. extern void reopen_fd(char *file,int mode);
  685. extern void reopen_FILE(char *file,char *mode,FILE *stream);
  686. extern void close_all_fds(int begin);
  687. /*
  688.     functions in esprintf.c
  689. */
  690. extern int esprintf(char *s,char *efmt, ...);
  691. extern char *escstrcpy(char *s1,char *s2);
  692. extern int octal_esc(char *s,int *len);
  693. extern int hex_esc(char *s,int *len);
  694. extern int char_esc(int c);
  695. /*
  696.     functions in memdump.c
  697. */
  698. extern void memdump(char *buf,int len,FILE *stream);
  699. extern char *slinedump(char *str,char *buf,int len);
  700. /*
  701.     functions in signame.c
  702. */
  703. extern char *signame(int sig);
  704. /*
  705.     functions in sockets.c
  706. */
  707. extern int attach_client_socket(char *hostname,int tcp_port);
  708. extern char *getinetaddr(char *hostname);
  709. extern void detach_client_socket(int sockfd);
  710. extern int create_server_socket(int tcp_port,int nonblock);
  711. extern int nonblocking(int sockfd);
  712. extern void concurrent_server(int sockfd,int (*funct)(int),int *signo,void (*sighandler)(int));
  713. extern void iterative_server(int sockfd,int (*funct)(int),int *signo,void (*sighandler)(int));
  714. extern int accept_server_connect(int sockfd);
  715. #ifdef USE_TCP_WRAPPERS
  716. extern int access_control(int sockfd);
  717. #endif
  718. /*
  719.     functions in syslog_perror.c
  720. */
  721. extern void syslog_perror(char *str);
  722. /*
  723.     functions in timestamp.c
  724. */
  725. extern char *timestamp(void);
  726. extern char *timestamp_ms(void);
  727. /*
  728.     functions in wait_child.c
  729. */
  730. extern pid_t wait_child(pid_t pid,int *statloc);
  731. extern void log_termination_status(pid_t pid,int status);
  732. /*
  733.     functions in trimz.c
  734. */
  735. extern char *trimz(char *str);
  736. /*
  737.     functions in rfc2217.c
  738. */
  739. extern int rfc2217(int sockfd);
  740. extern int rfc2217_proc(int sockfd,int modemfd,MYTERMIOS *newterm,SERIAL_INFO *modem);
  741. extern void rfc2217_sigint(void);
  742. extern int read_socket(int sockfd,int modemfd,BUFFER *skt2mdm,BUFFER *cpc2skt);
  743. extern int write_modem(int modemfd,BUFFER *skt2mdm);
  744. extern int read_modem(int modemfd,BUFFER *mdm2skt);
  745. extern int write_socket(int sockfd,BUFFER *mdm2skt);
  746. extern SERIAL_INFO *serial_init(int *fd,MYTERMIOS *oldterm,MYTERMIOS *newterm);
  747. extern int serial_init_termios(SERIAL_INFO *v,int *fd,MYTERMIOS *oldterm,MYTERMIOS *newterm);
  748. extern void serial_cleanup(SERIAL_INFO *v,int *fd,MYTERMIOS *oldterm,MYTERMIOS *newterm);
  749. extern speed_t ulong2speed_t(unsigned long s);
  750. extern unsigned long speed_t2ulong(speed_t s);
  751. extern unsigned long uint2cs(unsigned int dbits);
  752. extern unsigned int cs2uint(unsigned long cs);
  753. extern char *cs2str(unsigned long cs);
  754. extern char *telnet_cpc_datasize2str(unsigned char datasize);
  755. extern int network_init(int sockfd,int blockopt);
  756. extern int telnet_init(int sockfd,BUFFER *cpc2skt);
  757. extern int send_telnet_option(int sockfd,BUFFER *cpc2skt,unsigned char optcode,unsigned char option);
  758. extern int send_telnet_cpc_suboption(int sockfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned char *command,int cmdlen);
  759. extern int telnet_option_was_sent(unsigned char optcode,unsigned char option);
  760. extern void mark_telnet_option_as_sent(unsigned char optcode,unsigned char option);
  761. extern void mark_telnet_option_as_not_sent(unsigned char optcode,unsigned char option);
  762. extern void enable_telnet_server_option(unsigned char option);
  763. extern void disable_telnet_server_option(unsigned char option);
  764. extern void enable_telnet_client_option(unsigned char option);
  765. extern void disable_telnet_client_option(unsigned char option);
  766. extern int telnet_server_option_is_enabled(unsigned char option);
  767. extern int telnet_client_option_is_enabled(unsigned char option);
  768. extern int telnet_server_option_is_disabled(unsigned char option);
  769. extern int telnet_client_option_is_disabled(unsigned char option);
  770. extern void process_telnet_options(int sockfd,int modemfd,BUFFER *skt2mdm,BUFFER *cpc2skt);
  771. extern int respond_telnet_option(int sockfd,BUFFER *cpc2skt,unsigned char optcode,unsigned char option);
  772. extern int respond_known_telnet_option(int sockfd,BUFFER *cpc2skt,unsigned char optcode,unsigned char option);
  773. extern int respond_telnet_binary_option(int sockfd,BUFFER *cpc2skt,unsigned char optcode,unsigned char option);
  774. extern int process_telnet_cpc_suboption(int sockfd,int modemfd,BUFFER *skt2mdm,BUFFER *cpc2skt,unsigned char *optstr,int optlen);
  775. extern int respond_telnet_cpc_signature_subopt(int sockfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned char *command,int cmdlen);
  776. extern int respond_telnet_cpc_baudrate_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  777. extern unsigned long get_baudrate(int modemfd);
  778. extern int set_baudrate(int modemfd,unsigned long value);
  779. extern int respond_telnet_cpc_datasize_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  780. extern unsigned char get_datasize(int modemfd);
  781. extern int set_datasize(int modemfd,unsigned long value);
  782. extern int respond_telnet_cpc_parity_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  783. extern unsigned char get_parity(int modemfd);
  784. extern int set_parity(int modemfd,unsigned long value);
  785. extern int respond_telnet_cpc_stopsize_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  786. extern unsigned char get_stopsize(int modemfd);
  787. extern int set_stopsize(int modemfd,unsigned long value);
  788. extern int respond_telnet_cpc_control_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  789. extern int respond_telnet_cpc_control_break_subopt(int sockfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  790. extern int respond_telnet_cpc_control_dtr_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  791. extern int respond_telnet_cpc_control_rts_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  792. extern unsigned char get_flowcontrol(int modemfd);
  793. extern int set_flowcontrol(int modemfd,unsigned long value);
  794. extern unsigned int get_modem_signals(int modemfd);
  795. extern int set_modem_signals(int modemfd,unsigned long value);
  796. extern void advise_client_of_state_changes(int sockfd,int modemfd,BUFFER *cpc2skt);
  797. extern unsigned char check_modemstate(int modemfd,int query);
  798. extern int check_carrier_state(int modemfd);
  799. extern int respond_telnet_cpc_linestate_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  800. extern int respond_telnet_cpc_modemstate_subopt(int sockfd,int modemfd,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  801. extern int respond_telnet_cpc_purge_data_subopt(int sockfd,int modemfd,BUFFER *skt2mdm,BUFFER *cpc2skt,unsigned char suboptcode,unsigned long value);
  802. extern char *telnet_optcode2str(unsigned char optcode);
  803. extern char *telnet_option2str(unsigned char option);
  804. extern char *telnet_cpc_subopt2str(unsigned char suboptcode);
  805. extern char *telnet_cpc_parity2str(unsigned char optcode);
  806. extern char *telnet_cpc_stopsize2str(unsigned char optcode);
  807. extern char *telnet_cpc_modemstate2str(unsigned char modemstate);
  808. extern char *telnet_cpc_linestate2str(unsigned char linestate);
  809. extern char *telnet_cpc_flowcontrol2str(unsigned char optcode);
  810. extern void escape_iac_chars(BUFFER *mdm2skt);
  811. extern void telnet_cpc_log_subopt(char *prefix,unsigned char suboptcode,unsigned long value,unsigned char *command,int cmdlen);
  812. /*
  813.     functions in modems.c
  814. */
  815. extern int add_modem(struct config_t *conf,char *device);
  816. extern SERIAL_INFO *alloc_modem(void);
  817. extern void free_modem(SERIAL_INFO *v);
  818. extern void free_all_modems(SERIAL_INFO *v[]);
  819. extern SERIAL_INFO *select_modem(struct config_t *conf);
  820. extern int release_modem(SERIAL_INFO *v);
  821. /*
  822.     functions in msleep.c
  823. */
  824. extern int msleep(unsigned long microsec);
  825.  
  826. #endif /* _TELNETCPCD_H */
  827.