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