AmendHub

Download:

jcs

/

wallops

/

amendments

/

30

tcp: Sync with libjcs


jcs made amendment 30 over 2 years ago
--- MacTCP.h Thu Sep 17 17:48:48 2020 +++ MacTCP.h Thu Feb 10 14:49:09 2022 @@ -533,6 +533,20 @@ enum { NumOfHistoBuckets = 7 }; +enum { + ConnectionStateClosed = 0, + ConnectionStateListening = 2, + ConnectionStateSYNReceived = 4, + ConnectionStateSYNSent = 6, + ConnectionStateEstablished = 8, + ConnectionStateFINWait1 = 10, + ConnectionStateFINWait2 = 12, + ConnectionStateCloseWait = 14, + ConnectionStateClosing = 16, + ConnectionStateLastAck = 18, + ConnectionStateTimeWait = 20 +}; + struct TCPConnectionStats { unsigned long dataPktsRcvd; unsigned long dataPktsSent; --- tcp.c Wed Feb 2 12:54:31 2022 +++ tcp.c Thu Feb 10 14:48:39 2022 @@ -1,7 +1,6 @@ #include <stdio.h> #include <string.h> #include "tcp.h" -#include "util.h" #define RCV_BUFFER_SIZE 1024 #define TCP_BUFFER_SIZE 8192 @@ -28,9 +27,8 @@ _TCPInit(void) pb.ioParam.ioPermssn = fsCurPerm; osErr = PBOpen(&pb, false); - if (noErr == osErr) { + if (noErr == osErr) gIPPDriverRefNum = pb.ioParam.ioRefNum; - } return osErr; } @@ -40,12 +38,12 @@ _TCPGetOurIP(ip_addr *ip, long *netMask) { OSErr osErr; GetAddrParamBlock pb; - int i; memset(&pb, 0, sizeof(pb)); pb.csCode = ipctlGetAddr; pb.ioCRefNum = gIPPDriverRefNum; + pb.ioResult = 1; osErr = PBControl((ParmBlkPtr)&pb, true); while (pb.ioResult > 0) @@ -71,9 +69,10 @@ _TCPCreate(TCPiopb *pb, StreamPtr *stream, Ptr rcvBufP memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPCreate; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPCreate; + pb->ioResult = 1; pb->csParam.create.rcvBuff = rcvBufPtr; pb->csParam.create.rcvBuffLen = rcvBufLen; @@ -99,17 +98,18 @@ _TCPPassiveOpen(TCPiopb *pb, StreamPtr stream, ip_addr memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPPassiveOpen; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPPassiveOpen; pb->tcpStream = stream; + pb->ioResult = 1; - pb->csParam.open.ulpTimeoutValue = 0; - pb->csParam.open.ulpTimeoutAction = 1; + pb->csParam.open.ulpTimeoutAction = 1; /* abort half-open connection */ + pb->csParam.open.ulpTimeoutValue = 5; /* after 5 seconds */ pb->csParam.open.validityFlags = 0xC0; - pb->csParam.open.commandTimeoutValue = 30; - pb->csParam.open.remoteHost = *remoteIP; - pb->csParam.open.remotePort = *remotePort; + pb->csParam.open.commandTimeoutValue = 0; + pb->csParam.open.remoteHost = 0; + pb->csParam.open.remotePort = 0; pb->csParam.open.localHost = 0; pb->csParam.open.localPort = *localPort; pb->csParam.open.tosFlags = 0; @@ -123,10 +123,13 @@ _TCPPassiveOpen(TCPiopb *pb, StreamPtr stream, ip_addr pb->csParam.open.userDataPtr = userData; osErr = PBControl((ParmBlkPtr) pb, async); - if (!async && (noErr == osErr)) { - *remoteIP = pb->csParam.open.remoteHost; - *remotePort = pb->csParam.open.remotePort; - *localIP = pb->csParam.open.localHost; + if (!async && (osErr == noErr)) { + if (remoteIP) + *remoteIP = pb->csParam.open.remoteHost; + if (remotePort) + *remotePort = pb->csParam.open.remotePort; + if (localIP) + *localIP = pb->csParam.open.localHost; *localPort = pb->csParam.open.localPort; } @@ -144,10 +147,11 @@ _TCPActiveOpen(TCPiopb *pb, StreamPtr stream, ip_addr memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPActiveOpen; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPActiveOpen; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.open.ulpTimeoutValue = 30; pb->csParam.open.ulpTimeoutAction = 1; @@ -185,10 +189,11 @@ _TCPSend(TCPiopb *pb, StreamPtr stream, wdsEntry *wdsP { memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPSend; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPSend; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.send.ulpTimeoutValue = 30; pb->csParam.send.ulpTimeoutAction = 1; @@ -212,10 +217,11 @@ _TCPNoCopyRcv(TCPiopb *pb, StreamPtr stream, Ptr rdsPt memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPNoCopyRcv; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPNoCopyRcv; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.receive.commandTimeoutValue = 30; pb->csParam.receive.urgentFlag = 0; @@ -236,10 +242,11 @@ _TCPRcv(TCPiopb *pb, StreamPtr stream, Ptr rcvBufPtr, memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPRcv; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPRcv; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.receive.commandTimeoutValue = 30; pb->csParam.receive.urgentFlag = 0; @@ -261,10 +268,11 @@ _TCPBfrReturn(TCPiopb *pb, StreamPtr stream, Ptr rdsPt { memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPRcvBfrReturn; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPRcvBfrReturn; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.receive.rdsPtr = rdsPtr; pb->csParam.receive.userDataPtr = userData; @@ -278,10 +286,11 @@ _TCPClose(TCPiopb *pb, StreamPtr stream, Ptr userData, { memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPClose; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPClose; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.close.ulpTimeoutValue = 30; pb->csParam.close.ulpTimeoutAction = 1; @@ -297,10 +306,11 @@ _TCPAbort(TCPiopb *pb, StreamPtr stream, Ptr userData, { memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPAbort; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPAbort; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.abort.userDataPtr = userData; @@ -315,11 +325,12 @@ _TCPStatus(TCPiopb *pb, StreamPtr stream, struct TCPSt memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPStatus; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPStatus; pb->tcpStream = stream; pb->csParam.status.userDataPtr = userData; + pb->ioResult = 1; osErr = PBControl((ParmBlkPtr)pb, async); if (!async && (noErr == osErr)) { @@ -337,10 +348,11 @@ _TCPRelease(TCPiopb *pb, StreamPtr stream, Ptr userDat memset(pb, 0, sizeof(*pb)); + pb->csCode = TCPRelease; pb->ioCompletion = ioCompletion; pb->ioCRefNum = gIPPDriverRefNum; - pb->csCode = TCPRelease; pb->tcpStream = stream; + pb->ioResult = 1; pb->csParam.status.userDataPtr = userData; @@ -349,6 +361,27 @@ _TCPRelease(TCPiopb *pb, StreamPtr stream, Ptr userDat return osErr; } +OSErr +_UDPMaxMTUSize(UDPiopb *pb, short *mtu) +{ + OSErr osErr; + + memset(pb, 0, sizeof(*pb)); + + pb->csCode = UDPMaxMTUSize; + pb->ioCRefNum = gIPPDriverRefNum; + pb->ioResult = 1; + + pb->csParam.mtu.remoteHost = (ip_addr)0; + + osErr = PBControl((ParmBlkPtr)pb, false); + + if (osErr == noErr) + *mtu = pb->csParam.mtu.mtuSize; + + return osErr; +} + /* convenience functions */ static pascal void @@ -375,7 +408,7 @@ TCPResolveName(char **name, unsigned long *ipAddress) if (osErr == cacheFault) { /* StrToAddrMarkDone will set done when DNS resolution finishes */ while (!done) - SystemTask(); + ; } if ((aHostInfo.rtnCode == noErr) || (aHostInfo.rtnCode == cacheFault)) { --- tcp.h Fri Nov 13 14:05:09 2020 +++ tcp.h Thu Feb 10 14:48:44 2022 @@ -47,6 +47,8 @@ OSErr _TCPStatus(TCPiopb *pb, StreamPtr stream, struct OSErr _TCPRelease(TCPiopb *pb, StreamPtr stream, Ptr userData, TCPIOCompletionProc ioCompletion, Boolean async); +OSErr _UDPMaxMTUSize(UDPiopb *pb, short *mtu); + OSErr TCPResolveName(char **name, unsigned long *ipAddress); long ip2long(char *ip);