Пример #1
0
/**
 * |SetJsObject| is an internal function used by |BroadcastSystemMessage| only
 */
static bool
SetJsObject(JSContext* aContext,
            const BluetoothValue& aValue,
            JS::Handle<JSObject*> aObj)
{
  MOZ_ASSERT(aContext && aObj);

  if (aValue.type() != BluetoothValue::TArrayOfBluetoothNamedValue) {
    BT_WARNING("SetJsObject: Invalid parameter type");
    return false;
  }

  const nsTArray<BluetoothNamedValue>& arr =
    aValue.get_ArrayOfBluetoothNamedValue();

  for (uint32_t i = 0; i < arr.Length(); i++) {
    JS::Rooted<JS::Value> val(aContext);
    const BluetoothValue& v = arr[i].value();

    switch(v.type()) {
       case BluetoothValue::TBluetoothAddress: {
        nsAutoString addressStr;
        AddressToString(v.get_BluetoothAddress(), addressStr);

        JSString* jsData = JS_NewUCStringCopyN(aContext,
                                               addressStr.BeginReading(),
                                               addressStr.Length());
        NS_ENSURE_TRUE(jsData, false);
        val.setString(jsData);
        break;
      }
      case BluetoothValue::TnsString: {
        JSString* jsData = JS_NewUCStringCopyN(aContext,
                                     v.get_nsString().BeginReading(),
                                     v.get_nsString().Length());
        NS_ENSURE_TRUE(jsData, false);
        val.setString(jsData);
        break;
      }
      case BluetoothValue::Tuint32_t:
        val.setInt32(v.get_uint32_t());
        break;
      case BluetoothValue::Tbool:
        val.setBoolean(v.get_bool());
        break;
      default:
        BT_WARNING("SetJsObject: Parameter is not handled");
        break;
    }

    if (!JS_SetProperty(aContext, aObj,
                        NS_ConvertUTF16toUTF8(arr[i].name()).get(),
                        val)) {
      BT_WARNING("Failed to set property");
      return false;
    }
  }

  return true;
}
Пример #2
0
void
UnregisterBluetoothSignalHandler(const BluetoothAddress& aAddress,
                                 BluetoothSignalObserver* aHandler)
{
  nsAutoString path;
  AddressToString(aAddress, path);

  UnregisterBluetoothSignalHandler(path, aHandler);
}
Пример #3
0
void UoClientThread::run()
{
    Client* client = NULL;

    {
        struct sockaddr client_addr = _sck.peer_address();
        struct sockaddr host_addr;
        socklen_t host_addrlen = sizeof host_addr;

        PolLock lck;
        client = new Client( uo_client_interface, _def.encryption );
        client->csocket = _sck.release_handle(); // client cleans up its socket.
        client->listen_port = _def.port;
		if ( _def.aosresist )
			client->aosresist = true; // UOCLient.cfg Entry
		// Added null setting for pre-char selection checks using NULL validation
		client->acct = NULL;
        memcpy( &client->ipaddr, &client_addr, sizeof client->ipaddr );

        clients.push_back( client );
        CoreSetSysTrayToolTip( tostring(clients.size()) + " clients connected", ToolTipPrioritySystem );
        cout << "Client connected from " << AddressToString( &client_addr )
                << " (" << clients.size() << " connections)"
                << endl;
        string ifdesc = "";
        if (getsockname( client->csocket, &host_addr, &host_addrlen ) == 0)
        {
            // cout << "host address: " << AddressToString( &host_addr ) << endl;
            ifdesc = " on interface ";
            ifdesc += AddressToString( &host_addr );
        }
        Log( "Client#%lu connected from %s (%d connections)%s\n", 
                client->instance_,
                AddressToString( &client_addr ),
                clients.size(),
                ifdesc.c_str() );
    }

    client_io_thread( client );
}
CTString CCommunicationInterface::Server_GetClientName(INDEX iClient)
{
  CTSingleLock slComm(&cm_csComm, TRUE);
  ASSERT(iClient>=0 && iClient<SERVER_CLIENTS);

  if (iClient==SERVER_LOCAL_CLIENT) {
    return TRANS("Local machine");
  }

  cm_aciClients[iClient].ci_strAddress = AddressToString(cm_aciClients[iClient].ci_adrAddress.adr_ulAddress);

  return cm_aciClients[iClient].ci_strAddress;
};
Пример #5
0
int discover1(IFADDR *ifaddr, XbeeAddrList &addrs, int timeout)
{
    uint8_t txBuf[1024]; // BUG: get rid of this magic number!
    uint8_t rxBuf[1024]; // BUG: get rid of this magic number!
    SOCKADDR_IN bcastaddr;
    SOCKADDR_IN addr;
    SOCKET sock;
    int cnt;
    
    /* create a broadcast socket */
    if (OpenBroadcastSocket(DEF_DISCOVER_PORT, &sock) != 0) {
        printf("error: OpenBroadcastSocket failed\n");
        return -2;
    }
        
    /* build a broadcast address */
    bcastaddr = ifaddr->bcast;
    bcastaddr.sin_port = htons(DEF_DISCOVER_PORT);
    
    /* send the broadcast packet */
    sprintf((char *)txBuf, "Me here! Ignore this message.\n");
    if ((cnt = SendSocketDataTo(sock, txBuf, strlen((char *)txBuf), &bcastaddr)) != (int)strlen((char *)txBuf)) {
        perror("error: SendSocketDataTo failed");
        CloseSocket(sock);
        return -1;
    }

    /* receive Xbee responses */
    while (SocketDataAvailableP(sock, timeout)) {

        /* get the next response */
        memset(rxBuf, 0, sizeof(rxBuf));
        if ((cnt = ReceiveSocketDataAndAddress(sock, rxBuf, sizeof(rxBuf) - 1, &addr)) < 0) {
            printf("error: ReceiveSocketData failed\n");
            CloseSocket(sock);
            return -3;
        }
        rxBuf[cnt] = '\0';
        
        if (!strstr((char *)rxBuf, "Me here!"))
            printf("from %s got: %s", AddressToString(&addr), rxBuf);
    }
    
    /* close the socket */
    CloseSocket(sock);
    
    /* return successfully */
    return 0;
}
Пример #6
0
bool CTcpSocket::Listen(int n)
{
    struct sockaddr_in nAddress;
    if (!GetAddress(m_strHost, m_nPort, nAddress))
        return false;
    
    if (bind(m_nFd, (struct sockaddr*)&nAddress, sizeof(nAddress)) != 0)
    {
        AILOG_ERROR() << "Address=" << inet_ntoa(nAddress.sin_addr) << ":" << ntohs(nAddress.sin_port);
        AILOG_ERROR() << AddressToString() << " bind socket error:" << LastErrorMessage();
        return false;
    }
    
    return listen(m_nFd, n) != -1;
}
Пример #7
0
bool BlockExplorer::switchTo(const QString& query)
{
    bool IsOk;
    int64_t AsInt = query.toInt(&IsOk);
    // If query is integer, get hash from height
    if (IsOk && AsInt >= 0 && AsInt <= chainActive.Tip()->nHeight) {
        std::string hex = getexplorerBlockHash(AsInt);
        uint256 hash = uint256S(hex);
        CBlockIndex* pIndex = mapBlockIndex[hash];
        if (pIndex) {
            setBlock(pIndex);
            return true;
        }
    }

    // If the query is not an integer, assume it is a block hash
    uint256 hash = uint256S(query.toUtf8().constData());

    // std::map<uint256, CBlockIndex*>::iterator iter = mapBlockIndex.find(hash);
    BlockMap::iterator iter = mapBlockIndex.find(hash);
    if (iter != mapBlockIndex.end()) {
        setBlock(iter->second);
        return true;
    }

    // If the query is neither an integer nor a block hash, assume a transaction hash
    CTransaction tx;
    uint256 hashBlock = 0;
    if (GetTransaction(hash, tx, hashBlock, true)) {
        setContent(TxToString(hashBlock, tx));
        return true;
    }

    // If the query is not an integer, nor a block hash, nor a transaction hash, assume an address
    CBitcoinAddress Address;
    Address.SetString(query.toUtf8().constData());
    if (Address.IsValid()) {
        std::string Content = AddressToString(Address);
        if (Content.empty())
            return false;
        setContent(Content);
        return true;
    }

    return false;
}
Пример #8
0
VOID CRenoCommandFrame::OnResolved(INT nErrorCode,LPADDRINFO info)
{
	if(nErrorCode || !info)
	{
		switch(nErrorCode)
		{
		case NULL:
			PrintFormat(TEXT("* Failed to resolve name\r\n"));
			break;

		case WSATRY_AGAIN:
			PrintFormat(TEXT("* Failed to resolve name. Temporary error occurred during host name resolution\r\n"));
			break;

		case WSANO_RECOVERY:
			PrintFormat(TEXT("* Failed to resolve name. Non-recoverable error occurred during database lookup\r\n"));
			break;

		case WSAHOST_NOT_FOUND:
			PrintFormat(TEXT("* Failed to resolve name. The specified name could not be found in the database\r\n"));
			break;

		case WSATYPE_NOT_FOUND:
			PrintFormat(TEXT("* Failed to resolve name. The specified class could not be found in the database\r\n"));
			break;

		default:
			PrintFormat(TEXT("* Failed to resolve name. Resolution error %d\r\n"),nErrorCode);
			break;
		}

		CRenoSocketWnd::OnResolved(nErrorCode,NULL);
	}
	else
	{
		// Tell the user the resolved address that we are connecting to
		TCHAR address[NI_MAXHOST];
		AddressToString(info->ai_addr,info->ai_addrlen,address,sizeof(address)/sizeof(TCHAR));
		PrintFormat(TEXT("* Connecting to %s\r\n"),address);

		// This will actualy call connect
		CRenoSocketWnd::OnResolved(nErrorCode,info);
	}
}
Пример #9
0
void Listen::AcceptClient() {
  try {
    auto address = make_shared<sockaddr_in>();
    auto client_socket_tcp = Accept(*listener_tcp_, address);
    //Connecting to client receiver
    SetAddressPort(*address, client_port_);
    auto client_socket_udp = ConnectTo(*address, SOCK_DGRAM, IPPROTO_UDP);

    if (clients_.Push(move(client_socket_tcp), move(client_socket_udp))) {
      Error::LogToFile("Connected: "+AddressToString(*address));
    } else {
      //Server doesn't accept
    }
  } catch (AcceptException e) {
    if (e.code() != WSAEINTR) {//Happens when I close the  listening socket to force the accept to return.
      Display::Console::PrintError(e.what());
      Error::LogToFile(e.what(), e.code(), e.message());
    }
  }
}
Пример #10
0
DWORD CBTTestDlg::OnConnectionComplete(BYTE nStatus, USHORT nConnectionHandle, BYTE BD_ADDR[FBT_HCI_BDADDR_SIZE], BYTE nLinkType, BYTE nEncryptionMode)
{
	if (nStatus==0)
	{
		CString szDevice;
		AddressToString(BD_ADDR, szDevice);

		PBTDevice pBTDevice=NULL;
		int nDevice=FindDeviceByAddress(BD_ADDR);
		if (nDevice==-1)
		{
			int nDevice=m_lbDevices.AddString(szDevice);
			if (nDevice!=LB_ERR)
			{
				pBTDevice=(PBTDevice)malloc(sizeof(BTDevice));
				memset(pBTDevice, 0, sizeof(BTDevice));
				m_lbDevices.SetItemData(nDevice, (DWORD)pBTDevice);

			}

		}

		else
		{
			pBTDevice=(PBTDevice)m_lbDevices.GetItemData(nDevice);

		}

		memcpy(pBTDevice->BD_ADDR, BD_ADDR, FBT_HCI_BDADDR_SIZE);
		pBTDevice->ConnectionHandle=nConnectionHandle;

		CString szMsg;
		szMsg.Format("Connected to %s", szDevice);
		MessageBox(szMsg, "Device connected", MB_OK);

	}

	return 0;

}
Пример #11
0
QString QAutoGenDialog::GetRandomAddress(const QString & strParam)
{
	QString strAddress;
	Address sAddress;
	std::map<QString, std::vector<unsigned int> >::iterator iterRecords = m_mapRandomRecords.find(strParam);
	std::map<QString, Rect>::iterator iterMapSelection = m_mapMapSelections.find(strParam);
	unsigned int i, iMaxRetries = 3, iRecord, iShapePoint;
	float fProgress;
	MapRecord * pRecord;

	if (iterRecords == m_mapRandomRecords.end())
	{
		iterRecords = m_mapRandomRecords.find(OTHERADDRESSES);
		iterMapSelection = m_mapMapSelections.find(OTHERADDRESSES);
		if (iterRecords == m_mapRandomRecords.end())
			return strAddress;
	}

	// choose a random location in this region
	if (iterRecords->second.empty())
		return strAddress;

	for (i = 0; i < iMaxRetries; i++)
	{
		iRecord = RandUInt(0, iterRecords->second.size());
		pRecord = g_pMapDB->GetRecord(iterRecords->second[iRecord]);
		if (pRecord->nShapePoints > 1)
		{
			iShapePoint = RandUInt(0, pRecord->nShapePoints - 1);
			fProgress = (float)RandDouble(0., 1.);
			if (g_pMapDB->AddressFromRecord(&sAddress, iterRecords->second[iRecord], iShapePoint, fProgress))
			{
				strAddress = AddressToString(&sAddress);
				if (StringToAddress(strAddress, &sAddress) && sAddress.iRecord != (unsigned)-1 && iterMapSelection->second.intersectRect(pRecord->rBounds))
					break;
			}
		}
	}
	return strAddress;
}
Пример #12
0
std::string IPV4Address::ToString() const {
  return AddressToString(m_address);
}
BOOL CCommunicationInterface::Server_Update()
{

  CTSingleLock slComm(&cm_csComm, TRUE);
	CPacket *ppaPacket;
	CPacket *ppaPacketCopy;
	CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();
	INDEX iClient;

	// transfer packets for the local client
	if (cm_ciLocalClient.ci_bUsed && cm_ciLocalClient.ci_pciOther != NULL) {
		cm_ciLocalClient.ExchangeBuffers();
	};

	cm_aciClients[0].UpdateOutputBuffers();

	// if not just playing single player
	if (cci_bServerInitialized) {
		Broadcast_Update_t();
		// for each client transfer packets from the output buffer to the master output buffer
		for (iClient=1; iClient<SERVER_CLIENTS; iClient++) {
			CClientInterface &ci = cm_aciClients[iClient];
			// if not connected
			if (!ci.ci_bUsed) {
				// skip it
				continue;
			}
			// update its buffers, if a reliable packet is overdue (has not been delivered too long)
			// disconnect the client
			if (ci.UpdateOutputBuffers() != FALSE) {
				// transfer packets ready to be sent out to the master output buffer
				while (ci.ci_pbOutputBuffer.pb_ulNumOfPackets > 0) {
					ppaPacket = ci.ci_pbOutputBuffer.PeekFirstPacket();
					if (ppaPacket->pa_tvSendWhen < tvNow) {
						ci.ci_pbOutputBuffer.RemoveFirstPacket(FALSE);
						if (ppaPacket->pa_ubReliable & UDP_PACKET_RELIABLE) {
							ppaPacketCopy = new CPacket;
							*ppaPacketCopy = *ppaPacket;
							ci.ci_pbWaitAckBuffer.AppendPacket(*ppaPacketCopy,FALSE);
						}
						cci_pbMasterOutput.AppendPacket(*ppaPacket,FALSE);
					} else {
						break;
					}
				}
			} else {
        CPrintF(TRANSV("Unable to deliver data to client '%s', disconnecting.\n"),(const char *) AddressToString(cm_aciClients[iClient].ci_adrAddress.adr_ulAddress));
        Server_ClearClient(iClient);
        _pNetwork->ga_srvServer.HandleClientDisconected(iClient);

			}
		}

		// update broadcast output buffers
		// update its buffers
		cm_ciBroadcast.UpdateOutputBuffers();
		// transfer packets ready to be sent out to the master output buffer
		while (cm_ciBroadcast.ci_pbOutputBuffer.pb_ulNumOfPackets > 0) {
			ppaPacket = cm_ciBroadcast.ci_pbOutputBuffer.PeekFirstPacket();
			if (ppaPacket->pa_tvSendWhen < tvNow) {
				cm_ciBroadcast.ci_pbOutputBuffer.RemoveFirstPacket(FALSE);
				cci_pbMasterOutput.AppendPacket(*ppaPacket,FALSE);
			} else {
				break;
			}
		}

		// send/receive packets over the TCP/IP stack
		UpdateMasterBuffers();

		// dispatch all packets from the master input buffer to the clients' input buffers
		while (cci_pbMasterInput.pb_ulNumOfPackets > 0) {
			BOOL bClientFound;
			ppaPacket = cci_pbMasterInput.GetFirstPacket();
			bClientFound = FALSE;
			if (ppaPacket->pa_adrAddress.adr_uwID==SLASHSLASH || ppaPacket->pa_adrAddress.adr_uwID==0) {
				cm_ciBroadcast.ci_pbInputBuffer.AppendPacket(*ppaPacket,FALSE);
				bClientFound = TRUE;
			} else {
				for (iClient=0; iClient<SERVER_CLIENTS; iClient++) {
					if (ppaPacket->pa_adrAddress.adr_uwID == cm_aciClients[iClient].ci_adrAddress.adr_uwID) {
						cm_aciClients[iClient].ci_pbInputBuffer.AppendPacket(*ppaPacket,FALSE);
						bClientFound = TRUE;
						break;
					}
				}
			}
			if (!bClientFound) {
				// warn about possible attack
				extern INDEX net_bReportMiscErrors;
				if (net_bReportMiscErrors) {
					CPrintF(TRANSV("WARNING: Invalid message from: %s\n"), (const char *) AddressToString(ppaPacket->pa_adrAddress.adr_ulAddress));
				}
			}
 		}

		for (iClient=1; iClient<SERVER_CLIENTS; iClient++) {
			cm_aciClients[iClient].UpdateInputBuffers();
		}

		
	}
	cm_aciClients[0].UpdateInputBuffers();
	cm_ciLocalClient.UpdateInputBuffers();
	cm_ciBroadcast.UpdateInputBuffersBroadcast();
	Broadcast_Update_t();

	return TRUE;
};
// update master UDP socket and route its messages
void CCommunicationInterface::UpdateMasterBuffers() 
{

	UBYTE aub[MAX_PACKET_SIZE];
	CAddress adrIncomingAddress;
	SOCKADDR_IN sa;
	socklen_t size = sizeof(sa);
	SLONG slSizeReceived;
	SLONG slSizeSent;
	BOOL bSomethingDone;
	CPacket* ppaNewPacket;
	CTimerValue tvNow;

	if (cci_bBound) {
		// read from the socket while there is incoming data
		do {

			// initially, nothing is done
			bSomethingDone = FALSE;
			slSizeReceived = recvfrom(cci_hSocket,(char*)aub,MAX_PACKET_SIZE,0,(SOCKADDR *)&sa,&size);
			tvNow = _pTimer->GetHighPrecisionTimer();

			adrIncomingAddress.adr_ulAddress = ntohl(sa.sin_addr.s_addr);
			adrIncomingAddress.adr_uwPort = ntohs(sa.sin_port);

			//On error, report it to the console (if error is not a no data to read message)
			if (slSizeReceived == SOCKET_ERROR) {
				int iResult = WSAGetLastError();
				if (!isWouldBlockError(iResult)) {
					// report it
					if (iResult!=WSAECONNRESET || net_bReportICMPErrors) {
						CPrintF(TRANSV("Socket error during UDP receive. %s\n"), 
							(const char*)GetSocketError(iResult));
						return;
					}
				}

			// if block received
			} else {
				// if there is not at least one byte more in the packet than the header size
				if (slSizeReceived <= MAX_HEADER_SIZE) {
					// the packet is in error
          extern INDEX net_bReportMiscErrors;          
          if (net_bReportMiscErrors) {
					  CPrintF(TRANSV("WARNING: Bad UDP packet from '%s'\n"), (const char *) AddressToString(adrIncomingAddress.adr_ulAddress));
          }
					// there might be more to do
					bSomethingDone = TRUE;
				} else if (net_fDropPackets <= 0  || (FLOAT(rand())/RAND_MAX) > net_fDropPackets) {
					// if no packet drop emulation (or the packet is not dropped), form the packet 
					// and add it to the end of the UDP Master's input buffer
					ppaNewPacket = new CPacket;
					ppaNewPacket->WriteToPacketRaw(aub,slSizeReceived);
					ppaNewPacket->pa_adrAddress.adr_ulAddress = adrIncomingAddress.adr_ulAddress;
					ppaNewPacket->pa_adrAddress.adr_uwPort = adrIncomingAddress.adr_uwPort;						

					if (net_bReportPackets == TRUE) {
						CPrintF("%lu: Received sequence: %d from ID: %d, reliable flag: %d\n",(ULONG) tvNow.GetMilliseconds(),ppaNewPacket->pa_ulSequence,ppaNewPacket->pa_adrAddress.adr_uwID,ppaNewPacket->pa_ubReliable);
					}

					cci_pbMasterInput.AppendPacket(*ppaNewPacket,FALSE);
					// there might be more to do
					bSomethingDone = TRUE;
				
				}
			}	

		} while (bSomethingDone);
	}

	// write from the output buffer to the socket
	while (cci_pbMasterOutput.pb_ulNumOfPackets > 0) {
		ppaNewPacket = cci_pbMasterOutput.PeekFirstPacket();

		sa.sin_family = AF_INET;
    sa.sin_addr.s_addr = htonl(ppaNewPacket->pa_adrAddress.adr_ulAddress);
    sa.sin_port = htons(ppaNewPacket->pa_adrAddress.adr_uwPort);
		
    slSizeSent = sendto(cci_hSocket, (char*) ppaNewPacket->pa_pubPacketData, (int) ppaNewPacket->pa_slSize, 0, (SOCKADDR *)&sa, sizeof(sa));
    cci_bBound = TRUE;   // UDP socket that did a send is considered bound
		tvNow = _pTimer->GetHighPrecisionTimer();

    // if some error
    if (slSizeSent == SOCKET_ERROR) {
      int iResult = WSAGetLastError();
			// if output UDP buffer full, stop sending
			if (isWouldBlockError(iResult)) {
				return;
			// report it
			} else if (iResult!=WSAECONNRESET || net_bReportICMPErrors) {
        CPrintF(TRANSV("Socket error during UDP send. %s\n"), 
          (const char*)GetSocketError(iResult));
      }
			return;    

    } else if (slSizeSent < ppaNewPacket->pa_slSize) {
        STUBBED("LOST OUTGOING PACKET DATA!");
        ASSERT(0);

    // if all sent ok
    } else {
			
			if (net_bReportPackets == TRUE)	{
				CPrintF("%lu: Sent sequence: %d to ID: %d, reliable flag: %d\n",(ULONG)tvNow.GetMilliseconds(),ppaNewPacket->pa_ulSequence,ppaNewPacket->pa_adrAddress.adr_uwID,ppaNewPacket->pa_ubReliable);
			}

			cci_pbMasterOutput.RemoveFirstPacket(TRUE);
      bSomethingDone=TRUE;
    }

	}




};
BOOL CCommunicationInterface::Client_Update(void)
{
	CTSingleLock slComm(&cm_csComm, TRUE);
	CPacket *ppaPacket;
	CPacket *ppaPacketCopy;
	CTimerValue tvNow = _pTimer->GetHighPrecisionTimer();

	// update local client's output buffers
	if (cm_ciLocalClient.UpdateOutputBuffers() == FALSE) {
		return FALSE;
	}

	// if not playing on the server (i.e. connectet to a remote server)
	if (!cci_bServerInitialized) {
		// put all pending packets in the master output buffer
		while (cm_ciLocalClient.ci_pbOutputBuffer.pb_ulNumOfPackets > 0) {
			ppaPacket = cm_ciLocalClient.ci_pbOutputBuffer.PeekFirstPacket();
			if (ppaPacket->pa_tvSendWhen < tvNow) {
				cm_ciLocalClient.ci_pbOutputBuffer.RemoveFirstPacket(FALSE);
				if (ppaPacket->pa_ubReliable & UDP_PACKET_RELIABLE) {
					ppaPacketCopy = new CPacket;
					*ppaPacketCopy = *ppaPacket;
					cm_ciLocalClient.ci_pbWaitAckBuffer.AppendPacket(*ppaPacketCopy,FALSE);
				}
				cci_pbMasterOutput.AppendPacket(*ppaPacket,FALSE);

			} else {
				break;
			}
		}

		// update broadcast output buffers
		// update its buffers
		cm_ciBroadcast.UpdateOutputBuffers();
		// transfer packets ready to be sent out to the master output buffer
		while (cm_ciBroadcast.ci_pbOutputBuffer.pb_ulNumOfPackets > 0) {
			ppaPacket = cm_ciBroadcast.ci_pbOutputBuffer.PeekFirstPacket();
			if (ppaPacket->pa_tvSendWhen < tvNow) {
				cm_ciBroadcast.ci_pbOutputBuffer.RemoveFirstPacket(FALSE);
				cci_pbMasterOutput.AppendPacket(*ppaPacket,FALSE);
			} else {
				break;
			}
		}

		// send/receive packets over the TCP/IP stack
		UpdateMasterBuffers();

		// dispatch all packets from the master input buffer to the clients' input buffers
		while (cci_pbMasterInput.pb_ulNumOfPackets > 0) {
			BOOL bClientFound;
			ppaPacket = cci_pbMasterInput.GetFirstPacket();
			bClientFound = FALSE;

      // if the packet address is broadcast and it's an unreliable transfer, put it in the broadcast buffer
      if ((ppaPacket->pa_adrAddress.adr_uwID==SLASHSLASH || ppaPacket->pa_adrAddress.adr_uwID==0) && 
           ppaPacket->pa_ubReliable == UDP_PACKET_UNRELIABLE) {
        cm_ciBroadcast.ci_pbInputBuffer.AppendPacket(*ppaPacket,FALSE);
				bClientFound = TRUE;
      // if the packet is for this client, accept it
      } else if ((ppaPacket->pa_adrAddress.adr_uwID == cm_ciLocalClient.ci_adrAddress.adr_uwID) || 
				          ppaPacket->pa_adrAddress.adr_uwID==SLASHSLASH || ppaPacket->pa_adrAddress.adr_uwID==0) { 
				cm_ciLocalClient.ci_pbInputBuffer.AppendPacket(*ppaPacket,FALSE);
				bClientFound = TRUE;
			}
			if (!bClientFound) {
				// warn about possible attack
				extern INDEX net_bReportMiscErrors;
				if (net_bReportMiscErrors) {
					CPrintF(TRANSV("WARNING: Invalid message from: %s\n"), (const char *) AddressToString(ppaPacket->pa_adrAddress.adr_ulAddress));
				}
			}
 		}

	}

	cm_ciLocalClient.UpdateInputBuffers();
	cm_ciBroadcast.UpdateInputBuffersBroadcast();

	return TRUE;
};