home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / downloads / c_scripts / fspscan.c / fspscan.h < prev    next >
C/C++ Source or Header  |  1994-05-18  |  5KB  |  112 lines

  1. #include <stdio.h>
  2. #include <sys/param.h>
  3. #include <sys/types.h>
  4. #include <dirent.h>
  5. #include <errno.h>
  6. #include <sys/socket.h>
  7. #include <netinet/in.h>
  8. #include <sys/stat.h>
  9. #include <sys/time.h>
  10. #include <fcntl.h>
  11. #include <signal.h>
  12.  
  13. /****************************************************************************
  14. *  UBUF is the structure of message exchanged between server and clients. 
  15. *
  16. *    The 'buf' part of the buffer is variable lenght up to max of 1024.
  17. *    The 'key' field is used by the server for sequence identification.
  18. *    The 'seq' field is used by the client for sequence identification.
  19. *
  20. *  Client's message to server contain a key value that is the same as the
  21. *  key value of the previous message received from the server.  Similarly,
  22. *  the server's message to client contains a seq value that is the same
  23. *  as the seq value of the previous message from the client. 
  24. *
  25. *  The buf field is logically partitioned into two parts by the len field.
  26. *  The len field indicate the size of the first part of the buffer starting
  27. *  at buf[0].  The rest of the buffer is the second field.  In some cases
  28. *  both fields can contain information.
  29. *
  30. ****************************************************************************/
  31.  
  32. #define UBUF_HSIZE 12                           /* 12 bytes for the header */
  33. #define UBUF_SPACE 1024                    /* maximum payload.        */
  34.  
  35. typedef struct UBUF {            char   cmd;  /* message code.             */
  36.                         unsigned char   sum;  /* message checksum.         */
  37.                         unsigned short  key;  /* message key.              */
  38.                         unsigned short  seq;  /* message sequence number.  */
  39.                         unsigned short  len;  /* number of bytes in buf 1. */
  40.                         unsigned long   pos;  /* location in the file.     */
  41.  
  42.                         char   buf[UBUF_SPACE];
  43.                     } UBUF;
  44.  
  45. /* definition of cmd */
  46.  
  47. #define CC_VERSION    0x10    /* return server's version string.    */
  48. #define CC_ERR          0x40    /* error response from server.          */
  49. #define CC_GET_DIR      0x41    /* get a directory listing.             */
  50. #define CC_GET_FILE     0x42    /* get a file.                          */
  51. #define CC_UP_LOAD      0x43    /* open a file for writing.             */
  52. #define CC_INSTALL      0x44    /* close a file opened for writing.     */
  53. #define CC_DEL_FILE     0x45    /* delete a file.                       */
  54. #define CC_DEL_DIR      0x46    /* delete a directory.                  */
  55. #define CC_GET_PRO      0x47    /* get directory protection.            */
  56. #define CC_SET_PRO      0x48    /* set directory protection.            */
  57. #define CC_MAKE_DIR     0x49    /* create a directory.                  */
  58. #define CC_BYE          0x4A    /* finish a session.                    */
  59.  
  60. /****************************************************************************
  61. *  RDIRENT is the structure of a directory entry contained in a .FSP_CONTENT
  62. *  file.  Each entry contains a 4 bytes quantity 'time', a 4 bytes quentity
  63. *  'size', and 1 byte of 'type'.  Then followed by x number of bytes of
  64. *  'name'.  'name' is null terminated.  Then followed by enough number of
  65. *  padding to fill to an 4-byte boundary.  At this point, if the next entry
  66. *  to follow will spread across 1k boundary, then two possible things will
  67. *  happen.  1) if the header fits between this entry and the 1k boundary,
  68. *  a complete header will be filled in with a 'type' set to RDTYPE_SKIP.
  69. *  And then enough bytes to padd to 1k boundary.  2) if the header does
  70. *  not fit, then simply pad to the 1k boundary.  This will make sure that
  71. *  messages carrying directory information carry only complete directory
  72. *  entries and no fragmented entries.  The last entry is type RDTYPE_END.
  73. ****************************************************************************/
  74.  
  75. #define RDHSIZE (2*sizeof(unsigned long)+sizeof(unsigned char))
  76.  
  77. typedef struct RDIRENT { unsigned long  time;
  78.                          unsigned long  size;
  79.                          unsigned char  type;
  80.                          char        name[1]; } RDIRENT;
  81.  
  82. #define RDTYPE_END      0x00
  83. #define RDTYPE_FILE     0x01
  84. #define RDTYPE_DIR      0x02
  85. #define RDTYPE_SKIP     0x2A
  86.  
  87. #define NULLP ((char *) 0)
  88.  
  89.  
  90. /****************************************************************************
  91. * These structures are used to implement a opendir/readdir mechanism similar
  92. * to that of the normal opendir/reader mechanism in unix.
  93. ****************************************************************************/
  94.  
  95. typedef struct DDLIST {    struct DDLIST *next;
  96.             char          *path;
  97.             RDIRENT  **dep_root;
  98.             int         ref_cnt; } DDLIST;
  99.  
  100. typedef struct RDIR { DDLIST   *ddp;
  101.               RDIRENT **dep; } RDIR;
  102.  
  103. typedef struct rdirent { unsigned long  d_fileno;
  104.              unsigned short d_reclen;
  105.              unsigned short d_namlen;
  106.              char          *d_name; } rdirent;
  107.  
  108. UBUF     *client_interact();
  109. void     client_intr();
  110. long     inet_addr();
  111.  
  112.