int TCPLow_GetPacket(TCPINSTANCE* tcp,void* bufptr,ULONG* pLen,TCPPEER* addr) { // this method reads a packet and returns the // size of the data read and sets up the senders // address for the status routine unsigned char recvBuf[sizeof(InetAddress) + udpMaxRawData + 1]; InetAddress* srcAddr; unsigned long theSize = udpMaxRawData; Boolean gotPacket; extern otq_t* gInQueue; gotPacket = otq_get(gInQueue, recvBuf, &theSize); if (gotPacket) { theSize -= sizeof(InetAddress); memcpy(bufptr, recvBuf + sizeof(InetAddress), theSize); srcAddr = (InetAddress*) recvBuf; addr->addr = srcAddr->fHost; addr->port = srcAddr->fPort; *pLen = theSize; } else return TCP_RES_EMPTY; return TCP_RES_OK; }
int atalk_ddp_recv( unsigned handle, void *buf, unsigned len, unsigned timeout, unsigned char flags, unsigned *ttltos, unsigned *id ) { // this method reads a packet and returns the // size of the data read and sets up the senders // address for the status routine unsigned char recvBuf[sizeof(DDPAddress) + ddpMaxRawData + 1]; DDPAddress* srcAddress; unsigned long theSize = ddpMaxRawData; Boolean gotPacket; extern otq_t* gInQueue; gotPacket = otq_get(gInQueue, recvBuf, &theSize); if (gotPacket) { // there is a new packet, deal with it theSize -= sizeof(DDPAddress); memcpy(buf, recvBuf + sizeof(DDPAddress), theSize); // save the senders address srcAddress = (DDPAddress*) recvBuf; memcpy(&gSessionInfo.ip_dst, srcAddress, sizeof(DDPAddress)); } else { // there was no packet to read theSize = -1; } return theSize; }
int tcpabi_udp_recv( unsigned handle, void *buf, unsigned len, unsigned timeout, unsigned char flags, unsigned *ttltos, unsigned *id ) { // this method reads a packet and returns the // size of the data read and sets up the senders // address for the status routine unsigned char recvBuf[sizeof(InetAddress) + udpMaxRawData + 1]; AddressListStruct* addressList; InetAddress* srcAddress; unsigned long theSize = udpMaxRawData; Boolean gotPacket; extern otq_t* gInQueue; gotPacket = otq_get(gInQueue, recvBuf, &theSize); if (gotPacket) { // check to see if this is an address list packet. If it is, the transport handles // it and returns nothing to the outside world addressList = (AddressListStruct*) (recvBuf + sizeof(InetAddress)); if ( addressList->packetType == gAddressList.packetType) { AddAddressListToList(&(addressList->addressList[0]), addressList->addressCount); // we didn't get a packet that the application needs to worry about theSize = -1; } else { // there is a new packet, deal with it theSize -= sizeof(InetAddress); memcpy(buf, recvBuf + sizeof(InetAddress), theSize); // save the senders address srcAddress = (InetAddress*) recvBuf; gSessionInfo.ip_dst = srcAddress->fHost; // if this is a session packet, we need to send our address list back in // response. This will cause the address lists to propagate in the opposite direction // from the enumerate sessions packets if (addressList->packetType == dp_SESSION_PACKET_ID) { // short lastSendCount; // we first check to see how many addresses we have sent to this address // already. If we don't have any new ones, there is no point in wasting bandwidth // lastSendCount = GetSendCount(srcAddress->fHost); // if (gAddressList.addressCount > lastSendCount) { // ChangeSendCount(srcAddress->fHost, gAddressList.addressCount); tcpabi_udp_send_to_address(srcAddress, &gAddressList, sizeof(AddressListStruct)); // } } } } else { // there was no packet to read theSize = -1; } return theSize; }