home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff294.lzh / DNet / unix / dnet / dnet.h < prev    next >
C/C++ Source or Header  |  1989-12-11  |  7KB  |  247 lines

  1.  
  2. /*
  3.  *  DNET.H
  4.  *
  5.  *    DNET (c)Copyright 1988, Matthew Dillon, All Rights Reserved
  6.  */
  7.  
  8. #include <sys/types.h>
  9. #include <sys/ioctl.h>
  10. #include <sys/socket.h>
  11. #include <sys/time.h>
  12. #include <sys/file.h>
  13.  
  14. /* V2.01 */
  15. #include <sys/param.h>
  16. #include <pwd.h>
  17.  
  18. #include <signal.h>
  19. #include <stdio.h>
  20. #include <errno.h>
  21. #ifndef FD_SETSIZE
  22. #define FD_SETSIZE (sizeof(struct fd_set) * 8)
  23. #endif
  24. #ifndef NFDBITS
  25. #define NFDBITS 32
  26. #define    FD_SET(n, p)    ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
  27. #define    FD_CLR(n, p)    ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
  28. #define    FD_ISSET(n, p)    ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
  29. #define FD_ZERO(p)    bzero((char *)(p), sizeof(*(p)))
  30. #endif
  31. #ifndef sigmask
  32. #define sigmask(m) (1 << ((m)-1))
  33. #endif
  34.  
  35. #ifndef LASTTRYDNETSERVERS
  36. #define LASTTRYDNETSERVERS "/usr/local/lib/dnet/dnet.servers"
  37. #endif
  38.  
  39. struct Node {
  40.     struct Node *ln_Succ;
  41.     struct Node *ln_Pred;
  42. };
  43.  
  44. struct List {
  45.     struct Node *lh_Head;
  46.     struct Node *lh_Tail;
  47.     struct Node *lh_TailPred;
  48. };
  49.  
  50.  
  51. typedef unsigned char    ubyte;
  52. typedef unsigned short    uword;
  53. typedef unsigned long    ulong;
  54.  
  55. typedef struct List        LIST;
  56. typedef struct Node        NODE;
  57.  
  58. #include "channel.h"
  59.  
  60. #define PKT struct _PKT
  61. #define CTLPKT struct _CTLPKT
  62. #define XIOR struct _XIOR
  63.  
  64. #define EMPTY    0    /*  empty (sent)                    */
  65. #define READY    1    /*  data ready (not sent yet)       */
  66. #define RCVBUF  4096
  67.  
  68. #define MAXCHAN 128    /*  Max # of channels supported     */
  69. #define SYNC    0x5B    /*  SYNC character            */
  70. #define WTIME    8     /*  in seconds (expect ack)           */
  71. #define RTIME    4    /*  in seconds (read to)              */
  72. #define MAXPKT    200    /*  maximum packet size  (data area)              */
  73. #define MINPKT  32    /*  minimum packet size  (data area) for purposes */
  74.             /*  of determining the dynamic maximum packet size*/
  75.             /*  only.  Actual minimum is, of course, 1 byte   */
  76.  
  77. #define MAXPACKET ((MAXPKT * 8 + 5) / 6 + 64)
  78.  
  79. #define OVERHEAD    7    /*  for packets with data        */
  80.  
  81. XIOR {
  82.     NODE    io_Node;
  83.     ubyte   *io_Data;
  84.     ulong   io_Length;
  85.     ulong   io_Actual;
  86.     uword   io_Channel;
  87.     ubyte   io_Command;
  88.     ubyte   io_Error;
  89.     char    io_Pri;
  90. };
  91.  
  92. PKT {
  93.     uword   buflen;
  94.     ubyte   state;    /*  EMPTY, READY                    */
  95.  
  96.     ubyte   sync;    /*  THE PACKET        */
  97.     ubyte   ctl;
  98.     ubyte   cchk;
  99.     ubyte   lenh;
  100.     ubyte   lenl;
  101.     ubyte   dchkh;
  102.     ubyte   dchkl;
  103.     ubyte   data[MAXPACKET];
  104. };
  105.  
  106. CTLPKT {
  107.     uword buflen;
  108.     ubyte state;
  109.  
  110.     ubyte sync;
  111.     ubyte ctl;
  112.     ubyte cchk;
  113. };
  114.  
  115.     /*
  116.      *    In receiving a packet the receiver can be in one of these
  117.      *    states.
  118.      */
  119.  
  120. #define RS_SYNC 0        /*    Waiting for sync        */
  121. #define RS_CTL    1        /*    Waiting for command        */
  122. #define RS_CCHK 2        /*    Waiting for check byte        */
  123. #define RS_LEN1 3        /*    Waiting for MSB length byte    */
  124. #define RS_LEN2 4        /*    Waiting for LSB length byte    */
  125. #define RS_DATA 5        /*    Waiting for data & checksum    */
  126.  
  127.     /*
  128.      *    The low level protocol generates packets.   This is used 
  129.      *    for error checking, data sequencing, retries, restart, etc...
  130.      *    The packet format is:
  131.      *
  132.      *    SYNC sss0xccc CHK
  133.      *    SYNC sss1xccc CHK nnnnnnnn nnnnnnnn [DATA] CHK2
  134.      *                msb       lsb
  135.      *
  136.      *    sss = sequence #
  137.      *    B4  = packet contains data
  138.      *    B3  = reserved (may be used to extend the command set)
  139.      *    ccc = PKF_?????
  140.      *
  141.      *    NOTE that the data length nnn..nn is not checked with either
  142.      *    CHK or CHK2 .  The protocol will determine if the length
  143.      *    is reasonable (< MAXPKT) and then try to read that many
  144.      *    bytes.  The CHK will obviously fail if the length was 
  145.      *    incorrect.
  146.      */
  147.  
  148. #define PKF_SEQUENCE    0x07    /*  Sequence #            */
  149. #define PKF_MASK    0x78    /*  command mask        */
  150.  
  151. #define PKCMD_RESTART     0x20    /*  RESTART dnet.  (new)    */
  152. #define PKCMD_ACKRSTART    0x28    /*  ACK a restart  (new)    */
  153. #define PKCMD_WRITE6    0x30
  154. #define PKCMD_WRITE    0x38    /*  A DATA packet        */
  155. #define PKCMD_CHECK    0x40    /*  Request ACK or NAK for win    */
  156. #define PKCMD_ACK    0x48    /*  ACK a window        */
  157. #define PKCMD_NAK    0x50    /*  NAK a window        */
  158. #define PKCMD_WRITE7    0x58
  159.  
  160.     /*
  161.      *  All channel multiplexing, channel commands, etc... is encoded
  162.      *  within a PKCMD_WRITE packet.
  163.      *
  164.      *  Channel commands are characterized by a one byte control
  165.      *  field and up to 7 bytes of data.  The control field format
  166.      *  is:        10cccnnn [DATA]        ccc = SCMD_??
  167.      *                    nnn = # additional data bytes
  168.      */
  169.  
  170. #define SCMD_SWITCH    0x00    /*  switch active channel #    */
  171. #define SCMD_OPEN    0x01    /*  open a channel        */
  172. #define SCMD_CLOSE    0x02    /*  close a channel        */
  173. #define SCMD_ACKCMD    0x03    /*  ack an open/close request    */
  174. #define SCMD_EOFCMD    0x04    /*  Reof or Weof        */
  175. #define SCMD_QUIT    0x05    /*  QUIT dnet            */
  176. #define SCMD_IOCTL    0x06    /*  channel ioctl (new),PTY sup    */
  177. #define SCMD_RESERVE1    0x07
  178.  
  179.     /*
  180.      *  Stream data is characterized by the following format:
  181.      *
  182.      *           msb      lsb    
  183.      *        11nnnnnn nnnnnnnn [128-16383 bytes DATA]
  184.      *             0nnnnnnn [0-127 bytes DATA]
  185.      *
  186.      *  NOTE:  11000000 0ccccccc nnnnnnnn   reserved for furture ext. of
  187.      *                    SCMD commands.
  188.      */
  189.  
  190. #define SCMD_DATA    0x08    /*  stream command, DATA (dummy ID)    */
  191.  
  192.     /*
  193.      *  Each channel can be in one of several states.
  194.      */
  195.  
  196. #define CHAN_FREE    0x01    /*  free channel        */
  197. #define CHAN_ROPEN    0x02    /*  remote open, wait port msg    */
  198. #define CHAN_LOPEN    0x03    /*  local open, wait reply    */
  199. #define CHAN_OPEN    0x04    /*  channel open        */
  200. #define CHAN_CLOSE    0x05    /*  one side of channel closed  */
  201.  
  202. #define CHANF_ROK    0x01    /*  remote hasn't EOF'd us yet  */
  203. #define CHANF_WOK    0x02    /*  remote will accept data    */
  204. #define CHANF_LCLOSE    0x04     /*  channel closed on our side  */
  205. #define CHANF_RCLOSE    0x08    /*  channel closed on rem side  */
  206.  
  207. extern ubyte *RemHead();
  208. extern ubyte *malloc();
  209. extern char *getenv();
  210.  
  211. #ifndef NOEXT
  212. extern int DNet_fd;
  213. extern PKT Pkts[9];
  214. extern PKT *RPak[4];
  215. extern PKT *WPak[4];
  216. extern CHAN Chan[MAXCHAN];
  217. extern LIST TxList;           /*  For pending DNCMD_WRITE reqs.   */
  218. extern fd_set Fdread;
  219. extern fd_set Fdwrite;
  220. extern fd_set Fdexcept;
  221. extern void (*Fdstate[FD_SETSIZE])();
  222. extern ubyte Fdperm[FD_SETSIZE];
  223. extern uword FdChan[FD_SETSIZE];
  224. extern ubyte RcvBuf[RCVBUF];
  225. extern ubyte RTimedout, WTimedout;
  226. extern uword Rto_act, Wto_act;
  227. extern uword RcvData;
  228. extern uword RExpect;
  229. extern uword RChan;
  230. extern uword WChan;
  231. extern uword RPStart;
  232. extern uword WPStart;
  233. extern uword WPUsed;
  234. extern uword RState;
  235. extern ubyte DDebug;
  236. extern ubyte PDebug;
  237. extern ubyte Restart;
  238. extern ubyte DeldQuit;
  239. extern ulong NumCon; 
  240. extern ubyte Mode7;
  241.  
  242. extern int errno;
  243. extern int WReady;
  244.  
  245. #endif
  246.  
  247.