home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 May / PCFMay2001.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / packet.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  2.8 KB  |  84 lines

  1. #ifndef __mrouter_packet_h
  2. #pragma option push -b -a8 -pc -A- /*P_O_Push*/
  3. #define __mrouter_packet_h
  4.  
  5. #include <assert.h>
  6.  
  7. typedef    struct    PACKET_BUFFER        PACKET_BUFFER;
  8. typedef    struct    PACKET_LIST_ENTRY    PACKET_LIST_ENTRY;
  9.  
  10. typedef void (*PACKET_COMPLETION_FUNC) (PACKET_BUFFER *);
  11.  
  12. struct    PACKET_LIST_ENTRY
  13. {
  14.     LIST_ENTRY        ListEntry;
  15.     PACKET_BUFFER *    PacketBuffer;
  16. };
  17.  
  18. #define    PACKET_BUFFER_ADDRESS_MAX    16
  19.  
  20. struct    PACKET_BUFFER
  21. {
  22.     LPBYTE                Data;                // storage for packet data
  23.     LPBYTE                Start;                // where the data begins, must be offset from Data
  24.     DWORD                Length;                // how long the data is, relative to Start
  25.     DWORD                Max;                // the maximum length of buffer, within Data
  26.     union {
  27.     DWORD                Context;            // for use by the originator of the packet
  28.     PVOID                ContextPointer;        // for use by the originator, but safe for 64-bit
  29.     };
  30.     WORD                Protocol;            // see below
  31.     WORD                AddressLength;
  32.     BYTE                Address        [PACKET_BUFFER_ADDRESS_MAX];
  33.     PACKET_COMPLETION_FUNC    CompletionFunc;
  34.     LONG                ReferenceCount;        // use interlocked access, do not access directly
  35.     LIST_ENTRY            ListEntry;            // for use only by the originator of the packet
  36. };
  37.  
  38. #define    PACKET_BUFFER_PROTOCOL_IP            0x0000
  39. #define    PACKET_BUFFER_PROTOCOL_VBI_RAW        0x0001
  40. #define    PACKET_BUFFER_PROTOCOL_DSS_ARP        0x0002
  41. #define    PACKET_BUFFER_PROTOCOL_DSS_RAW        0x0003
  42. #define    PACKET_BUFFER_PROTOCOL_DSS_MPT        0x0004
  43.  
  44. // PACKET_BUFFER_PROTOCOL_IP
  45. // packet body is a full IP packet, including header and body
  46. // IP address should be extracted from the message body
  47. // address field is not used
  48.  
  49. // PACKET_BUFFER_PROTOCOL_DSS_RAW
  50. // the address field is not used
  51. // the packet length must be 130 bytes.
  52. // the packet is a standard DSS frame: 3 bytes of header
  53. // and 127 bytes of payload
  54.  
  55. // PACKET_BUFFER_PROTOCOL_DSS_MPT
  56. // the address field may or may not be specified
  57. // the address field is the sub-SCID ID
  58. // if the address is not specified, the output driver should build the
  59. // sub-SCID like an Ethernet MAC address.  this only works for multicast packets,
  60. // which have a fixed, deterministic IP address to MAC address mapping.
  61. // if the address field exists (length is not zero), then the
  62. // address length must be 6 and the address must contain an MPT sub-SCID ID.
  63.  
  64. static __inline void PacketBufferComplete (PACKET_BUFFER * packet)
  65. {
  66.     assert (packet);
  67.     assert (packet -> CompletionFunc);
  68.  
  69.     (*packet -> CompletionFunc) (packet);
  70. }
  71.  
  72. static __inline void PacketBufferAddRef (PACKET_BUFFER * packet) {
  73.     assert (packet);
  74.     InterlockedIncrement (&packet -> ReferenceCount);
  75. }
  76.  
  77. static __inline void PacketBufferRelease (PACKET_BUFFER * packet) {
  78.     assert (packet);
  79.     if (!InterlockedDecrement (&packet -> ReferenceCount))
  80.         PacketBufferComplete (packet);
  81. }
  82.  
  83. #pragma option pop /*P_O_Pop*/
  84. #endif // __mrouter_packet_h