home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / IPFlakeWay / Squelch Module / source / NatProcess.h < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.1 KB  |  149 lines

  1. // =================================================================================
  2. //    NatProcess.h                     ©1997 Sustainable Softworks. All rights reserved.
  3. // =================================================================================
  4. //    Network Address Translation Process
  5. //    This module encapsulates the process of converting an IP datagram
  6. //    using Network Address Translation
  7. //
  8. //    Since this module executes in the STREAMs context, instance data is
  9. //    allocated when the STREAM is opened rather than by instantiating
  10. //    a C++ object.  For this reason, many of the module functions are
  11. //    passed a pointer to their instance data (i.e. the table).
  12. //    This also makes the module self contained to facilitate debugging
  13. //    in an application context.
  14.  
  15. #ifndef _H_NatProcess
  16. #define _H_NatProcess
  17. #pragma once
  18.  
  19. #include "NatTable.h"
  20.  
  21. // ---------------------------------------------------------------------------
  22. // forward function declarations [external]
  23. // ---------------------------------------------------------------------------
  24. Boolean    Convert2Apparent(translationEntry_t table[], UInt8* datagram, mblk_t* mp, UInt8 option);
  25. UInt8    Convert2Actual(translationEntry_t table[], UInt8* datagram, mblk_t* mp, UInt8 option);
  26. UInt16    IpSum( UInt16* dataPtr, UInt16* endPtr);
  27. UInt16    AdjustIpSum( UInt16 oldSum, UInt16 oldData, UInt16 newData);
  28. UInt16    AdjustIpSum32( UInt16 oldSum, UInt32 oldData, UInt32 newData);
  29. UInt16    RemoveFromSum( UInt16 oldSum, UInt16* dataPtr, UInt16* endPtr);
  30. UInt16    AddToSum( UInt16 oldSum, UInt16* dataPtr, UInt16* endPtr);
  31. Boolean ipCheck(UInt8* datagram);
  32. Boolean tcpCheck(UInt8* datagram);
  33.  
  34. // ---------------------------------------------------------------------------
  35. //        • IP packet structures
  36. // ---------------------------------------------------------------------------
  37. struct ip_header_t
  38.     {
  39.     UInt8    hlen;
  40.     UInt8    tos;
  41.     UInt16    totalLength;
  42.     UInt16    identification;
  43.     UInt16    fragmentOffset;
  44.     UInt8    ttl;
  45.     UInt8    protocol;
  46.     UInt16    checksum;
  47.     UInt32    srcAddress;
  48.     UInt32    dstAddress;
  49.     };
  50. typedef struct ip_header_t ip_header_t;
  51.  
  52. struct icmp_header_t
  53.     {
  54.     UInt8    type;
  55.     UInt8    code;
  56.     UInt16    checksum;
  57.     UInt16    identifier;            // icmp echo
  58.     UInt16    seqNumber;            // icmp echo
  59.     UInt8    data[28];            // optional data
  60.         // IP header + first 64 bits of datagram
  61.     };
  62. typedef struct icmp_header_t icmp_header_t;
  63.  
  64. #define kIcmpEchoReply                     0
  65. #define kIcmpTypeDestUnreachable        3
  66. #define kIcmpTypeSourceQuench            4
  67. #define kIcmpTypeRedirect                5
  68. #define kIcmpTypeEchoRequest            8
  69. #define kIcmpTypeTimeExceeded             11
  70. #define kIcmpTypeParameterProblem        12
  71.  
  72. #define rSTRN_IcmpCode                    133
  73. #define kIcmpCodeNetworkUnreachable        0
  74. #define kIcmpCodeHostUnreachable        1
  75. #define kIcmpCodeProtocolUnreachable    2
  76. #define kIcmpCodePortUnreachable        3
  77. #define kIcmpCodeDestNetworkUnknown        6
  78. #define kIcmpCodeDestHostUnknown        7
  79. #define kIcmpCodeDestNetworkAdmin        9
  80. #define kIcmpCodeDestHostAdmin            10
  81. #define kIcmpCodeCommAdminFilter        13
  82. #define kIcmpCodeNone                    64    // not a valid type code
  83.  
  84. // UDP header
  85. struct udp_pseudo_t
  86.     {
  87.     UInt32    srcAddress;
  88.     UInt32    dstAddress;
  89.     UInt8    zero;
  90.     UInt8    protocol;
  91.     UInt16    length;
  92.     };
  93. typedef struct udp_pseudo_t udp_pseudo_t;
  94. struct udp_header_t
  95.     {
  96.     UInt16    srcPort;
  97.     UInt16    dstPort;
  98.     UInt16    messageLength;
  99.     UInt16    checksum;
  100.     UInt8    data[36];            // optional data
  101.     };
  102. typedef struct udp_header_t udp_header_t;
  103.  
  104. // TCP header
  105. struct tcp_pseudo_t
  106.     {
  107.     UInt32    srcAddress;
  108.     UInt32    dstAddress;
  109.     UInt8    zero;
  110.     UInt8    protocol;
  111.     UInt16    length;
  112.     };
  113. typedef struct tcp_pseudo_t tcp_pseudo_t;
  114. struct tcp_header_t
  115.     {
  116.     UInt16    srcPort;
  117.     UInt16    dstPort;
  118.     UInt32    seqNumber;
  119.     UInt32    ackNumber;
  120.     UInt8    hlen;            // hlen[4], reserved[6], code bits[6]
  121.     UInt8    code;
  122.     UInt16    windowSize;
  123.     UInt16    checksum;
  124.     UInt16    urgentPointer;
  125.     UInt8    options[4];        // TCP options
  126.     };
  127. typedef struct tcp_header_t tcp_header_t;
  128.  
  129. #define kCodeFIN        0x01
  130. #define kCodeSYN        0x02
  131. #define kCodeRST        0x04
  132. #define kCodePSH        0x08
  133. #define kCodeACK        0x10
  134. #define kCodeURG        0x20
  135.  
  136. #define kTCPOptionEnd    0
  137. #define kTCPOptionNop    1
  138. #define kTCPOptionMSS    2
  139.  
  140. #define kNATOptionIPMasq    0
  141. #define kNATOptionLocal     1
  142. #define kNATOptionDNS        2
  143.  
  144. #define kNATActionNone        0
  145. #define kNATActionConvert    1
  146. #define kNATActionReject    2
  147.  
  148. #endif
  149.