home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / dobbs / v17n05 / ipx.exe / NETWORK.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-01  |  18.1 KB  |  382 lines

  1. /**************************************************************************************************
  2. *
  3. *        Title:    NETWORK.H
  4. *        Copyright (c) December 1991, Ryu Consulting, 916/722-1939
  5. *        Written by Rahner James
  6. *
  7. *        This file contains all the structure and header information for the Novell network
  8. *        programming library.
  9. *
  10. **************************************************************************************************/
  11.  
  12. #define    _NETWORK_H_
  13. #pragma    pack(1)
  14.  
  15. /**************************************************************************************************
  16. *
  17. *                                        Definitions
  18. *
  19. **************************************************************************************************/
  20.  
  21. /*
  22. ** In use flags for ECBs
  23. */
  24.  
  25. #define    IU_DONE            0x00    // Indicates that the ECB has been processed and completion code is valid
  26. #define    IU_HOLDING        0xFB    // Send/receive has occurred, but ECB is in holding queue waiting to be processed
  27. #define    IU_SCHEDULED    0xFD    // Event has been scheduled and is waiting for time-out
  28. #define    IU_LISTENING    0xFE    // IPX is listening for incoming packets at a socket
  29. #define    IU_SENDING        0xFF    // ECB is being sent or in the process of being sent
  30. #define    IU_PROCESSING    0xFA    // ECB is being processed by IPX
  31. #define    IU_WAITING        0xF8    // ECB has been put in a waiting queue because IPX was busy
  32.  
  33.  
  34. /*
  35. ** Completion codes for transmission ECBs
  36. ** Note: completion codes are not valid until in use flag contains IU_DONE value
  37. */
  38.  
  39. #define    CC_SUCCESS        0x00    // The packet has been sent successfully
  40. #define    CC_CANCELLED    0xFC    // Send request for this ECB has been cancelled, just like Twin Peaks
  41. #define    CC_CHALLEDGED    0xFD    // Packet was malformed (eg. IPX packet <30 bytes, SPX<42 bytes, packet > 576 bytes)
  42. #define    CC_UNDELIVERED    0xFE    // Packet couldn't be sent, no listener available
  43. #define    CC_FAILURE        0xFF    // Network was physically unable to deliver the packet
  44.  
  45.  
  46. /*
  47. ** Additional completion codes for reception ECBs
  48. ** Note: completion codes are not valid until in use flag contains IU_DONE value
  49. */
  50.  
  51. #define    CC_OVERFLOW        0xFD    // The size of the fragment received is either 0 or too large (>576 bytes)
  52. #define    CC_CLOSED        0xFF    // The reception socket was not open
  53.  
  54.  
  55. /*
  56. ** Additional completion codes for cancellation of an ECB
  57. ** Note: completion codes are not valid until in use flag contains IU_DONE value
  58. */
  59.  
  60. #define    CC_CANCEL_FAIL    0xF9    // The ECB could not be cancelled
  61.  
  62.  
  63. /*
  64. ** xPX_OPEN flags
  65. */
  66.  
  67. #define    XPX_READ        1        // Sets up listening packets for the stream
  68. #define    XPX_WRITE        2        // Sets up talking packets for the stream
  69. #define    XPX_RW            3        // Sets up talking and listening packets for the stream
  70. #define    XPX_WAIT        4        // xPX_OPEN() waits for a response before returning
  71. #define    XPX_NOWAIT        0        // xPX_OPEN() returns immediately after stream is opened
  72. #define    XPX_SPX            8        // xPX_OPEN() creates an SPX stream
  73. #define    XPX_IPX            0        // xPX_OPEN() creates an IPX stream
  74.  
  75.  
  76. /*
  77. ** Error return codes used by the xPX library
  78. */
  79.  
  80. #define    ERR_SOCKET_OPEN    -1        // Socket was already open
  81. #define    ERR_NO_SOCKET    -1        // Socket does not exist
  82. #define    ERR_SOCKET_FULL    -2        // Socket table is full
  83. #define    ERR_NO_IPX_PATH    -6        // No path to destination node found
  84. #define    ERR_MEMORY        -8        // Not enough memory to allocated for function
  85. #define    ERR_IPX_TIMEOUT    -9        // Timeout occurred during a waiting period
  86. #define    ERR_POINTER        -10        // Pointer contents are not supported by the function
  87. #define    ERR_PARAMETER    -11        // One of the passed parameters is not kosher
  88. #define    ERR_OPEN        -12        // Stream is already open
  89. #define    ERR_NOT_OPEN    -13        // Stream is not open or invalid stream pointer
  90. #define    ERR_NO_SUPPORT    -14        // Tried to read a WRITE ONLY or write a READ ONLY stream
  91. #define    ERR_NO_NULLS    -15        // Tried to write with a NULL flag while _Asynch_Flag == !0
  92.  
  93.  
  94. /*
  95. ** Control parameters
  96. */
  97.  
  98. #define    DEFAULT_TALKERS        5    // Number of talkers normally created with an open
  99. #define    DEFAULT_LISTENERS    5    // Number of listeners normally created with an open
  100. #define    NODE_ADDRESS_SIZE    6    // Number of bytes in a node address, either local or global
  101. #define    MAX_PACKET_SIZE        576    // Maximum size of a packet including IPX/SPX header
  102. #define    IPX_TYPE            4    // Packet type number for IPX packets
  103. #define    SPX_TYPE            5    // Packet type number for SPX packets
  104.  
  105.  
  106. /**************************************************************************************************
  107. *
  108. *                                        Structures
  109. *
  110. **************************************************************************************************/
  111.  
  112. typedef struct NET_ADDRESS_S
  113. {
  114.     unsigned long    network;                    // Network number
  115.     unsigned char    node[NODE_ADDRESS_SIZE];    // Physical node address
  116.     unsigned short    socket;                        // Socket number
  117. } NET_ADDRESS_T;
  118.  
  119.  
  120. typedef struct IPX_S
  121. {
  122.     unsigned short    checksum;        // Dummy checksum of the 30-byte packet header, filled by IPX
  123.     unsigned short    length;            // Length of the complete IPX packet, filled by IPX
  124.     unsigned char    control;        // Transport control byte for internetwork bridges, filled by IPX
  125.     unsigned char    type;            // Packet type: IPX=4, SPX=5, defined by Xerox, set by application    *
  126.     NET_ADDRESS_T    dest;            // Destination node address, set by application                        *
  127.     NET_ADDRESS_T    src;            // Source node address, set by IPX
  128. } IPX_T;
  129.  
  130.  
  131. typedef struct SPX_S
  132. {
  133.     unsigned short    checksum;        // Dummy checksum of the 30-byte packet header, filled by SPX
  134.     unsigned short    length;            // Length of the complete IPX packet, filled by SPX
  135.     unsigned char    control;        // Transport control byte for internetwork bridges, filled by SPX
  136.     unsigned char    type;            // Packet type: IPX=4, SPX=5, defined by Xerox, set by application    *
  137.     NET_ADDRESS_T    dest;            // Destination node address, set by application                        *
  138.     NET_ADDRESS_T    src;            // Source node address, set by SPX
  139.  
  140.     struct
  141.     {
  142.         unsigned char reserved1:4;    // Reserved for future use
  143.         unsigned char end_of_msg:1;    // End of message
  144.         unsigned char reserved2:1;    // Reserved for future use
  145.         unsigned char ACK_req:1;    // Acknowledge required
  146.         unsigned char sys_packet:1;    // System packet
  147.     } con_control;                    // Connection control structure, set by SPX
  148.     unsigned char    datastream;        // Datastream type, 0x00-0xFD are ignored, set by application        *
  149.     unsigned short    src_ID;            // Source connection ID, used by SPX, filled by SPX
  150.     unsigned short    dest_ID;        // Destination connection ID, used by SPX, filled by SPX
  151.     unsigned short    sequence;        // Sequence number to keep track of the packet sequence, filled by SPX
  152.     unsigned short    ACK_number;        // Acknowledge number, used by SPX, filled by SPX
  153.     unsigned short    allocation;        // Allocation number, used by SPX, filled by SPX
  154. } SPX_T;
  155.  
  156.  
  157. typedef struct ECB_HEADER_S
  158. {
  159.     struct ECB_S far *next;            // Used by IPX/SPX when the ECB is active, can be used when ECB is inactive
  160.     void (far *function)(void);        // Called when packet sent/recd, called Event Service Routine                    * s,r
  161.     unsigned char    in_use;            // Flag used by IPX/SPX while it processes the ECB, !0 while in use
  162.     unsigned char    completion_code;// Completion code that is valid only when in_use is set to 0
  163.     unsigned short    socket;            // Transmission/reception socket to use for this ECB                            * s,r
  164.     unsigned char    IPX_work[4];    // Workspace used internally by IPX
  165.     unsigned char    driver_work[12];// Workspace used internally by the IPX driver
  166.     unsigned char    dest_address[NODE_ADDRESS_SIZE];    // Address of node to which packet is sent/received            * s,r
  167.     unsigned short    fragment_count;                        // Number of address/size IPX/SPX fragments that follow        * s,r
  168. } ECB_HEADER_T;
  169.  
  170.  
  171. typedef struct FRAGMENT_S
  172. {
  173.     void far *        ptr;            // -> buffer that data is sent from or received into
  174.     unsigned short    size;            // Size of that buffer
  175. } FRAGMENT_T;
  176.  
  177.  
  178. typedef struct SPX_PACKET_S
  179. {
  180.     struct SPX_PACKET_T far *next;    // Used by IPX/SPX when the ECB is active
  181.     void (far *function)(void);        // Called after packet sent/recd, called ESR,             * s,r
  182.     unsigned char    in_use;            // Set to !0 by IPX/SPX when packet is in use
  183.     unsigned char    completion_code;// Set by IPX/SPX after packet task is complete
  184.     unsigned short    socket;            // Socket to use for this ECB                            * s,r
  185.     unsigned char    IPX_work[4];    // Workspace used internally by IPX
  186.     unsigned char    driver_work[12];// Workspace used internally by the IPX driver
  187.     unsigned char    dest_address[NODE_ADDRESS_SIZE];    // Destination address for packet    * s
  188.     unsigned short    fragment_count;    // Fragments descriptors that follow                    * s,r
  189.     SPX_T far *        hdr;            // -> IPX/SPX packet descriptor to use                    * s,r
  190.     unsigned short    size_hdr;        // Size of the IPX(30) or SPX(42) descriptor            * s,r
  191.     void far *        buffer_ptr;        // -> data buffer to use for transmission/reception        * s,r
  192.     unsigned short    buffer_size;    // Number of bytes in that buffer                        * s,r
  193.  
  194.     struct SPX_PACKET_S far *next_allocated;    // -> next allocated packet structure        * set by SPX_OPEN
  195.     struct SPX_PACKET_S far *next_sibling;        // -> next packet for stream and condition    * various functions
  196.     struct XPX_STREAM_S far *parent;            // -> parent stream definition packet        * set by SPX_OPEN
  197.     void far *        default_buffer;    // -> default buffer to use for IPX or SPX                * set by SPX_OPEN
  198.     unsigned short    default_size;    // Size of the default buffer                            * set by SPX_OPEN
  199.     char far *        done_flag;        // Set by the ESR with the completion code                * set by SPX_READ,SPX_WRITE
  200.  
  201.     unsigned short    checksum;        // Dummy checksum of the 30-byte packet header
  202.     unsigned short    length;            // Length of the complete IPX packet, filled by IPX/SPX
  203.     unsigned char    control;        // Transport control byte for internetwork bridges
  204.     unsigned char    type;            // Packet type: IPX(4)/SPX(5), defined by Xerox            * s
  205.     NET_ADDRESS_T    dest;            // Destination node address                                * s
  206.     NET_ADDRESS_T    src;            // Source node address, filled by IPX/SPX
  207.  
  208.     struct
  209.     {
  210.         unsigned char reserved1:4;    // Reserved for future use
  211.         unsigned char end_of_msg:1;    // End of message
  212.         unsigned char reserved2:1;    // Reserved for future use
  213.         unsigned char ACK_req:1;    // Acknowledge required
  214.         unsigned char sys_packet:1;    // System packet
  215.     } con_control;                    // Connection control structure
  216.     unsigned char    datastream;        // Datastream type, 0x00-0xFD can be used by application    * s
  217.     unsigned short    src_ID;            // Source connection ID, used by SPX, filled by SPX
  218.     unsigned short    dest_ID;        // Destination connection ID, used by SPX, filled by SPX
  219.     unsigned short    sequence;        // Sequence number to keep track of the packet sequence
  220.     unsigned short    ACK_number;        // Acknowledge number
  221.     unsigned short    allocation;        // Allocation number
  222. } SPX_PACKET_T;
  223.  
  224.  
  225. typedef struct IPX_PACKET_S
  226. {
  227.     struct IPX_PACKET_T far *next;    // Used by IPX/SPX when the ECB is active
  228.     void (far *function)(void);        // Called after packet sent/recd, called ESR,             * s,r
  229.     unsigned char    in_use;            // Set to !0 by IPX/SPX when packet is in use
  230.     unsigned char    completion_code;// Set by IPX/SPX after packet task is complete
  231.     unsigned short    socket;            // Socket to use for this ECB                            * s,r
  232.     unsigned char    IPX_work[4];    // Workspace used internally by IPX
  233.     unsigned char    driver_work[12];// Workspace used internally by the IPX driver
  234.     unsigned char    dest_address[NODE_ADDRESS_SIZE];    // Destination address for packet    * s
  235.     unsigned short    fragment_count;    // Fragments descriptors that follow                    * s,r
  236.     IPX_T far *        hdr;            // -> IPX/SPX packet descriptor to use                    * s,r
  237.     unsigned short    size_hdr;        // Size of the IPX(30) or SPX(42) descriptor            * s,r
  238.     void far *        buffer_ptr;        // -> data buffer to use for transmission/reception        * s,r
  239.     unsigned short    buffer_size;    // Number of bytes in that buffer                        * s,r
  240.  
  241.     struct IPX_PACKET_S far *next_allocated;    // -> next allocated packet structure        * set by IPX_OPEN
  242.     struct IPX_PACKET_S far *next_sibling;        // -> next packet for stream and condition    * various functions
  243.     struct XPX_STREAM_S far *parent;            // -> parent stream definition packet        * set by IPX_OPEN
  244.     void far *        default_buffer;    // -> default buffer to use for IPX or SPX                * set by IPX_OPEN
  245.     unsigned short    default_size;    // Size of the default buffer                            * set by IPX_OPEN
  246.     char far *        done_flag;        // Set by the ESR with the completion code                * set by IPX_READ,IPX_WRITE
  247.  
  248.     unsigned short    checksum;        // Dummy checksum of the 30-byte packet header
  249.     unsigned short    length;            // Length of the complete IPX packet, filled by IPX/SPX
  250.     unsigned char    control;        // Transport control byte for internetwork bridges
  251.     unsigned char    type;            // Packet type: IPX(4)/SPX(5), defined by Xerox            * s
  252.     NET_ADDRESS_T    dest;            // Destination node address                                * s
  253.     NET_ADDRESS_T    src;            // Source node address, filled by IPX/SPX
  254. } IPX_PACKET_T;
  255.  
  256.  
  257. typedef struct XPX_STREAM_S
  258. {
  259.     struct XPX_STREAM_S far *next;        // -> next stream structure that has been opened
  260.     SPX_PACKET_T far *first_allocated;    // -> first allocated packet for this handle
  261.     SPX_PACKET_T far *last_allocated;    // -> last allocated packet for this handle
  262.     SPX_PACKET_T far *first_unread;        // -> first unread packet
  263.     SPX_PACKET_T far *last_unread;        // -> last unread packet in the list
  264.     SPX_PACKET_T far *first_free;        // -> first packet available for talking
  265.     SPX_PACKET_T far *first_error;        // -> first packet that encountered an error
  266.     SPX_PACKET_T far *last_error;        // -> last packet that encountered an error
  267.  
  268.     NET_ADDRESS_T dest;                        // -> destination network, node, and socket
  269.     char local_target[NODE_ADDRESS_SIZE];    // Node address of the local target for the destination
  270.     unsigned short connection_ID;            // Connection ID used for SPX
  271.     int    total_talkers;                        // Number of talkers allocated to this stream
  272.     int    total_listeners;                    // Number of listeners allocated to this stream
  273.     int    unread_count;                        // Number of packets unread by application
  274.     int free_count;                            // Number of free packets ready for tranmitting
  275.     int    maximum_unread;                        // Maximum number of unread packets that have occurred so far
  276.     int    error_count;                        // Number of unprocessed error packets
  277.  
  278.     unsigned long    total_transmissions;    // Number of transmissions performed by this stream
  279.     unsigned long    total_receptions;        // Number of receptions performed by this stream
  280.     unsigned long    total_errors;            // Number of errors encountered by this stream
  281.  
  282.     int                open_flags;                // Flags used when this stream was opened
  283. } XPX_STREAM_T;
  284.  
  285.  
  286. typedef struct ORPHAN_S
  287. {
  288.     NET_ADDRESS_T    src;                    // Source address of the orphaned packet
  289.     unsigned short    length;                    // Number of bytes in the buffer that follows
  290.     unsigned char    buffer[1];                // Start of the data buffer
  291. } ORPHAN_T;
  292.  
  293.  
  294. /**************************************************************************************************
  295. *
  296. *                                    Global Data
  297. *
  298. **************************************************************************************************/
  299.  
  300. extern NET_ADDRESS_T    _Our_Address;        // Full address into which the application will receive transmissions
  301. extern char    _Socket_Life;                    // 0 if all sockets are closed at application exit, 0xFF if only closed explicitly
  302.  
  303. extern unsigned short    _SPX_Version;
  304. extern unsigned short    _SPX_Max_Connections;
  305. extern unsigned short    _SPX_Available_Connections;
  306. extern unsigned char    _SPX_Retry_Count;
  307. extern unsigned char    _SPX_Bowser_Flag;
  308.  
  309. #ifndef _IPX_OPEN_C_
  310. extern int _Default_Talkers;                // Default number of talkers created when a stream is opened
  311. extern int _Default_Listeners;                // Default number of listeners created when a stream is opened
  312. extern void (far *_Default_Talk_ESR)();        // -> default talking ESR
  313. extern void (far *_Default_Listen_ESR)();    // -> default listening ESR
  314. extern XPX_STREAM_T far *_First_Stream;        // -> first stream structure allocated by this application
  315. extern SPX_PACKET_T far *_First_Nomatch;    // -> first received packet that does not match a stream address
  316. extern SPX_PACKET_T far *_Last_Nomatch;        // -> last received packet that does not match a stream address
  317. extern int _Total_Nomatchs;                    // Count of the packets of nonmatched packets
  318. extern int _Total_Open_Streams;                // Number of open streams
  319. extern int _Wait_Timeout;                    // Number of system ticks to wait for a response
  320. extern char    _Asynch_Flag;                    // Set to !0 if all writes will be asynchronous
  321. extern char    _Ignore_Nomatch;                // Set to 0 if non matching packets should be kept
  322. #endif
  323.  
  324.  
  325. /**************************************************************************************************
  326. *
  327. *                                    Function Prototypes
  328. *
  329. **************************************************************************************************/
  330.  
  331. extern void atoaddr( char far *, char far * );
  332. extern void addrtoa( char far *, char far * );
  333. extern int broadcast_to_console( char * );
  334. extern int close_semaphore( long );
  335. extern int create_socket_list( unsigned short, int, int, void (far *)(), unsigned short );
  336. extern int end_of_job( int );
  337. extern int farcmpw( void far *, void far *, unsigned int );
  338. extern void far *farmove( void far *, void far *, unsigned int );
  339. extern void far *farset( void far *, char, unsigned int );
  340. extern int get_semaphore_count( long );
  341. extern int get_semaphore_value( long );
  342. extern int isbroadcast( char far * );
  343. extern int ipx_add_listener( ECB_HEADER_T far * );
  344. extern int ipx_cancel_ecb( ECB_HEADER_T far * );
  345. extern int ipx_close_socket( unsigned short );
  346. extern int xpx_init( unsigned short );
  347. extern int ipx_open_socket( unsigned short far * );
  348. extern int ipx_send_packet( ECB_HEADER_T far * );
  349. extern int ipx_target( char far *, NET_ADDRESS_T far * );
  350. extern int open_semaphore( char *, char, char *, long * );
  351. extern int signal_semaphore( long );
  352. extern int spx_add_listener( ECB_HEADER_T far * );
  353. extern int spx_establish_connection( ECB_HEADER_T far *, unsigned short far * );
  354. extern int spx_send_packet( ECB_HEADER_T far * );
  355. extern int wait_semaphore( long, unsigned short );
  356.  
  357. extern void far talk_esr( void );
  358. extern void far listen_esr( void );
  359.  
  360. #define    xpx_error_status(ptr)    ptr->error_count
  361. #define    xpx_orphan_status()        _Total_Nomatchs
  362. #define    xpx_read_status(ptr)    ptr->unread_count
  363. #define    xpx_write_status(ptr)    ptr->free_count
  364.  
  365.  
  366. #ifndef _IPX_OPEN_C_
  367. extern int xpx_close( XPX_STREAM_T far * );
  368. extern int xpx_open( NET_ADDRESS_T *, int, XPX_STREAM_T far ** );
  369. #endif
  370.  
  371. #ifndef _IPX_ORPH_C_
  372. extern ORPHAN_T far *ipx_read_orphan( ORPHAN_T far * );
  373. #endif
  374.  
  375. #ifndef _IPX_READ_C_
  376. extern int xpx_read( XPX_STREAM_T far *, void far *, int );
  377. #endif
  378.  
  379. #ifndef _IPX_WRIT_C_
  380. extern int xpx_write( XPX_STREAM_T far *, void far *, int, char far * );
  381. #endif
  382.