コード例 #1
0
ファイル: RTSPRequest.cpp プロジェクト: 12307/EasyDarwin
void RTSPRequest::ParseAddrSubHeader(StrPtrLen* inSubHeader, StrPtrLen* inHeaderName, UInt32* outAddr)
{
    if (!inSubHeader || !inHeaderName || !outAddr)
        return;
        
    StringParser theSubHeaderParser(inSubHeader);

    // Skip over to the value
    StrPtrLen theFirstBit;
    theSubHeaderParser.GetThru(&theFirstBit, '=');
    theFirstBit.TrimWhitespace();

    // First make sure this is the proper subheader
    if (!theFirstBit.EqualIgnoreCase(*inHeaderName))
        return;
    
    //Find the IP address
    theSubHeaderParser.ConsumeUntilDigit();

    //Set the addr string param.
    StrPtrLen theAddr(theSubHeaderParser.GetCurrentPosition(), theSubHeaderParser.GetDataRemaining());
    
    //Convert the string to a UInt32 IP address
    char theTerminator = theAddr.Ptr[theAddr.Len];
    theAddr.Ptr[theAddr.Len] = '\0';
    
    *outAddr = SocketUtils::ConvertStringToAddr(theAddr.Ptr);
    
    theAddr.Ptr[theAddr.Len] = theTerminator;
    
}
コード例 #2
0
ファイル: GameSocket.cpp プロジェクト: LeonG-ZA/mxosource
void GameSocket::OnRawData( const char *pData,size_t len,struct sockaddr *sa_from,socklen_t sa_len )
{
	struct sockaddr_in inc_addr;
	memcpy(&inc_addr,sa_from,sa_len);
	Ipv4Address theAddr(inc_addr);

	if (theAddr.IsValid() == false)
		return;

	string IPStr = theAddr.Convert(true);
	GClientList::iterator it = m_clients.find(IPStr);
	if (it != m_clients.end())
	{
		GameClient *Client = it->second;
		if (Client->IsValid() == false)
		{
			DEBUG_LOG( format("Removing dead client [%1%]") % IPStr );
			m_clients.erase(it);
			delete Client;
		}
		else
		{
			Client->HandlePacket(pData, len);
		}
	}
	else
	{
		m_clients[IPStr] = new GameClient(inc_addr, this);
		DEBUG_LOG(format ("Client connected [%1%], now have [%2%] clients")
			% IPStr % Clients_Connected());

		m_clients[IPStr]->HandlePacket(pData, len);
		m_clients[IPStr]->InitializeWorld () ;
	}
}