home *** CD-ROM | disk | FTP | other *** search
- // =================================================================================
- // NatProcess.h ©1997 Sustainable Softworks. All rights reserved.
- // =================================================================================
- // Network Address Translation Process
- // This module encapsulates the process of converting an IP datagram
- // using Network Address Translation
- //
- // Since this module executes in the STREAMs context, instance data is
- // allocated when the STREAM is opened rather than by instantiating
- // a C++ object. For this reason, many of the module functions are
- // passed a pointer to their instance data (i.e. the table).
- // This also makes the module self contained to facilitate debugging
- // in an application context.
-
- #ifndef _H_NatProcess
- #define _H_NatProcess
- #pragma once
-
- #include "NatTable.h"
-
- // ---------------------------------------------------------------------------
- // forward function declarations [external]
- // ---------------------------------------------------------------------------
- Boolean Convert2Apparent(translationEntry_t table[], UInt8* datagram, mblk_t* mp, UInt8 option);
- UInt8 Convert2Actual(translationEntry_t table[], UInt8* datagram, mblk_t* mp, UInt8 option);
- UInt16 IpSum( UInt16* dataPtr, UInt16* endPtr);
- UInt16 AdjustIpSum( UInt16 oldSum, UInt16 oldData, UInt16 newData);
- UInt16 AdjustIpSum32( UInt16 oldSum, UInt32 oldData, UInt32 newData);
- UInt16 RemoveFromSum( UInt16 oldSum, UInt16* dataPtr, UInt16* endPtr);
- UInt16 AddToSum( UInt16 oldSum, UInt16* dataPtr, UInt16* endPtr);
- Boolean ipCheck(UInt8* datagram);
- Boolean tcpCheck(UInt8* datagram);
-
- // ---------------------------------------------------------------------------
- // • IP packet structures
- // ---------------------------------------------------------------------------
- struct ip_header_t
- {
- UInt8 hlen;
- UInt8 tos;
- UInt16 totalLength;
- UInt16 identification;
- UInt16 fragmentOffset;
- UInt8 ttl;
- UInt8 protocol;
- UInt16 checksum;
- UInt32 srcAddress;
- UInt32 dstAddress;
- };
- typedef struct ip_header_t ip_header_t;
-
- struct icmp_header_t
- {
- UInt8 type;
- UInt8 code;
- UInt16 checksum;
- UInt16 identifier; // icmp echo
- UInt16 seqNumber; // icmp echo
- UInt8 data[28]; // optional data
- // IP header + first 64 bits of datagram
- };
- typedef struct icmp_header_t icmp_header_t;
-
- #define kIcmpEchoReply 0
- #define kIcmpTypeDestUnreachable 3
- #define kIcmpTypeSourceQuench 4
- #define kIcmpTypeRedirect 5
- #define kIcmpTypeEchoRequest 8
- #define kIcmpTypeTimeExceeded 11
- #define kIcmpTypeParameterProblem 12
-
- #define rSTRN_IcmpCode 133
- #define kIcmpCodeNetworkUnreachable 0
- #define kIcmpCodeHostUnreachable 1
- #define kIcmpCodeProtocolUnreachable 2
- #define kIcmpCodePortUnreachable 3
- #define kIcmpCodeDestNetworkUnknown 6
- #define kIcmpCodeDestHostUnknown 7
- #define kIcmpCodeDestNetworkAdmin 9
- #define kIcmpCodeDestHostAdmin 10
- #define kIcmpCodeCommAdminFilter 13
- #define kIcmpCodeNone 64 // not a valid type code
-
- // UDP header
- struct udp_pseudo_t
- {
- UInt32 srcAddress;
- UInt32 dstAddress;
- UInt8 zero;
- UInt8 protocol;
- UInt16 length;
- };
- typedef struct udp_pseudo_t udp_pseudo_t;
- struct udp_header_t
- {
- UInt16 srcPort;
- UInt16 dstPort;
- UInt16 messageLength;
- UInt16 checksum;
- UInt8 data[36]; // optional data
- };
- typedef struct udp_header_t udp_header_t;
-
- // TCP header
- struct tcp_pseudo_t
- {
- UInt32 srcAddress;
- UInt32 dstAddress;
- UInt8 zero;
- UInt8 protocol;
- UInt16 length;
- };
- typedef struct tcp_pseudo_t tcp_pseudo_t;
- struct tcp_header_t
- {
- UInt16 srcPort;
- UInt16 dstPort;
- UInt32 seqNumber;
- UInt32 ackNumber;
- UInt8 hlen; // hlen[4], reserved[6], code bits[6]
- UInt8 code;
- UInt16 windowSize;
- UInt16 checksum;
- UInt16 urgentPointer;
- UInt8 options[4]; // TCP options
- };
- typedef struct tcp_header_t tcp_header_t;
-
- #define kCodeFIN 0x01
- #define kCodeSYN 0x02
- #define kCodeRST 0x04
- #define kCodePSH 0x08
- #define kCodeACK 0x10
- #define kCodeURG 0x20
-
- #define kTCPOptionEnd 0
- #define kTCPOptionNop 1
- #define kTCPOptionMSS 2
-
- #define kNATOptionIPMasq 0
- #define kNATOptionLocal 1
- #define kNATOptionDNS 2
-
- #define kNATActionNone 0
- #define kNATActionConvert 1
- #define kNATActionReject 2
-
- #endif
-