home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / TCPOOExample / TCP Libraries / TCPTypes.unit < prev   
Encoding:
Text File  |  1993-06-23  |  13.1 KB  |  565 lines  |  [TEXT/PJMM]

  1. unit TCPTypes;
  2.  
  3. { TCPTypes © Peter Lewis, Oct 1991 }
  4. { This source is Freeware }
  5.  
  6. interface
  7.  
  8. { MacTCP return Codes in the range -23000 through -23049 }
  9.     const
  10.         inProgress = 1;                            { I/O in progress }
  11.  
  12.         ipBadLapErr = -23000;                    { bad network configuration }
  13.         ipBadCnfgErr = -23001;                { bad IP configuration error }
  14.         ipNoCnfgErr = -23002;                    { missing IP or LAP configuration error }
  15.         ipLoadErr = -23003;                    { error in MacTCP load }
  16.         ipBadAddr = -23004;                    { error in getting address }
  17.         connectionClosing = -23005;            { connection is closing }
  18.         invalidLength = -23006;
  19.         connectionExists = -23007;            { request conflicts with existing connection }
  20.         connectionDoesntExist = -23008;        { connection does not exist }
  21.         insufficientResources = -23009;        { insufficient resources to perform request }
  22.         invalidStreamPtr = -23010;
  23.         streamAlreadyOpen = -23011;
  24.         connectionTerminated = -23012;
  25.         invalidBufPtr = -23013;
  26.         invalidRDS = -23014;
  27.         invalidWDS = -23014;
  28.         openFailed = -23015;
  29.         commandTimeout = -23016;
  30.         duplicateSocket = -23017;
  31.  
  32. { Error codes from internal IP functions }
  33.         ipDontFragErr = -23032;                { Packet too large to send w/o fragmenting }
  34.         ipDestDeadErr = -23033;                { destination not responding }
  35.         icmpEchoTimeoutErr = -23035;        { ICMP echo timed-out }
  36.         ipNoFragMemErr = -23036;            { no memory to send fragmented pkt }
  37.         ipRouteErr = -23037;                    { can't route packet off-net }
  38.  
  39.         nameSyntaxErr = -23041;
  40.         cacheFault = -23042;
  41.         noResultProc = -23043;
  42.         noNameServer = -23044;
  43.         authNameErr = -23045;
  44.         noAnsErr = -23046;
  45.         dnrErr = -23047;
  46.         outOfMemory = -23048;
  47.  
  48.     const
  49.         CTRUE = $FF;
  50.         CFALSE = $00;
  51.  
  52.     type
  53.         CBOOLEAN = signedByte;
  54.         CSTRING = ptr;
  55.         ipAddr = longInt;
  56.         ipPort = integer;
  57.         StreamPtr = ptr;
  58.  
  59.     type
  60.         wdsType = record            { Write block for TCP driver. }
  61.                 size: integer;                { Number of bytes. }
  62.                 buffer: Ptr;                { Pointer to bytes. }
  63.                 term: integer;                { Zero for end of blocks. }
  64.             end;
  65.         wdsPtr = ^wdsType;
  66.         wdsEntry = record
  67.                 size: integer;                { Number of bytes. }
  68.                 buffer: Ptr;                { Pointer to bytes. }
  69.             end;
  70.  
  71.         hostInfo = record
  72.                 rtnCode: longInt;
  73.                 rtnHostName: str255;
  74.                 addrs: array[1..4] of ipAddr;
  75.             end;
  76.         hostInfoPtr = ^hostInfo;
  77.  
  78.     const { csCodes for the TCP driver: }
  79.         TCPcsGetMyIP = 15;
  80.         TCPcsEchoICMP = 17;
  81.         TCPcsLAPStats = 19;
  82.         TCPcsCreate = 30;
  83.         TCPcsPassiveOpen = 31;
  84.         TCPcsActiveOpen = 32;
  85. {    TCPcsActOpenWithData = 33;}
  86.         TCPcsSend = 34;
  87.         TCPcsNoCopyRcv = 35;
  88.         TCPcsRcvBfrReturn = 36;
  89.         TCPcsRcv = 37;
  90.         TCPcsClose = 38;
  91.         TCPcsAbort = 39;
  92.         TCPcsStatus = 40;
  93.         TCPcsExtendedStat = 41;
  94.         TCPcsRelease = 42;
  95.         TCPcsGlobalInfo = 43;
  96.  
  97.         UDPcsCreate = 20;
  98.         UDPcsRead = 21;
  99.         UDPcsBfrReturn = 22;
  100.         UDPcsWrite = 23;
  101.         UDPcsRelease = 24;
  102.         UDPcsMaxMTUSize = 25;
  103.         UDPcsStatus = 26;
  104.         UDPcsMultiCreate = 27;
  105.         UDPcsMultiSend = 28;
  106.         UDPcsMultiRead = 29;
  107.         UDPcsCtlMax = 29;
  108.  
  109.     type
  110.         TCPEventCode = integer;
  111.     const
  112.         TEC_Closing = 1;
  113.         TEC_ULPTimeout = 2;
  114.         TEC_Terminate = 3;
  115.         TEC_DataArrival = 4;
  116.         TEC_Urgent = 5;
  117.         TEC_ICMPReceived = 6;
  118.         TEC_last = 32767;
  119.  
  120.     type
  121.         UDPEventCode = integer;
  122.     const
  123.         UDPDataArrival = 1;
  124.         UDPICMPReceived = 2;
  125.         lastUDPEvent = 32767;
  126.  
  127.     type
  128.         TCPTerminateReason = integer;
  129.     const {TCPTerminateReasons: }
  130.         TTR_RemoteAbort = 2;
  131.         TTR_NetworkFailure = 3;
  132.         TTR_SecPrecMismatch = 4;
  133.         TTR_ULPTimeoutTerminate = 5;
  134.         TTR_ULPAbort = 6;
  135.         TTR_ULPClose = 7;
  136.         TTR_ServiceError = 8;
  137.         TTR_last = 32767;
  138.  
  139.     type
  140.         ICMPMsgType = integer;
  141.     const
  142.         ICMP_NetUnreach = 0;
  143.         ICMP_HostUnreach = 1;
  144.         ICMP_ProtocolUnreach = 2;
  145.         ICMP_PortUnreach = 3;
  146.         ICMP_FragReqd = 4;
  147.         ICMP_SourceRouteFailed = 5;
  148.         ICMP_TimeExceeded = 6;
  149.         ICMP_ParmProblem = 7;
  150.         ICMP_MissingOption = 8;
  151.  
  152.     type
  153.         TCPNotifyProc = procPtr;
  154. { procedure TCPNotifyProc(tcpStream:StreamPtr; event:TCPEventCode; userDataPtr:ptr; }
  155. {                                   terminReason:TCPTerminateReason; icmpMsg:ICMPReportPtr); }
  156.  
  157.     type
  158.         TCPIOCompletionProc = procPtr;
  159. { C procedure TCPIOCompletionProc(iopb:TCPControlBlockPtr); - WHY IS THIS A C PROC???? }
  160.  
  161.     type
  162.         UDPNotifyProc = procPtr;
  163. { procedure UDPProc(udpStream:StreamPtr ; eventCode:integer;userDataPtr:ptr; icmpMsg:ICMPReportPtr) }
  164.  
  165.     type
  166.         UDPIOCompletionProc = procPtr;
  167. { procedure UDPIOCompletionProc(iopb:UDPiopb Ptr) }
  168.  
  169.     type
  170.         ICMPEchoNotifyProc = ProcPtr;
  171. { C procedure ICMPEchoNotifyProc(iopb:IPControlBlockPtr) }
  172. { WARNING: Ignore the docs, its a C proceudre no matter what they say }
  173.  
  174.     type
  175.         ICMPReport = record
  176.                 stream: StreamPtr;
  177.                 localHost: ipAddr;
  178.                 localPort: ipPort;
  179.                 remoteHost: ipAddr;
  180.                 remotePort: ipPort;
  181.                 reportType: ICMPMsgType;
  182.                 optionalAddlInfo: integer;
  183.                 optionalAddlInfoPtr: ptr;
  184.             end;
  185.  
  186.     const
  187.         NBP_TABLE_SIZE = 20;            { number of NBP table entries }
  188.         NBP_MAX_NAME_SIZE = 16 + 10 + 2;
  189.         ARP_TABLE_SIZE = 20;            { number of ARP table entries }
  190.  
  191.     type
  192.         nbpEntry = record
  193.                 ip_address: ipAddr;                { IP address }
  194.                 at_address: longInt;                { matching AppleTalk address }
  195.                 gateway: Boolean;                { TRUE if entry for a gateway }
  196.                 valid: Boolean;                    { TRUE if LAP address is valid }
  197.                 probing: Boolean;                { TRUE if NBP lookup pending }
  198.                 age: integer;                    { ticks since cache entry verified }
  199.                 access: integer;                    { ticks since last access }
  200.                 filler: packed array[1..116] of byte;            { for internal use only !!! }
  201.             end;
  202.         EnetAddr = record
  203.                 en_hi: integer;
  204.                 en_lo: longInt;
  205.             end;
  206.         arpEntry = record
  207.                 age: integer;            { cache aging field }
  208.                 protocol: integer;        { Protocol type }
  209.                 ip_address: ipAddr;        { IP address }
  210.                 en_address: EnetAddr;        { matching Ethernet address }
  211.             end;
  212.         AddrXlation = record
  213.                 case integer of
  214.                     0: (
  215.                             arp_table: ^arpEntry
  216.                     );
  217.                     1: (
  218.                             nbp_entry: ^nbpEntry
  219.                     )
  220.             end;
  221.         LAPStats = record
  222.                 ifType: integer;
  223.                 ifString: CSTRING;
  224.                 ifMaxMTU: integer;
  225.                 ifSpeed: longInt;
  226.                 ifPhyAddrLength: integer;
  227.                 ifPhysicalAddress: CSTRING;
  228.                 addr: AddrXlation;
  229.                 slotNumber: integer;
  230.             end;
  231.         IPEchoPB = record
  232.                 dest: ipAddr;                { echo to IP address }
  233.                 data: wdsEntry;
  234.                 timeout: integer;
  235.                 options: Ptr;
  236.                 optLength: integer;
  237.                 icmpCompletion: ICMPEchoNotifyProc;
  238.                 userDataPtr: ptr;
  239.             end;
  240.         LAPStatsPB = record
  241.                 lapStatsPtr: ^LAPStats;
  242.             end;
  243.         ICMPEchoInfo = record
  244.                 params: array[1..11] of integer;
  245.                 echoRequestOut: longInt;    { time in ticks of when the echo request went out }
  246.                 echoReplyIn: longInt;        { time in ticks of when the reply was received }
  247.                 data: wdsEntry;        { data received in responce }
  248.                 options: ptr;
  249.                 userDataPtr: ptr;
  250.             end;
  251.         IPGetMyIPPB = record
  252.                 ourAddress: ipAddr;            { our IP address }
  253.                 ourNetMask: ipAddr;            { our IP net mask }
  254.             end;
  255.  
  256.         IPControlBlock = record
  257.                 qLink: QElemPtr;
  258.                 qType: INTEGER;
  259.                 ioTrap: INTEGER;
  260.                 ioCmdAddr: Ptr;
  261.                 ioCompletion: TCPIOCompletionProc; {completion routine, or NIL if none}
  262.                 ioResult: OSErr; {result code}
  263.                 ioNamePtr: StringPtr;
  264.                 ioVRefNum: INTEGER;
  265.                 ioCRefNum: INTEGER; {device refnum}
  266.                 case csCode : integer of
  267.                     TCPcsGetMyIP: (
  268.                             getmyip: IPGetMyIPPB;
  269.                     );
  270.                     TCPcsEchoICMP: (
  271.                             echo: IPEchoPB
  272.                     );
  273.                     9999: (
  274.                             echoinfo: ICMPEchoInfo
  275.                     );
  276.                     TCPcsLAPStats: (
  277.                             lapstat: LAPStatsPB
  278.                     );
  279.             end;
  280.  
  281.     type
  282.         UDPCreatePB = record { for create and release calls }
  283.                 rcvBuff: Ptr;
  284.                 rcvBuffLen: longInt;
  285.                 notifyProc: UDPNotifyProc;
  286.                 localport: ipPort;
  287.                 userDataPtr: ptr;
  288.                 endingPort: ipPort;
  289.             end;
  290.  
  291.     type
  292.         UDPSendPB = record
  293.                 reserved: integer;
  294.                 remoteIP: ipAddr;
  295.                 remotePort: ipPort;
  296.                 wds: wdsPtr;
  297.                 checkSum: signedByte;
  298.                 sendLength: integer;
  299.                 userDataPtr: ptr;
  300.                 localPort: ipPort;
  301.             end;
  302.  
  303.     type
  304.         UDPReceivePB = record
  305.                 timeOut: integer;
  306.                 remoteIP: ipAddr;
  307.                 remotePort: ipPort;
  308.                 rcvBuff: ptr;
  309.                 rcvBuffLen: integer;
  310.                 secondTimeStamp: integer;
  311.                 userDataPtr: ptr;
  312.                 destHost: ipAddr;
  313.                 destPort: ipPort;
  314.             end;
  315.  
  316.     type
  317.         UDPMTUPB = record
  318.                 mtuSize: integer;
  319.                 remoteIP: ipAddr;
  320.                 userDataPtr: ptr;
  321.             end;
  322.  
  323.     type
  324.         UDPControlBlock = record
  325.                 qLink: QElemPtr;
  326.                 qType: INTEGER;
  327.                 ioTrap: INTEGER;
  328.                 ioCmdAddr: Ptr;
  329.                 ioCompletion: UDPIOCompletionProc;
  330.                 ioResult: OSErr;
  331.                 ioNamePtr: stringPtr;
  332.                 ioVRefNum: integer;
  333.                 ioCRefNum: integer;
  334.                 csCode: integer;
  335.                 udpStream: streamPtr;
  336.                 case integer of
  337.                     UDPcsCreate: (
  338.                             create: UDPCreatePB
  339.                     );
  340.                     UDPcsWrite: (
  341.                             send: UDPSendPB
  342.                     );
  343.                     UDPcsRead: (
  344.                             receive: UDPReceivePB
  345.                     );
  346.                     UDPcsBfrReturn: (
  347.                             return: UDPReceivePB
  348.                     );
  349.                     UDPcsMaxMTUSize: (
  350.                             mtu: UDPMTUPB
  351.                     );
  352.             end;
  353.  
  354.     const { Validity Flags }
  355.         timeOutValue = $80;
  356.         timeOutAction = $40;
  357.         typeOfService = $20;
  358.         precedence = $10;
  359.  
  360.     const { TOSFlags }
  361.         lowDelay = $01;
  362.         throughPut = $02;
  363.         reliability = $04;
  364.  
  365.     type
  366.         TCPCreatePB = packed record
  367.                 rcvBuff: ptr;
  368.                 rcvBuffLen: longInt;
  369.                 notifyProc: TCPNotifyProc;
  370.                 userDataPtr: ptr;
  371.             end;
  372.  
  373.         TCPOpenPB = packed record
  374.                 ulpTimeoutValue: byte;
  375.                 ulpTimeoutAction: byte;
  376.                 validityFalgs: byte;
  377.                 commandTimeoutValue: byte;
  378.                 remoteHost: ipAddr;
  379.                 remotePort: ipPort;
  380.                 localHost: ipAddr;
  381.                 localPort: ipPort;
  382.                 tosFlags: byte;
  383.                 precedence: byte;
  384.                 dontFrag: CBOOLEAN;
  385.                 timeToLive: byte;
  386.                 security: byte;
  387.                 optionCnt: byte;
  388.                 options: array[0..39] of byte;
  389.                 userDataPtr: ptr;
  390.             end;
  391.  
  392.         TCPSendPB = packed record
  393.                 ulpTimeoutValue: byte;
  394.                 ulpTimeoutAction: byte;
  395.                 validityFalgs: byte;
  396.                 pushFalg: byte;
  397.                 urgentFlag: CBOOLEAN;
  398.                 wds: wdsptr;
  399.                 sendFree: longInt;
  400.                 sendLength: integer;
  401.                 userDataPtr: ptr;
  402.             end;
  403.  
  404.         TCPReceivePB = packed record
  405.                 commandTimeoutValue: byte;
  406.                 filler: byte;
  407.                 markFlag: CBOOLEAN;
  408.                 urgentFlag: CBOOLEAN;
  409.                 rcvBuff: ptr;
  410.                 rcvBuffLength: integer;
  411.                 rdsPtr: ptr;
  412.                 rdsLength: integer;
  413.                 secondTimeStamp: integer;
  414.                 userDataPtr: ptr;
  415.             end;
  416.  
  417.         TCPClosePB = packed record
  418.                 ulpTimeoutValue: byte;
  419.                 ulpTimeoutAction: byte;
  420.                 validityFlags: byte;
  421.                 userDataPtrX: ptr;   { Thats mad!  Its not on a word boundary! Parhaps a documentation bug??? }
  422.             end;
  423.  
  424.         HistoBucket = packed record
  425.                 value: integer;
  426.                 counter: longInt;
  427.             end;
  428.  
  429.     const
  430.         NumOfHistoBuckets = 7;
  431.  
  432.     type
  433.         TCPConnectionStats = packed record
  434.                 dataPktsRcvd: longInt;
  435.                 dataPktsSent: longInt;
  436.                 dataPktsResent: longInt;
  437.                 bytesRcvd: longInt;
  438.                 bytesRcvdDup: longInt;
  439.                 bytesRcvdPastWindow: longInt;
  440.                 bytesSent: longInt;
  441.                 bytesResent: longInt;
  442.                 numHistoBuckets: integer;
  443.                 sentSizeHisto: array[1..NumOfHistoBuckets] of HistoBucket;
  444.                 lastRTT: integer;
  445.                 tmrRTT: integer;
  446.                 rttVariance: integer;
  447.                 tmrRTO: integer;
  448.                 sendTries: byte;
  449.                 sourceQuenchRcvd: byte;
  450.             end;
  451.         TCPConnectionStatsPtr = ^TCPConnectionStats;
  452.  
  453.         TCPStatusPB = packed record
  454.                 ulpTimeoutValue: byte;
  455.                 ulpTimeoutAction: byte;
  456.                 unused: longInt;
  457.                 remoteHost: ipAddr;
  458.                 remotePort: ipPort;
  459.                 localHost: ipAddr;
  460.                 localPort: ipPort;
  461.                 tosFlags: byte;
  462.                 precedence: byte;
  463.                 connectionState: byte;
  464.                 filler: byte;
  465.                 sendWindow: integer;
  466.                 rcvWindow: integer;
  467.                 amtUnackedData: integer;
  468.                 amtUnreadData: integer;
  469.                 securityLevelPtr: ptr;
  470.                 sendUnacked: longInt;
  471.                 sendNext: longInt;
  472.                 congestionWindow: longInt;
  473.                 rcvNext: longInt;
  474.                 srtt: longInt;
  475.                 lastRTT: longInt;
  476.                 sendMaxSegSize: longInt;
  477.                 connStatPtr: TCPConnectionStatsPtr;
  478.                 userDataPtr: ptr;
  479.             end;
  480.  
  481.         TCPAbortPB = packed record
  482.                 userDataPtr: ptr;
  483.             end;
  484.  
  485.         TCPParam = packed record
  486.                 tcpRTOA: StringPtr;
  487.                 tcpRTOMin: longInt;
  488.                 tcpRTOMax: longInt;
  489.                 tcpMaxSegSize: longInt;
  490.                 tcpMaxConn: longInt;
  491.                 tcpMaxWindow: longInt;
  492.             end;
  493.         TCPParamPtr = ^TCPParam;
  494.  
  495.         TCPStats = packed record
  496.                 tcpConnAttempts: longInt;
  497.                 tcpConnOpened: longInt;
  498.                 tcpConnAccepted: longInt;
  499.                 tcpConnClosed: longInt;
  500.                 tcpConnAborted: longInt;
  501.                 tcpOctetsIn: longInt;
  502.                 tcpOctetsOut: longInt;
  503.                 tcpOctetsInDup: longInt;
  504.                 tcpOctetsRetrans: longInt;
  505.                 tcpInputPackets: longInt;
  506.                 tcpOutputPkts: longInt;
  507.                 tcpDupPkts: longInt;
  508.                 tcpRetransPkts: longInt;
  509.             end;
  510.         TCPStatsPtr = ^TCPStats;
  511.  
  512.         StreamPtrArray = array[1..1000] of StreamPtr;
  513.         StreamPtrArrayPtr = ^StreamPtrArray;
  514.  
  515.         TCPGlobalInfoPB = packed record
  516.                 tcpParamp: TCPParamPtr;
  517.                 tcpStatsp: TCPStatsPtr;
  518.                 tcpCDBTable: StreamPtrArrayPtr;
  519.                 userDataPtr: ptr;
  520.                 maxTCPConnections: integer;
  521.             end;
  522.  
  523.         TCPControlBlock = record
  524.                 qLink: QElemPtr;
  525.                 qType: INTEGER;
  526.                 ioTrap: INTEGER;
  527.                 ioCmdAddr: Ptr;
  528.                 ioCompletion: TCPIOCompletionProc; {completion routine, or NIL if none}
  529.                 ioResult: OSErr; {result code}
  530.                 ioNamePtr: StringPtr;
  531.                 ioVRefNum: INTEGER;
  532.                 ioCRefNum: INTEGER; {device refnum}
  533.                 csCode: integer;
  534.                 tcpStream: StreamPtr;
  535.                 case integer of
  536.                     TCPcsCreate: (
  537.                             create: TCPCreatePB
  538.                     );
  539.                     TCPcsActiveOpen, TCPcsPassiveOpen: (
  540.                             open: TCPOpenPB;
  541.                     );
  542.                     TCPcsSend: (
  543.                             send: TCPSendPB;
  544.                     );
  545.                     TCPcsNoCopyRcv, TCPcsRcvBfrReturn, TCPcsRcv: (
  546.                             receive: TCPReceivePB;
  547.                     );
  548.                     TCPcsClose: (
  549.                             close: TCPClosePB;
  550.                     );
  551.                     TCPcsAbort: (
  552.                             abort: TCPAbortPB;
  553.                     );
  554.                     TCPcsStatus: (
  555.                             status: TCPStatusPB;
  556.                     );
  557.                     TCPcsGlobalInfo: (
  558.                             globalInfo: TCPGlobalInfoPB
  559.                     );
  560.             end;
  561.         TCPControlBlockPtr = ^TCPControlBlock;
  562.  
  563. implementation
  564.  
  565. end.