enum TVerdict CEsockTest19_1::easyTestStepL() { TInetAddr addr; TBuf<39> buf; // setting the IP address const TIp6Addr KInet6Addr19_1 = {{{0xff,0xfe,0,0,0,0,0,0,0,0,0,0,0,0,0x29,0xfe}}}; const TIp6Addr KInet6Addr19_2 = {{{0xff,0xf1,0,1,0,1,0,1,0,1,0,1,0,1,0x29,0xff}}}; // setting the IP address // set the address addr.SetAddress(KInet6Addr19_1); // check it has been set correctly addr.OutputWithScope(buf); TESTL(buf==_L("fffe::29fe")); // check port number initialised to 0 TESTL(addr.Port()==0); // change the address addr.SetAddress(KInet6Addr19_2); // check it has been set correctly addr.OutputWithScope(buf); TESTL(buf==_L("fff1:1:1:1:1:1:1:29ff")); // check port number is still set to 0 TESTL(addr.Port()==0); return EPass; }
/** * Handle incoming connects */ void tcp_sock::tcp_conn_handler() { if (!ctc) { DEBUG_WARNING("conn handler: no pending socket\n"); } TInetAddr ia; struct sa peer; ctc->iSocket.RemoteName(ia); sa_set_in(&peer, ia.Address(), ia.Port()); DEBUG_INFO("conn handler: incoming connect from %J\n", &peer); ctc->blank = false; /* * Application handler might call tcp_accept(), tcp_reject() * or do nothing */ if (connh) connh(&peer, arg); if (ctc) { DEBUG_INFO("delete ctc\n"); delete ctc; ctc = NULL; } /* Create blank socket for the next incoming CONNECT */ blank_socket(); cts->Accepting(); }
TSAHostCacheEntry::TSAHostCacheEntry(const TInetAddr& aAddress, TInt aQuality) { iPort = aAddress.Port(); iAddress = aAddress.Address(); iQuality = aQuality; }
TInt CUdpProcess::SendDataL(TDes8& aData, TInetAddr& aAddr, TInt aSize) /** Send data. @return the size of data sent */ { TRequestStatus status; TInt port = aAddr.Port(); iConsole.Printf(_L("Before sending, size = %d, port=%d\n"), aSize, port); TSockXfrLength sendSize = 0; //aSize; iSocket.SendTo(aData, aAddr, 0, status, sendSize); User::WaitForRequest(status); iConsole.Printf(_L("Sending result = %d, and sent=%d\n"), status.Int(), sendSize()); switch(status.Int()) { case KErrEof: iConsole.Printf(_L("Connection closed!")); return 0; case KErrNone: iConsole.Printf(_L("Send successfully.\n")); break; default: User::LeaveIfError(status.Int()); break; } return sendSize(); }
SilcUInt16 silc_net_get_remote_port(SilcSocket sock) { SilcSymbianSocket *s = (SilcSymbianSocket *)sock; TInetAddr addr; s->sock->RemoteName(addr); return (SilcUInt16)addr.Port(); }
SilcUInt16 silc_net_get_local_port(SilcSocket sock) { SilcSymbianSocket *s = (SilcSymbianSocket *)sock; TInetAddr addr; s->sock->LocalName(addr); return (SilcUInt16)addr.Port(); }
int udp_sock::local_get(struct sa *local) const { TInetAddr ia; cus->iSocket.LocalName(ia); sa_set_in(local, ia.Address(), ia.Port()); return 0; }
/** * Get the local IP address of the device * * @note Requires at least one IP packet sent in advance! */ int net_if_getaddr4(const char *ifname, int af, struct sa *ip) { (void)ifname; if (AF_INET != af) return EAFNOSUPPORT; /* Already cached? */ if (sa_isset(&local_ip, SA_ADDR)) { sa_cpy(ip, &local_ip); return 0; } RSocketServ ss; RSocket s; TInt ret; ret = ss.Connect(); if (KErrNone != ret) { DEBUG_WARNING("connecting to socket server fail (ret=%d)\n", ret); return ECONNREFUSED; } ret = s.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp); if (KErrNone != ret) { DEBUG_WARNING("open socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr bind; bind.SetPort(0); bind.SetAddress(KInetAddrAny); ret = s.Bind(bind); if (KErrNone != ret) { DEBUG_WARNING("bind socket failed (ret=%d)\n", ret); return ECONNREFUSED; } TInetAddr local; s.LocalName(local); s.Close(); ss.Close(); sa_set_in(&local_ip, local.Address(), local.Port()); DEBUG_NOTICE("local IP addr: %j\n", &local_ip); if (!sa_isset(&local_ip, SA_ADDR)) return EINVAL; sa_cpy(ip, &local_ip); return 0; }
int tcp_sock_local_get(const struct tcp_sock *ts, struct sa *local) { if (!ts || !local) return EINVAL; TInetAddr ia; ts->cts->iSocket.LocalName(ia); sa_set_in(local, ia.Address(), ia.Port()); return 0; }
int tcp_conn_peer_get(const struct tcp_conn *tc, struct sa *peer) { if (!tc || !peer) return EINVAL; TInetAddr ia; tc->ctc->iSocket.RemoteName(ia); sa_set_in(peer, ia.Address(), ia.Port()); return 0; }
int tcp_conn_local_get(const struct tcp_conn *tc, struct sa *local) { if (!tc || !local) return EINVAL; TInetAddr ia; tc->ctc->iSocket.LocalName(ia); sa_set_in(local, ia.Address(), ia.Port()); return 0; }
int ILibSocketWrapper_recvfrom(int socketObject, char *buffer, int bufferLength, struct sockaddr *src) { RSocket *s = (RSocket*)SocketArray[socketObject]; TRequestStatus status; TInetAddr addr; int RetVal=0; RBuf8 *buf = new RBuf8(); if(buf->Create(bufferLength)==KErrNone) { TProtocolDesc aProtocol; s->Info(aProtocol); if(aProtocol.iSockType==KSockStream) { s->RemoteName(addr); ((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address()); src->sa_port = htons(addr.Port()); RetVal = ILibSocketWrapper_recv(socketObject, buffer, bufferLength); } else { s->RecvFrom(*buf,addr,(unsigned int)0,status); User::WaitForRequest(status); if(status!=KErrNone) { RetVal = 0; } else { ((struct in_addr*)src->sa_data)->s_addr = ntohl(addr.Address()); src->sa_port = htons(addr.Port()); Mem::Copy(buffer,buf->Ptr(),buf->Length()); RetVal = buf->Length(); } } } buf->Close(); delete buf; return(RetVal); }
MFactoryQuery::TMatchResult THttpClientFlowQuery::Compare(TFactoryObjectInfo& aFactoryObjectInfo ) { const CHttpClientFlow* flow = static_cast<const CHttpClientFlow*>(aFactoryObjectInfo.iInfo.iFactoryObject); // iClientFlags == ECreateNew is handled by factory, other needs to be checked here TInetAddr remName; flow->RemName( remName ); if ( remName.Address ( ) == iSockAddr.iAddr && remName.Port ( ) == iSockAddr.iPort && flow->Status( ) == KErrNone ) { return MFactoryQuery::EMatch; } return MFactoryQuery::EContinue; }
int ILibSocketWrapper_getsockname(int socketObject, struct sockaddr* local, int* length) { struct sockaddr_in* localAddr = (struct sockaddr_in*)local; RSocket *s = (RSocket*)SocketArray[socketObject]; TInetAddr sockAddr; // get the local name s->LocalName(sockAddr); // convert from Symbian localAddr->sin_family = sockAddr.Family(); localAddr->sin_port = sockAddr.Port(); localAddr->sin_addr.s_addr = ntohl(sockAddr.Address()); return 0; }
void CFTPResolver::SetAddress(TInetAddr& aAddress) { // Get the 1st entry resolved iNameRecord = iNameEntry(); // Save the address (take care not to overwrite the port, might have been already set) if (TInetAddr::Cast(iNameRecord.iAddr).Family() == KAfInet) aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Address()); else aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Ip6Address()); #if defined(__FTPPROTDEBUG__) TBuf<512> debugBuffer; // A Buffer to output the resolved IP aAddress.Output(debugBuffer); debugBuffer.Append(_L(",")); debugBuffer.AppendNum(aAddress.Port(), EDecimal); debugBuffer.Append(_L("\n")); #endif FTPPROTDEBUG(_DBGResolver,_L("Resolved address is:")); FTPPROTDEBUG(_DBGResolver,debugBuffer); }
// --------------------------------------------------------------------------- // CStunTurnTests::TestOutgoingAddrL // --------------------------------------------------------------------------- // void CStunTurnTests::TestOutgoingAddrL() { TInetAddr inetAddr; TBuf<40> buffer; RDebug::Print( _L( "\nTEST CASE: Get outgoing address" ) ); iWrapper->OutgoingAddr( inetAddr ); inetAddr.Output( buffer ); RDebug::Print( _L("TEST PRINT: CStunTurnTests::TestOutgoingAddrL, wrapper outgoing Address: %S:%d "), &buffer, inetAddr.Port() ); if ( buffer.Length() == 0 ) { User::Leave( KErrCompletion ); } }
// // RunReader // void CDnsSocketWriter::RunReader(const TMsgBuf &aMsg, const TInetAddr &aFrom) { if (iRunReader) return; iRunReader = 1; #ifdef _LOG { TBuf<50> tmp; aFrom.OutputWithScope(tmp); Log::Printf(_L("CDnsSocketWriter[%u]::RunReader() read %d bytes from %S#%d"), this, (TInt)aMsg.Length(), &tmp, aFrom.Port()); } #endif if (aMsg.Length() >= TInt(sizeof(TDndHeader))) { const TDndHeader &hdr = aMsg.Header(); const TUint16 id = (TUint16)hdr.ID(); if (hdr.QR()) { // // This is a reply message, match it with // a waiting request, if any... // // Things get somewhat tricky, because almost anything // can happen inside the Reply (like DeactivateSocket, // ActivateSocketL, removal of any requests, requeing // for sent, etc... // Grab the current list into separate list. Note, that // Query or Reply callbacks are allowed to remove entries // from this temporary queue (the TDnsRequest::Cancel and // CDnsSocket::Redmove() still work correctly--they don't // care which chain the request belongs!), TRequestQueue reply(iWaitQueue); TUint mark = iDeactivateCount; TDnsRequest *rq; for (;;) { rq = reply.Remove(); if (rq == NULL) { // Didn't match any request, punt it into Query() iMaster.Query(aMsg, aFrom, iSocket); break; } iWaitQueue.AddLast(*rq); if (rq->iId == id && rq->Reply(iMaster, aMsg, aFrom)) break; } if (iDeactivateCount == mark) { // // No socket shutdown occurred, just reinsert remaining requests // while ((rq = reply.Remove()) != NULL) iWaitQueue.AddLast(*rq); } else { // // Socket was shut within Reply, all requests // should have been cancelled then... // while ((rq = reply.Remove()) != NULL) { rq->iQueueLink.SetWriter(NULL); rq->Abort(iMaster, KErrCancel); } } } else { // // Not a reply message, let the derived // class decide on how to deal with it. // iMaster.Query(aMsg, aFrom, iSocket); } } iRunReader = 0; if (iOpened ) // still open for business? { // Start a new read iReader->Activate(); } }
void CWin32Socket::ConvertAddress(const TInetAddr& aESockAddress, SOCKADDR_IN& aWinSockAddress) const { aWinSockAddress.sin_family = AF_INET; aWinSockAddress.sin_addr.s_addr = htonl(aESockAddress.Address()); aWinSockAddress.sin_port = htons(static_cast<TUint16>(aESockAddress.Port())); }
void CSTTrackerConnection::CreateUriL() { TInetAddr localAddress; TInt getAddressRes = KErrGeneral; // only send IP if we are connected via proxy //if (Preferences()->IncomingConnectionsMode() == EEnabledWithProxy) // getAddressRes = iNetMgr->Address(localAddress); CBufFlat* uriBuf = CBufFlat::NewL(512); CleanupStack::PushL(uriBuf); //TPtrC8 activeTracker = iTorrent.AnnounceList()->ActiveAddress(); //LWRITE(iLog, _L("Active tracker: ")); //LWRITELN(iLog, activeTracker); uriBuf->InsertL(uriBuf->Size(), *iAddress); uriBuf->InsertL(uriBuf->Size(), _L8("?")); uriBuf->InsertL(uriBuf->Size(), _L8("info_hash=")); HBufC8* encoded = EscapeUtils::EscapeEncodeL(iTorrent.InfoHash(), EscapeUtils::EEscapeUrlEncoded); CleanupStack::PushL(encoded); uriBuf->InsertL(uriBuf->Size(), *encoded); CleanupStack::PopAndDestroy(); // encoded uriBuf->InsertL(uriBuf->Size(), _L8("&peer_id=")); encoded = EscapeUtils::EscapeEncodeL(TorrentMgr()->PeerId(), EscapeUtils::EEscapeUrlEncoded); CleanupStack::PushL(encoded); uriBuf->InsertL(uriBuf->Size(), *encoded); CleanupStack::PopAndDestroy(); // encoded uriBuf->InsertL(uriBuf->Size(), _L8("&key=")); TBuf8<32> keyBuf; keyBuf.Num(TorrentMgr()->Key()); uriBuf->InsertL(uriBuf->Size(), keyBuf); uriBuf->InsertL(uriBuf->Size(), _L8("&port=")); TBuf8<32> portBuf; if (getAddressRes == KErrNone) portBuf.Num(localAddress.Port()); else portBuf.Num(Preferences()->IncomingPort()); uriBuf->InsertL(uriBuf->Size(), portBuf); uriBuf->InsertL(uriBuf->Size(), _L8("&uploaded=")); TBuf8<24> bytesUploaded; bytesUploaded.Num(iTorrent.BytesUploaded()); uriBuf->InsertL(uriBuf->Size(), bytesUploaded); uriBuf->InsertL(uriBuf->Size(), _L8("&downloaded=")); TBuf8<24> bytesDownloaded; bytesDownloaded.Num(iTorrent.BytesDownloaded()); uriBuf->InsertL(uriBuf->Size(), bytesDownloaded); uriBuf->InsertL(uriBuf->Size(), _L8("&left=")); TBuf8<24> bytesLeft; bytesLeft.Num(iTorrent.BytesLeft()); uriBuf->InsertL(uriBuf->Size(), bytesLeft); // it seems that some trackers support only compact responses uriBuf->InsertL(uriBuf->Size(), _L8("&compact=1")); if (iEvent != ETrackerEventNotSpecified) { uriBuf->InsertL(uriBuf->Size(), _L8("&event=")); switch (iEvent) { case ETrackerEventStarted: uriBuf->InsertL(uriBuf->Size(), _L8("started")); break; case ETrackerEventStopped: uriBuf->InsertL(uriBuf->Size(), _L8("stopped")); break; case ETrackerEventCompleted: uriBuf->InsertL(uriBuf->Size(), _L8("completed")); break; default: break; } } if (getAddressRes == KErrNone) { TBuf<64> ipBuf; localAddress.Output(ipBuf); TBuf8<64> ipBuf8; ipBuf8.Copy(ipBuf); uriBuf->InsertL(uriBuf->Size(), _L8("&ip=")); uriBuf->InsertL(uriBuf->Size(), ipBuf8); #ifdef LOG_TO_FILE // debug info LWRITE(iLog, _L("Sent to tracker: ")); LWRITE(iLog, ipBuf); TBuf8<32> portBuf; portBuf.Num(localAddress.Port()); LWRITE(iLog, _L(":")); LWRITELN(iLog, portBuf); #endif // } iUri = uriBuf->Ptr(0).AllocL(); CleanupStack::PopAndDestroy(); // uriBuf //iLog->WriteL(_L("[Trackerconnection] GET ")); //iLog->WriteLineL(*iUri); }
// --------------------------------------------------------------------------- // CStunTurnTests::TestSetSendingStatusTCPL // --------------------------------------------------------------------------- // void CStunTurnTests::TestSetSendingStatusTCPL() { TInetAddr inetAddr; TBuf<40> buffer; CTestClient* client = CTestClient::NewLC( this ); // testserver to wrapper CTestServer* server = CTestServer::NewLC( this ); TInetAddr addr( KInetAddrAny, KTestServerPort ); // stop scheduler when server timer runs out server->OpenL( addr, KTimeoutTime ); iNotificationIsOn = EFalse; TInetAddr testServerAddr; client->ResolveLocalAddrL( testServerAddr, iTestIapId ); testServerAddr.SetPort( KTestServerPort ); iWrapper->SetIncomingAddrL( testServerAddr ); iIfStub.StartActiveSchedulerL( KRunningTime ); iNotificationIsOn = ETrue; // testserver to natfw CTestServer* server2 = CTestServer::NewLC( this ); TInetAddr addr2( KInetAddrAny, KTestServer2Port ); server2->OpenL( addr2, KTimeoutTime ); TInetAddr destination; client->ResolveLocalAddrL( destination, iTestIapId ); destination.SetPort( KTestServer2Port ); destination.Output( buffer ); RDebug::Print( _L( "CStunTurnTests::TestSetSendingStatusTCPL; ADDR: %S PORT: %d" ), &buffer, destination.Port() ); // set sending status active RDebug::Print( _L( "\nTEST CASE: Set Sending Status Active" ) ); iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStateActive, destination ); iIfStub.StartActiveSchedulerL( KRunningTime ); server2->Cancel(); // set sending status passive RDebug::Print( _L( "\nTEST CASE: Set Sending Status Passive" ) ); iNat.SetSendingStateL( iIfStub.LocalCandidateL(), EStreamingStatePassive, destination ); iIfStub.StartActiveSchedulerL( KRunningTime ); CleanupStack::PopAndDestroy( server2 ); CleanupStack::PopAndDestroy( server ); CleanupStack::PopAndDestroy( client ); }
void CSTTorrentManager::OnLocalUDPReceiveL(TInetAddr aSender, const TDesC8& aData) { HLWRITELN(iLog, _L("[TorrentManager] OnLocalUDPReceiveL begin")); TInetAddr localAddress; iNetworkManager->GetLocalAddress(1, localAddress); if (localAddress.Address() == aSender.Address()) { HLWRITELN(iLog, _L("[TorrentManager] Throwing away own message")); return; } #ifdef LOG_TO_FILE LWRITE(iLog, _L("[TorrentManager] UDP sender: ")); TBuf<128> addressBuf; if (aSender.Address() == 0) { addressBuf = _L("? (could not get local address)"); } else { aSender.Output(addressBuf); addressBuf.Append(_L(":")); TBuf<16> portBuf; portBuf.Num(localAddress.Port()); addressBuf.Append(portBuf); } HLWRITELN(iLog, addressBuf); #endif //HLWRITEL(iLog, _L("[TorrentManager] Data received: ")); //HLWRITELN(iLog, aData); // TODO handle multiple torrents if (iTorrents.Count() == 0) return; if (aData.Size() >= 4) { TUint messageLength = NSTUtils::ReadInt32(aData); LWRITE(iLog, _L("[TorrentManager] Datagram length: ")); LWRITELN(iLog, aData.Size()); LWRITE(iLog, _L("[TorrentManager] Message length: ")); LWRITELN(iLog, messageLength); if ((TUint(aData.Size()) >= (4 + messageLength)) && (aData[4] == KMessageIdPiece)) { TInt index = NSTUtils::ReadInt32(aData.Mid(5)); TInt begin = NSTUtils::ReadInt32(aData.Mid(9)); TBool pendingRequestFound = EFalse; // check if the incoming local piece is requested by this peer for (TInt i=0; i<iTorrents[0]->PeerCount(); i++) { if ((iTorrents[0]->Peer(i)->IsLocal()) && (iTorrents[0]->Peer(i)->Connection()) && (iTorrents[0]->Peer(i)->Connection()->State() == EPeerPwConnected)) { pendingRequestFound = iTorrents[0]->Peer(i)->Connection()->HandleIncomingLocalPieceL(index, begin, aData.Mid(13, messageLength - 9)); if (pendingRequestFound) break; } } if (!pendingRequestFound) { if ((iTorrents[0]->PieceCount() > index) && (!iTorrents[0]->Piece(index)->IsDownloaded())) { HLWRITELN(iLog, _L("[TorrentManager] Received unrequested piece")); CSTPiece* piece = iTorrents[0]->Piece(index); CSTPeer* peer = iTorrents[0]->GetPeer(aSender); if (piece->InsertBlockL(begin, aData.Mid(13, messageLength - 9), peer) != KErrNone) { LWRITELN(iLog, _L8("CRITICAL FAULT, Writing to piece failed")); // CRITICAL FAULT } else { HLWRITELN(iLog, _L("[TorrentManager] Writing piece complete")); if (iTorrents[0]->EndGame()) iTorrents[0]->EndGamePieceReceivedL(piece, peer); } iTorrents[0]->iLocalSubPiecesNotRequested++; iTorrents[0]->iLocalSubPiecesNotRequestedSize += aData.Size(); // TODO remove commented part if the code above is working /*if (piece->DownloadedSize() == begin) { CSTPeer* peer = iTorrents[0]->GetPeer(aSender); if (piece->AppendBlockL(aData, peer) != KErrNone) { LWRITELN(iLog, _L8("CRITICAL FAULT, Writing to piece failed")); // CRITICAL FAULT } else { HLWRITELN(iLog, _L("[TorrentManager] Writing piece complete")); if (iTorrents[0]->EndGame()) iTorrents[0]->EndGamePieceReceivedL(piece, peer); } iTorrents[0]->iLocalSubPiecesNotRequested++; } else iTorrents[0]->iLocalSubPiecesReceivedNotMatchPieceBeginning++;*/ } else { iTorrents[0]->iLocalSubPiecesReceivedAlreadyDownloaded++; iTorrents[0]->iLocalSubPiecesReceivedAlreadyDownloadedSize += aData.Size(); } } } } HLWRITELN(iLog, _L("[TorrentManager] OnLocalUDPReceiveL end")); }
// --------------------------------------------------------------------------- // CStunTurnTests::TestSetReceivingStatusTCPL // --------------------------------------------------------------------------- // void CStunTurnTests::TestSetReceivingStatusTCPL() { // Connect wrapper to test server CTestServer* server = CTestServer::NewLC( this ); TInetAddr addr( KInetAddrAny, KTestServerPort ); // stop scheduler when clients timer runs out server->OpenL( addr, KTimeoutTime ); iNotificationIsOn = EFalse; CTestClient* client = CTestClient::NewLC( this ); TInetAddr testServerAddr; client->ResolveLocalAddrL( testServerAddr, iTestIapId ); testServerAddr.SetPort( KTestServerPort ); iWrapper->SetIncomingAddrL( testServerAddr ); iIfStub.StartActiveSchedulerL( KRunningTime ); iNotificationIsOn = ETrue; // Set receiving status active RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Active" ) ); iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), EStreamingStateActive ); // connect test client to natfw TInetAddr incomingAddr; client->ResolveLocalAddrL( incomingAddr, iTestIapId ); incomingAddr.SetPort( 5000 ); TBuf<40> buffer; incomingAddr.Output( buffer ); RDebug::Print( _L( "CStunTurnTests::TestSetReceivingStatusTCPL; ADDR: %S PORT: %d" ), &buffer ,incomingAddr.Port() ); client->OpenL( iTestIapId ); iIfStub.StartActiveSchedulerL(); // stop scheduler when clients timer runs out client->ConnectL( incomingAddr, KTimeoutTime ); iNotificationIsOn = EFalse; iIfStub.StartActiveSchedulerL( KRunningTime ); iNotificationIsOn = ETrue; // Set receiving status passive RDebug::Print( _L( "\nTEST CASE: Set Receiving Status Passive" ) ); iNat.SetReceivingStateL( iIfStub.LocalCandidateL(), EStreamingStatePassive ); iIfStub.StartActiveSchedulerL( KRunningTime ); CleanupStack::PopAndDestroy( client ); CleanupStack::PopAndDestroy( server ); }