home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / Talk 1.0.6 / TCP Libraries / TCPTypes.unit < prev    next >
Encoding:
Text File  |  1992-04-20  |  10.0 KB  |  440 lines  |  [TEXT/PJMM]

  1. unit TCPTypes;
  2.  
  3. { This program was written by Peter N Lewis, Mar 1992 in THINK Pascal 4.0.1 }
  4.  
  5. interface
  6.  
  7. { MacTCP return Codes in the range -23000 through -23049 }
  8.     const
  9.         inProgress = 1;                            { I/O in progress }
  10.  
  11.         ipBadLapErr = -23000;                    { bad network configuration }
  12.         ipBadCnfgErr = -23001;                { bad IP configuration error }
  13.         ipNoCnfgErr = -23002;                    { missing IP or LAP configuration error }
  14.         ipLoadErr = -23003;                    { error in MacTCP load }
  15.         ipBadAddr = -23004;                    { error in getting address }
  16.         connectionClosing = -23005;            { connection is closing }
  17.         invalidLength = -23006;
  18.         connectionExists = -23007;            { request conflicts with existing connection }
  19.         connectionDoesntExist = -23008;        { connection does not exist }
  20.         insufficientResources = -23009;        { insufficient resources to perform request }
  21.         invalidStreamPtr = -23010;
  22.         streamAlreadyOpen = -23011;
  23.         connectionTerminated = -23012;
  24.         invalidBufPtr = -23013;
  25.         invalidRDS = -23014;
  26.         invalidWDS = -23014;
  27.         openFailed = -23015;
  28.         commandTimeout = -23016;
  29.         duplicateSocket = -23017;
  30.  
  31. { Error codes from internal IP functions }
  32.         ipDontFragErr = -23032;                { Packet too large to send w/o fragmenting }
  33.         ipDestDeadErr = -23033;                { destination not responding }
  34.         ipNoFragMemErr = -23036;            { no memory to send fragmented pkt }
  35.         ipRouteErr = -23037;                    { can't route packet off-net }
  36.  
  37.         nameSyntaxErr = -23041;
  38.         cacheFault = -23042;
  39.         noResultProc = -23043;
  40.         noNameServer = -23044;
  41.         authNameErr = -23045;
  42.         noAnsErr = -23046;
  43.         dnrErr = -23047;
  44.         outOfMemory = -23048;
  45.  
  46.     const
  47.         CTRUE = $FF;
  48.         CFALSE = $00;
  49.  
  50.     type
  51.         CBOOLEAN = signedByte;
  52.         ip_addr = longInt;
  53.         tcp_port = integer;
  54.         udp_port = integer;
  55.         StreamPtr = ptr;
  56.  
  57.     type
  58.         wdsType = record            { Write block for TCP driver. }
  59.                 size: integer;                { Number of bytes. }
  60.                 buffer: Ptr;                { Pointer to bytes. }
  61.                 term: integer;                { Zero for end of blocks. }
  62.             end;
  63.         wdsPtr = ^wdsType;
  64.  
  65.         hostInfo = record
  66.                 rtnCode: longInt;
  67.                 rtnHostName: str255;
  68.                 addrs: array[1..4] of longInt;
  69.             end;
  70.         hostInfoPtr = ^hostInfo;
  71.  
  72.     const { csCodes for the TCP driver: }
  73.         TCPcsGetMyIP = 15;
  74.         ipctlLAPStats = 19;
  75.         TCPcsCreate = 30;
  76.         TCPcsPassiveOpen = 31;
  77.         TCPcsActiveOpen = 32;
  78. {    TCPcsActOpenWithData = 33;}
  79.         TCPcsSend = 34;
  80.         TCPcsNoCopyRcv = 35;
  81.         TCPcsRcvBfrReturn = 36;
  82.         TCPcsRcv = 37;
  83.         TCPcsClose = 38;
  84.         TCPcsAbort = 39;
  85.         TCPcsStatus = 40;
  86.         TCPcsExtendedStat = 41;
  87.         TCPcsRelease = 42;
  88.         TCPcsGlobalInfo = 43;
  89.  
  90.         UDPcsCreate = 20;
  91.         UDPcsRead = 21;
  92.         UDPcsBfrReturn = 22;
  93.         UDPcsWrite = 23;
  94.         UDPcsRelease = 24;
  95.         UDPcsMaxMTUSize = 25;
  96.         UDPcsStatus = 26;
  97.         UDPcsMultiCreate = 27;
  98.         UDPcsMultiSend = 28;
  99.         UDPcsMultiRead = 29;
  100.         UDPcsCtlMax = 29;
  101.  
  102.     type
  103.         TCPEventCode = integer;
  104.     const
  105.         TEC_Closing = 1;
  106.         TEC_ULPTimeout = 2;
  107.         TEC_Terminate = 3;
  108.         TEC_DataArrival = 4;
  109.         TEC_Urgent = 5;
  110.         TEC_ICMPReceived = 6;
  111.         TEC_last = 32767;
  112.  
  113.     type
  114.         UDPEventCode = integer;
  115.     const
  116.         UDPDataArrival = 1;
  117.         UDPICMPReceived = 2;
  118.         lastUDPEvent = 32767;
  119.  
  120.     type
  121.         TCPTerminateReason = integer;
  122.     const {TCPTerminateReasons: }
  123.         TTR_RemoteAbort = 2;
  124.         TTR_NetworkFailure = 3;
  125.         TTR_SecPrecMismatch = 4;
  126.         TTR_ULPTimeoutTerminate = 5;
  127.         TTR_ULPAbort = 6;
  128.         TTR_ULPClose = 7;
  129.         TTR_ServiceError = 8;
  130.         TTR_last = 32767;
  131.  
  132.     type
  133.         TCPNotifyProc = procPtr;
  134. { procedure TCPNotifyProc(tcpStream:StreamPtr; event:TCPEventCode; userDataPtr:ptr; }
  135. {                                   terminReason:TCPTerminateReason; icmpMsg:ICMPReportPtr); }
  136.  
  137.     type
  138.         TCPIOCompletionProc = procPtr;
  139. { C procedure TCPIOCompletionProc(iopb:TCPControlBlockPtr); - WHY IS THIS A C PROC???? }
  140.  
  141.     type
  142.         UDPNotifyProc = procPtr;
  143. { procedure UDPProc(udpStream:StreamPtr ; eventCode:integer;userDataPtr:ptr; icmpMsg:ICMPReportPtr) }
  144.  
  145.     type
  146.         UDPIOCompletionProc = procPtr;
  147. {procedure UDPIOCompletionProc(iopb:UDPiopb Ptr) }
  148.  
  149.     type
  150.         UDPCreatePB = record { for create and release calls }
  151.                 rcvBuff: Ptr;
  152.                 rcvBuffLen: longInt;
  153.                 notifyProc: UDPNotifyProc;
  154.                 localport: integer;
  155.                 userDataPtr: ptr;
  156.                 endingPort: udp_port;
  157.             end;
  158.  
  159.     type
  160.         UDPSendPB = record
  161.                 reserved: integer;
  162.                 remoteIP: longInt;
  163.                 remotePort: udp_port;
  164.                 wds: wdsPtr;
  165.                 checkSum: signedByte;
  166.                 sendLength: integer;
  167.                 userDataPtr: ptr;
  168.                 localPort: udp_port;
  169.             end;
  170.  
  171.     type
  172.         UDPReceivePB = record
  173.                 timeOut: integer;
  174.                 remoteIP: longInt;
  175.                 remotePort: integer;
  176.                 rcvBuff: ptr;
  177.                 rcvBuffLen: integer;
  178.                 secondTimeStamp: integer;
  179.                 userDataPtr: ptr;
  180.                 destHost: ip_addr;
  181.                 destPort: udp_port;
  182.             end;
  183.  
  184.     type
  185.         UDPMTUPB = record
  186.                 mtuSize: integer;
  187.                 remoteIP: ip_addr;
  188.                 userDataPtr: ptr;
  189.             end;
  190.  
  191.     type
  192.         UDPControlBlock = record
  193.                 fill12: array[1..6] of integer;
  194.                 ioCompletion: UDPIOCompletionProc;
  195.                 ioResult: integer;
  196.                 ioNamePtr: stringPtr;
  197.                 ioVRefNum: integer;
  198.                 ioCRefNum: integer;
  199.                 csCode: integer;
  200.                 udpStream: streamPtr;
  201.                 case integer of
  202.                     UDPcsCreate: (
  203.                             create: UDPCreatePB
  204.                     );
  205.                     UDPcsWrite: (
  206.                             send: UDPSendPB
  207.                     );
  208.                     UDPcsRead: (
  209.                             receive: UDPReceivePB
  210.                     );
  211.                     UDPcsBfrReturn: (
  212.                             return: UDPReceivePB
  213.                     );
  214.                     UDPcsMaxMTUSize: (
  215.                             mtu: UDPMTUPB
  216.                     );
  217.             end;
  218.  
  219.     const { Validity Flags }
  220.         timeOutValue = $80;
  221.         timeOutAction = $40;
  222.         typeOfService = $20;
  223.         precedence = $10;
  224.  
  225.     const { TOSFlags }
  226.         lowDelay = $01;
  227.         throughPut = $02;
  228.         reliability = $04;
  229.  
  230.     type
  231.         TCPCreatePB = packed record
  232.                 rcvBuff: ptr;
  233.                 rcvBuffLen: longInt;
  234.                 notifyProc: TCPNotifyProc;
  235.                 userDataPtr: ptr;
  236.             end;
  237.  
  238.         TCPOpenPB = packed record
  239.                 ulpTimeoutValue: byte;
  240.                 ulpTimeoutAction: byte;
  241.                 validityFalgs: byte;
  242.                 commandTimeoutValue: byte;
  243.                 remoteHost: ip_addr;
  244.                 remotePort: tcp_port;
  245.                 localHost: ip_addr;
  246.                 localPort: tcp_port;
  247.                 tosFlags: byte;
  248.                 precedence: byte;
  249.                 dontFrag: CBOOLEAN;
  250.                 timeToLive: byte;
  251.                 security: byte;
  252.                 optionCnt: byte;
  253.                 options: array[0..39] of byte;
  254.                 userDataPtr: ptr;
  255.             end;
  256.  
  257.         TCPSendPB = packed record
  258.                 ulpTimeoutValue: byte;
  259.                 ulpTimeoutAction: byte;
  260.                 validityFalgs: byte;
  261.                 pushFalg: CBOOLEAN;
  262.                 urgentFlag: CBOOLEAN;
  263.                 wds: wdsptr;
  264.                 sendFree: longInt;
  265.                 sendLength: integer;
  266.                 userDataPtr: ptr;
  267.             end;
  268.  
  269.         TCPReceivePB = packed record
  270.                 commandTimeoutValue: byte;
  271.                 filler: byte;
  272.                 markFlag: CBOOLEAN;
  273.                 urgentFlag: CBOOLEAN;
  274.                 rcvBuff: ptr;
  275.                 rcvBuffLength: integer;
  276.                 rdsPtr: ptr;
  277.                 rdsLength: integer;
  278.                 secondTimeStanmp: integer;
  279.                 userDataPtr: ptr;
  280.             end;
  281.  
  282.         TCPClosePB = packed record
  283.                 ulpTimeoutValue: byte;
  284.                 ulpTimeoutAction: byte;
  285.                 validityFlags: byte;
  286.                 userDataPtrX: ptr;   { Thats mad!  Its not on a word boundary! Parhaps a documentation bug??? }
  287.             end;
  288.  
  289.         HistoBucket = packed record
  290.                 value: integer;
  291.                 counter: longInt;
  292.             end;
  293.  
  294.     const
  295.         NumOfHistoBuckets = 7;
  296.  
  297.     type
  298.         TCPConnectionStats = packed record
  299.                 dataPktsRcvd: longInt;
  300.                 dataPktsSent: longInt;
  301.                 dataPktsResent: longInt;
  302.                 bytesRcvd: longInt;
  303.                 bytesRcvdDup: longInt;
  304.                 bytesRcvdPastWindow: longInt;
  305.                 bytesSent: longInt;
  306.                 bytesResent: longInt;
  307.                 numHistoBuckets: integer;
  308.                 sentSizeHisto: array[1..NumOfHistoBuckets] of HistoBucket;
  309.                 lastRTT: integer;
  310.                 tmrRTT: integer;
  311.                 rttVariance: integer;
  312.                 tmrRTO: integer;
  313.                 sendTries: byte;
  314.                 sourchQuenchRcvd: byte;
  315.             end;
  316.         TCPConnectionStatsPtr = ^TCPConnectionStats;
  317.  
  318.         TCPStatusPB = packed record
  319.                 ulpTimeoutValue: byte;
  320.                 ulpTimeoutAction: byte;
  321.                 unused: longInt;
  322.                 remoteHost: ip_addr;
  323.                 remotePort: tcp_port;
  324.                 localHost: ip_addr;
  325.                 localPort: tcp_port;
  326.                 tosFlags: byte;
  327.                 precedence: byte;
  328.                 connectionState: byte;
  329.                 filler: byte;
  330.                 sendWindow: integer;
  331.                 rcvWindow: integer;
  332.                 amtUnackedData: integer;
  333.                 amtUnreadData: integer;
  334.                 securityLevelPtr: ptr;
  335.                 sendUnacked: longInt;
  336.                 sendNext: longInt;
  337.                 congestionWindow: longInt;
  338.                 rcvNext: longInt;
  339.                 srtt: longInt;
  340.                 lastRTT: longInt;
  341.                 sendMaxSegSize: longInt;
  342.                 connStatPtr: TCPConnectionStatsPtr;
  343.                 userDataPtr: ptr;
  344.             end;
  345.  
  346.         TCPAbortPB = packed record
  347.                 userDataPtr: ptr;
  348.             end;
  349.  
  350.         TCPParam = packed record
  351.                 tcpRtoA: longInt;
  352.                 tcpRtoMin: longInt;
  353.                 tcpRtoMax: longInt;
  354.                 tcpMaxSegSize: longInt;
  355.                 tcpMaxConn: longInt;
  356.                 tcpMacWindow: longInt;
  357.             end;
  358.         TCPParamPtr = ^TCPParam;
  359.  
  360.         TCPStats = packed record
  361.                 tcpConnAttempts: longInt;
  362.                 tcpConnOpened: longInt;
  363.                 tcpConnAccepted: longInt;
  364.                 tcpConnClosed: longInt;
  365.                 tcpConnAborted: longInt;
  366.                 tcpOctetsIn: longInt;
  367.                 tcpOctetsOut: longInt;
  368.                 tcpOctetsInDup: longInt;
  369.                 tcpOctetsRetrans: longInt;
  370.                 tcpInputPkts: longInt;
  371.                 tcpOutputPkts: longInt;
  372.                 tcpDupPkts: longInt;
  373.                 tcpRetransPkts: longInt;
  374.             end;
  375.         TCPStatsPtr = ^TCPStats;
  376.  
  377.         StreamPtrArray = array[1..1000] of StreamPtr;
  378.         StreamPtrArrayPtr = ^StreamPtrArray;
  379.  
  380.         TCPGlobalInfoPB = packed record
  381.                 tcpParamp: TCPParamPtr;
  382.                 tcpStatsp: TCPStatsPtr;
  383.                 tcpCDBTable: StreamPtrArrayPtr;
  384.                 userDataPtr: ptr;
  385.                 maxTCPConnections: integer;
  386.             end;
  387.  
  388.         TCPGetMyIPPB = packed record
  389.                 ourAddress: ip_addr;
  390.                 ourNetMask: longInt;
  391.             end;
  392.  
  393.         TCPControlBlock = record
  394.                 qLink: QElemPtr;
  395.                 qType: INTEGER;
  396.                 ioTrap: INTEGER;
  397.                 ioCmdAddr: Ptr;
  398.                 ioCompletion: TCPIOCompletionProc; {completion routine, or NIL if none}
  399.                 ioResult: OSErr; {result code}
  400.                 ioNamePtr: StringPtr;
  401.                 ioVRefNum: INTEGER;
  402.                 ioCRefNum: INTEGER; {device refnum}
  403.                 case csCode : integer of
  404.                     TCPcsGetMyIP: (
  405.                             getmyip: TCPGetMyIPPB;
  406.                     );
  407.                     0: (
  408.                             tcpStream: StreamPtr;
  409.                             case integer of
  410.                                 TCPcsCreate: (
  411.                                         create: TCPCreatePB
  412.                                 );
  413.                                 TCPcsActiveOpen, TCPcsPassiveOpen: (
  414.                                         open: TCPOpenPB;
  415.                                 );
  416.                                 TCPcsSend: (
  417.                                         send: TCPSendPB;
  418.                                 );
  419.                                 TCPcsNoCopyRcv, TCPcsRcvBfrReturn, TCPcsRcv: (
  420.                                         receive: TCPReceivePB;
  421.                                 );
  422.                                 TCPcsClose: (
  423.                                         close: TCPClosePB;
  424.                                 );
  425.                                 TCPcsAbort: (
  426.                                         abort: TCPAbortPB;
  427.                                 );
  428.                                 TCPcsStatus: (
  429.                                         status: TCPStatusPB;
  430.                                 );
  431.                                 TCPcsGlobalInfo: (
  432.                                         globalInfo: TCPGlobalInfoPB
  433.                                 );
  434.                     );
  435.             end;
  436.         TCPControlBlockPtr = ^TCPControlBlock;
  437.  
  438. implementation
  439.  
  440. end.