enum TVerdict CEsockTest2_4::easyTestStepL() { TESTL(EPass == TestStepResult()); // double bind on different sockets // get IP address TInetAddr addr; TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.4")), _L("ipAddress"), addr)); // set port number to a valid value addr.SetPort(9); // socket already opened - retrieve // socket handle and bind TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr); // bind should succeed TESTEL(nRet == KErrNone, nRet); // socket already opened - retrieve // socket handle and bind again to same address nRet = iEsockSuite->GetSocketHandle(2).Bind(addr); // second bind should fail TESTEL(nRet == KErrInUse, nRet); return EPass; }
int ILibSocketWrapper_joinmulticastgroup(int socketObject, long multicastAddress, long multicastInterface) { RSocket *s = (RSocket*)SocketArray[socketObject]; int RetVal; TInetAddr dst; dst.SetAddress(htonl(multicastAddress)); dst.SetPort(0); dst.ConvertToV4Mapped(); TPckgBuf<TIp6Mreq> req; req().iAddr = dst.Ip6Address(); req().iInterface = ILibSocketWrapper_GetInterfaceIndex(multicastInterface); RetVal = s->SetOpt(KSoIp6JoinGroup,KSolInetIp,req); if(RetVal==KErrNone) { return(0); } else { s->SetOpt(KSoIp6LeaveGroup,KSolInetIp,req); return(-1); } }
void CSender::ConstructL() { // Connect to socket server User::LeaveIfError(iSocketServ.Connect()); User::LeaveIfError(iSocketServ.ShareAuto()); // allow other threads to use iSendSocket.Close(); User::LeaveIfError(iSendSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp)); TRequestStatus status; // Request the Socket to connect to the destination address (implicit Connection) TInetAddr destAddr; destAddr.Input(KRemoteAddr); destAddr.SetPort(KRemotePort); iSendSocket.Connect(destAddr, status); RDEBUGPRINTLOGGER1(_L("RPS: Waiting for Send socket to connect to remote destination ...")); User::WaitForRequest(status); RDEBUGPRINTLOGGER2(_L("RPS: Wait over. Status returned: %d\n"), status.Int()); if(status != KErrNone) { RDEBUGPRINTLOGGER1(_L("RPS: Socket could not Connect!!")); User::Leave(KErrCouldNotConnect); } else { RDEBUGPRINTLOGGER1(_L("RPS: Send socket connected to remote destination ")); } }
TBool CTcpTestConsole::StartL() { TLex args(iChars); // args are separated by spaces args.SkipSpace(); TInetAddr addr; TInt size; if(!iMode) { //Get ip addr TPtrC cmdAddr = args.NextToken(); if(!args.Eos()) { if(KErrNone == addr.Input(cmdAddr)) { args.Inc(); } else { return EFalse; } } else { return EFalse; } } //Get port TInt port; if(KErrNone != args.Val(port)) { return EFalse; } addr.SetPort(port); //Get pkg size args.Inc(); if(KErrNone != args.Val(size)) { return EFalse; } iCommandMode = ECommandRunning; if (iIsTcp) { iConsole->Printf(_L("Test for TCP...\n")); iTcp = CTcpProcess::NewL(*iConsole, addr, port, size, iMode); } else { iConsole->Printf(_L("Test for UDP...\n")); iUdp = CUdpProcess::NewL(*iConsole, addr, port, size, iMode); } return ETrue; }
enum TVerdict CEsockTest11_1::easyTestStepL() { // get ip address to connect to TInetAddr addr; TESTL(GetIpAddressFromConfig(_L("Test_Common"), _L("ipAddress"), addr)); // get port number to connect to TInt port; TESTL(GetIntFromConfig(_L("Test_11.1"), _L("port"), port)); // set remote address port addr.SetPort(port); // open a TCP socket RSocket sock; CleanupClosePushL(sock); TInt nRet = sock.Open(iEsockSuite->iSocketServer, KAfInet, KSockStream, KProtocolInetTcp); TESTEL(KErrNone == nRet, nRet); // connect to the remote address TRequestStatus stat; sock.Connect(addr, stat); User::WaitForRequest(stat); TESTEL(stat==KErrNone, stat.Int()); // get the remote name of the connected socket TInetAddr addr1; sock.RemoteName(addr1); // check this matches the address we connected to TESTL(addr.CmpAddr(addr1)); CleanupStack::PopAndDestroy(1, &sock); return EPass; }
int TcpipComm::Open(CConsoleBase *cons, TDes &name, TDesC &destination, TRequestStatus &st) { int r; TInetAddr addr; TPtrC servername; int port = 0; if((r = iServ.Connect()) != KErrNone) return r; if((r = iSock.Open(iServ,KAfInet,KSockStream,KProtocolInetTcp)) != KErrNone) return r; ////////////// // Parse the destination, which is of the form ip.adress:port for(r = 0; r < destination.Length(); r++) if(destination[r] == ':') break; servername.Set(destination.Left(r)); // Wont include ':' TLex parser(destination.Mid(r+1)); parser.Val(port); addr.SetPort(port); if(addr.Input(servername) != KErrNone) // Its a real hostname, wont resolv return 1; iSock.Connect(addr, st); TPckgBuf<int> one(1); iSock.SetOpt(KSoTcpNoDelay, KSolInetTcp, one); 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; }
void HXSymbianTCPConnector::Connect(RSocket& socket, ULONG32 ulAddr, UINT16 nPort) { m_addr.SetAddress(ulAddr); m_addr.SetPort(nPort); iStatus = KRequestPending; socket.Connect(m_addr, iStatus); SetActive(); }
void CMSocketS::Listen() { if (m_status != IDLE) { m_pNotify->OnAccept(MERN_INITIALIZE, NULL); return; } CMNetConnMgr& mgr = CMNetConnMgr::Instance(); //网络未接入直接返回失败 if (mgr.CurrentType() == CMNetConnMgr::NONE) { // m_pNotify->OnAccept(MERN_INITIALIZE, NULL); } //构造本地侦听ip,端口 RHostResolver hostResolver; TNameEntry entry; TInetAddr aAddress; User::LeaveIfError( hostResolver.Open( mgr.SocketServer(), KAfInet, KProtocolInetTcp, mgr.Connection() )); CleanupClosePushL( hostResolver ); User::LeaveIfError(hostResolver.GetByName(TPtrC(), entry)); if (!TInetAddr::Cast(entry().iAddr).IsWildAddr()) { aAddress = TInetAddr::Cast(entry().iAddr); } CleanupStack::PopAndDestroy(); // hostResolver aAddress.SetPort(m_nPort); //开始侦听 User::LeaveIfError( m_sk.Open( mgr.SocketServer(), KAfInet, KSockStream, KProtocolInetTcp ) ); User::LeaveIfError( m_sk.Bind( aAddress ) ); User::LeaveIfError( m_sk.Listen( 1 ) ); CMSocketC* pSocketC = new CMSocketC(NULL); // pSocketC->m_status = CMSocketC::CONNECTED; // if (pSocketC == NULL || pSocketC->GetStatus() != CMSocketC::NOTCONNECTED) // { // m_pNotify->OnAccept(MERN_WRONG_PARAM, NULL); // return; // } User::LeaveIfError( pSocketC->m_sk.Open( mgr.SocketServer() ) ); m_sk.Accept( pSocketC->m_sk, iStatus ); m_status = LISTENING; m_pSocketC = pSocketC; SetActive(); }
enum TVerdict CEsockTest17_7::easyTestStepL() { // // IsWildPort() // // TInetAddr addr; addr.SetAddress(IPADDR(126,0,0,1)); addr.SetPort(0); // IP Address to 126,0,0,1 and Port to Zero TESTL(addr.IsWildPort()!=EFalse); // Port = 0 - True addr.SetPort(21); // Sets Port to 21 FTP TESTL(addr.IsWildPort()==EFalse); // Port = 21 - False addr.SetAddress(IPADDR(191,220,145,22)); // IP Address to 191.220.145.22 TESTL(addr.IsWildPort()==EFalse); // Port = 21 - False addr.SetPort(0); // Sets Port to 0 TESTL(addr.IsWildPort()!=EFalse); // Port = 0 - True return EPass; }
void TFtpTest02Params::SetParams(const TDesC& aInetAddr, TUint aPort, const TDesC& aHostName, const TDesC8& aUserName, const TDesC8& aPassword, const TDesC8& aDirectoryPath, const TDesC8& aRemoteFileName, const TDesC& aLocalFileName) { iInetAddr.Input(aInetAddr); iInetAddr.SetPort(aPort); iPort=aPort; iHostName=aHostName; iUserName.Set(aUserName); iDirectoryPath.Set(aDirectoryPath); iPassword.Set(aPassword); iRemoteFileName.Set(aRemoteFileName); iLocalFileName.Set(aLocalFileName); }
SOAP_SOCKET CAafSocketUtils::SocketOpen(struct soap *soap, const char *endpoint, const char *host, int port) { __LOGSTR_TOFILE("CAafSocketUtils::SocketOpen() begins"); // Set endpoint if (endpoint) strncpy(soap->endpoint, endpoint, sizeof(soap->endpoint)-1); // Get thread entry point data MGSoapData* entryPointData = reinterpret_cast<MGSoapData*>(soap->user); // Open socket entryPointData->GetSocketInstance()->Open(*entryPointData->GetConnectionManager()->GetSocketServ(), KAfInet, KSockStream, KProtocolInetTcp, *entryPointData->GetConnectionManager()->GetConnection()); RHostResolver hostResolver; // Open resolver socket User::LeaveIfError(hostResolver.Open(*entryPointData->GetConnectionManager()->GetSocketServ(), KAfInet, KProtocolInetTcp)) ; TNameEntry hostAddress; TRequestStatus status; HBufC* serverName = CAafUtils::StringToDescriptorLC(host); // Attempt to resolve name hostResolver.GetByName(*serverName, hostAddress, status); CleanupStack::PopAndDestroy(serverName); User::WaitForRequest(status); // Connect to the specified host TInetAddr addrOnPort; addrOnPort = hostAddress().iAddr; addrOnPort.SetPort((TUint)port); entryPointData->GetSocketInstance()->Connect(addrOnPort, status); User::WaitForRequest(status); __LOGSTR_TOFILE("CAafSocketUtils::SocketOpen() ends"); if (status.Int() == KErrNone) return SOAP_OK; return SOAP_ERR; }
void CTrkSocketCommPort::ConnectL() { TInetAddr address; TInt err = KErrNone; // address.SetPort(10000); // err = address.Input(_L("10.86.2.93")); // // TRequestStatus stat; // iSocket.Connect(address, stat); // User::WaitForRequest(stat); // iConnected = ETrue; // TSockAddr test; // iSocket.LocalName(test); // TUint lp = iSocket.LocalPort(); address.SetPort(6110); err = address.Input(_L("127.0.0.1")); // err = address.Input(_L("0.0.0.0")); err = iSocket.Bind(address); if (err != KErrNone) { User::Leave(err); } err = iSocket.Listen(1); if (err != KErrNone) { User::Leave(err); } RSocket blankSocket; err = blankSocket.Open(iSocketServ); TRequestStatus stat; iSocket.Accept(blankSocket, stat); // SetActive(); User::WaitForRequest(stat); User::Leave(5000); // iSocket.Connect(address, iStatus); iConnected = ETrue; }
static int connect_test() { RSocketServ rSockServ; RSocket rSock; TInetAddr inetAddr; TRequestStatus reqStatus; char buffer[16]; TPtrC8 data((const TUint8*)buffer, (TInt)sizeof(buffer)); int rc; rc = rSockServ.Connect(); if (rc != KErrNone) return rc; rc = rSock.Open(rSockServ, KAfInet, KSockDatagram, KProtocolInetUdp); if (rc != KErrNone) { rSockServ.Close(); return rc; } inetAddr.Init(KAfInet); inetAddr.Input(_L("127.0.0.1")); inetAddr.SetPort(80); rSock.Connect(inetAddr, reqStatus); User::WaitForRequest(reqStatus); if (reqStatus != KErrNone) { rSock.Close(); rSockServ.Close(); return rc; } rSock.Send(data, 0, reqStatus); User::WaitForRequest(reqStatus); if (reqStatus!=KErrNone) { rSock.Close(); rSockServ.Close(); return rc; } rSock.Close(); rSockServ.Close(); return KErrNone; }
enum TVerdict CEsockTest2_3::easyTestStepL() { TESTL(EPass == TestStepResult()); // bind to an illegal address // get IP address TInetAddr addr; TESTL(GetIpAddressFromConfig(SectionName(_L("Test_2.3")), _L("ipAddress"), addr)); // set port number to a valid value addr.SetPort(7); // socket already opened - retrieve // socket handle and bind TInt nRet = iEsockSuite->GetSocketHandle(1).Bind(addr); TESTEL(nRet == KErrNotFound, nRet); return EPass; }
// // Start asynchronous recv() operation // pj_status_t CIoqueueCallback::StartRead (pj_ioqueue_op_key_t *op_key, void *buf, pj_ssize_t *size, unsigned flags, pj_sockaddr_t *addr, int *addrlen) { PJ_ASSERT_RETURN (IsActive() ==false, PJ_EBUSY); PJ_ASSERT_RETURN (pending_data_.common_.op_key_==NULL, PJ_EBUSY); flags &= ~PJ_IOQUEUE_ALWAYS_ASYNC; pending_data_.read_.op_key_ = op_key; pending_data_.read_.addr_ = addr; pending_data_.read_.addrlen_ = addrlen; aBufferPtr_.Set ( (TUint8*) buf, 0, (TInt) *size); type_ = TYPE_READ; if (addr && addrlen) { sock_->Socket().RecvFrom (aBufferPtr_, aAddress_, flags, iStatus); } else { aAddress_.SetAddress (0); aAddress_.SetPort (0); if (sock_->IsDatagram()) { sock_->Socket().Recv (aBufferPtr_, flags, iStatus); } else { // Using static like this is not pretty, but we don't need to use // the value anyway, hence doing it like this is probably most // optimal. static TSockXfrLength len; sock_->Socket().RecvOneOrMore (aBufferPtr_, flags, iStatus, len); } } SetActive(); return PJ_EPENDING; }
void FSocket::ConstructL(const StringBuffer& peer, int32_t port) { //LOG.debug("FSocket::ConstructL"); StringBuffer errorMsg; RHostResolver resolver; RBuf serverName; TNameEntry hostAddress; TInetAddr address; TInt res = KErrNone; serverName.Assign(stringBufferToNewBuf(peer)); // // Get the connection manager instance // FConnection* connection = FConnection::getInstance(); if (!connection) { iStatus = -1; errorMsg = "Error opening connection"; goto error; } // Session is owned by FConnection! RSocketServ* session = connection->getSession(); // // Open the Client Socket tcp/ip // #ifdef __WINSCW__ // WINSCW: simply open the socket res = iSocket.Open(*session, KAfInet, KSockStream, KProtocolInetTcp); #else // GCCE: use the existing connection // If first time, connect to gprs if (!connection->isConnected()) { LOG.debug("FSocket: not connected, start new connection"); if (connection->startConnection()) { iStatus = -1; errorMsg = "FSocket: error starting connection"; goto error; } } RConnection* conn = connection->getConnection(); LOG.debug("Opening socket and associate with existing connection"); res = iSocket.Open(*session, KAfInet, KSockStream, KProtocolInetTcp, *conn); //LOG.debug("Socket opened (err = %d)", res); #endif if (res != KErrNone) { iStatus = -1; errorMsg.sprintf("FSocket : Error opening socket. code %d", res); goto error; } // This works if serverName is the ip address, like "x.y.z.w" res = address.Input(serverName); if (res != KErrNone) { // // Try to resolve the host address. (On GCCE, use the existing RConnection) // LOG.debug("Resolve IP address..."); #ifdef __WINSCW__ res = resolver.Open(*session, KAfInet, KProtocolInetTcp); #else res = resolver.Open(*session, KAfInet, KProtocolInetTcp, *conn); #endif if (res != KErrNone) { iStatus = -2; errorMsg.sprintf("FSocket: Host resolver open failed. code %d", res); goto error; } resolver.GetByName(serverName, hostAddress, iStatus); User::WaitForRequest(iStatus); resolver.Close(); if (iStatus != KErrNone) { errorMsg.sprintf("FSocket: DNS lookup failed. code %d", iStatus.Int()); goto error; } // Set the socket server address/port address = hostAddress().iAddr; } address.SetPort(port); // --- Connect to host --- LOG.debug("Socket connect..."); iSocket.Connect(address, iStatus); User::WaitForRequest(iStatus); if (iStatus != KErrNone) { errorMsg.sprintf("FSocket: Failed to connect to Server. code %d", iStatus.Int()); goto error; } serverName.Close(); return; error: LOG.error("%s", errorMsg.c_str()); serverName.Close(); return; }
TInt CTS_MultiHomingStep::GetSockConfig(const TInt aIndex, TInt& aProtocol, TInt& aPackSize, TInt& aNumPackets, TInt& aUdp, TInetAddr& aDstAddr, TInetAddr& aSrcAddr, TBool& aExpectSuccess, TBool& aIsListener, TConnDetails **aConnDetails) /** * Gets socket configuration from file, using defaults if necessary * @param aIndex The index for the socket configkey * @param aProtocol The protocol to be used * @param aPackSize The packet size in bytes * @param aNumPackets Number of packets to send * @param aUdp Percentage of UDP packets that can be dropped * @param aAddr The destination address for the socket * @param aSS The socket server sub-session to use for the socket * @param aNetName The network connection name in the suite * @return System wide error code */ { TInt err=KErrNone; TInt val=0; TBuf<10> socketNum; // Create the Key for the config lookup socketNum= KSocket; socketNum.AppendNum(aIndex); TPtrC ptrBuf; // Port 0 means we dont care about binding to port err = GetStringFromConfig(socketNum, KSrcAddr, ptrBuf); if (err) { // String found in table err = aSrcAddr.Input(ptrBuf); TESTE(err==KErrNone,err); if (err !=KErrNone) { iTestStepResult= EInconclusive; return KErrBadName; } } else aSrcAddr.SetAddress(KInetAddrAny); err = GetIntFromConfig(socketNum, KSrcPort, val); if (err) aSrcAddr.SetPort((TUint) val); else aSrcAddr.SetPort(0); // Default to zero - ie source address NOT uses err = GetStringFromConfig(socketNum, KDestAddr, ptrBuf); if (!err) { LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile); iTestStepResult= EInconclusive; return KErrNotFound; } err = aDstAddr.Input(ptrBuf); TESTE(err==KErrNone,err); if (err !=KErrNone) { iTestStepResult= EInconclusive; return KErrBadName; } err = GetIntFromConfig(socketNum, KDestPort, val); if (!err) aDstAddr.SetPort(ECHO_PORT); // Default to echo port aDstAddr.SetPort((TUint) val); err = GetStringFromConfig(socketNum, KProtocol, ptrBuf); if (err && (ptrBuf.Compare(KTcp)==0)) aProtocol = KProtocolInetTcp; else aProtocol = KProtocolInetUdp; err = GetIntFromConfig(socketNum, KPacketSize, val); if (!err) aPackSize=PACKET_SIZE; aPackSize=val; err = GetIntFromConfig(socketNum, KNumOfPackets, val); if (!err) aNumPackets=NUM_OF_PACKETS; aNumPackets=val; err = GetIntFromConfig(socketNum, KUdpTol, val); if (!err) aUdp=UDP_TOLERANCE; aUdp=val; aExpectSuccess = ETrue; GetBoolFromConfig(socketNum, KExpectSuccess, aExpectSuccess); aIsListener = EFalse; GetBoolFromConfig(socketNum, KIsListener, aIsListener); err = GetStringFromConfig(socketNum, KConnName, ptrBuf); if (!err) { LogExtra((TText8*)__FILE__, __LINE__, ESevrWarn, KEConfigFile); iTestStepResult= EInconclusive; return KErrNotFound; } // Use default *aConnDetails = iOwnerSuite->GetTConnection(ptrBuf); return KErrNone; }
// --------------------------------------------------------------------------- // 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 ); }
// ---------------------------------------------------- // CSymellaAppUi::HandleCommandL(TInt aCommand) // ?implementation_description // ---------------------------------------------------- // void CSymellaAppUi::HandleCommandL(TInt aCommand) { switch ( aCommand ) { case ESymellaCmdConnect: { CTR->ConnectL(); } break; case ESymellaCmdSelectGenre: { TInt index = 0; CAknListQueryDialog* queryDialog = new(ELeave) CAknListQueryDialog(&index); if(queryDialog->ExecuteLD(R_SYMELLA_GENRE_SELECTION_LIST)) { CTR->SetGenre(index); } } break; case ESymellaCmdResetHostCache: { // ask to quit CAknQueryDialog* query = CAknQueryDialog::NewL(); CleanupStack::PushL(query); _LIT(KPrompt, "Are you sure you want to reset the hostcache?"); query->SetPromptL(KPrompt); CleanupStack::Pop(); // query if (query->ExecuteLD(R_GENERAL_QUERY)) { CTR->HostCache().Reset(); } } break; case ESymellaCmdDisconnect: { CTR->DisconnectL(); } break; case ESymellaCmdConnectInfo: { HBufC* info = CTR->CreateConnectInfoL(); CleanupStack::PushL(info); /*CAknNoteDialog* note = new (ELeave) CAknNoteDialog; CleanupStack::PushL(note); note->SetTextL(*info); CleanupStack::Pop(); note->PrepareLC(R_CONNECTION_INFO_NOTE); note->RunLD();*/ CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); dlg->PrepareLC( R_MESSAGE_QUERY ); dlg->SetMessageTextL(info->Des()); dlg->QueryHeading()->SetTextL(_L("Connect info")); dlg->RunLD(); CleanupStack::PopAndDestroy(); //info } break; case ESymellaCmdAbout: { TBuf<30> time; TBuf<50> date; date.Copy(_L8(__DATE__)); time.Copy(_L8(__TIME__)); _LIT(KBuild, "Built on "); HBufC* info = HBufC::NewLC(TPtrC(KAbout).Length() + 64 /*+ TPtrC(KEngineVersion).Length() */+ TPtrC(KBuild).Length() + date.Length() + 4); TPtr des = info->Des(); des.Append(_L("Version ")); des.Append(SYMELLA_VERSION_LIT); des.Append(KAbout); //des.Append(KEngineVersion); des.Append(KBuild); des.Append(date); CAknMessageQueryDialog* dlg = new (ELeave)CAknMessageQueryDialog(); CleanupStack::PushL(dlg); dlg->PrepareLC( R_MESSAGE_QUERY ); dlg->SetMessageTextL(des); dlg->QueryHeading()->SetTextL(_L("Symella S60")); CleanupStack::Pop(); //dlg dlg->RunLD(); CleanupStack::PopAndDestroy(); //info } break; case ESymellaCmdAddNode: { // Create dialog to allow user to view/edit connection details TBuf<100> hostName; //hostName.Copy(_L("")); hostName.Copy(_L("192.168.0.100")); TInt port = 6346; CAknMultiLineDataQueryDialog* dialog = CAknMultiLineDataQueryDialog::NewL(hostName, port); // Display and execute dialog, and act according to return value if (dialog->ExecuteLD(R_ADD_NODE_DIALOG)) { TInetAddr addr; if (addr.Input(hostName) == KErrNone) { addr.SetPort(port); CTR->HostCache().AddUltrapeerL(addr); } } } break; case EAknCmdExit: case EEikCmdExit: { PREFERENCES->SaveWebCachesL(); LOG->WriteLineL(_L("Saving hostcache...")); CTR->HostCache().SaveHostCacheL(); LOG->WriteLineL(_L("Symella terminating")); Exit(); } break; case EAknSoftkeyBack: case EAknSoftkeyExit: { // ask to quit CAknQueryDialog* query = CAknQueryDialog::NewL(); CleanupStack::PushL(query); _LIT(KPrompt, "Quit Symella?"); query->SetPromptL(KPrompt); CleanupStack::Pop(); // query if (query->ExecuteLD(R_GENERAL_QUERY)) { // ((CSymellaSearchView*)View(TUid::Uid(1)))->CloseFindBoxL(); PREFERENCES->SaveWebCachesL(); LOG->WriteLineL(_L("Saving hostcache...")); CTR->HostCache().SaveHostCacheL(); LOG->WriteLineL(_L("Symella terminating")); Exit(); } } break; case ESymellaCmdSearch: { TBuf<256> query; query.Copy(CTR->SearchString()); CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(query, CAknQueryDialog::ENoTone); dlg->SetPredictiveTextInputPermitted(ETrue); if (! dlg->ExecuteLD(R_SEARCH_QUERY)) break; HBufC8* query8 = HBufC8::NewLC(query.Length()); TPtr8 query8Ptr(query8->Des()); query8Ptr.Copy(query); CTR->SearchL(*query8); CleanupStack::PopAndDestroy(); // query8 iTabGroup->SetActiveTabByIndex(1); ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(1))); LOG->WriteL(_L("Searching for: ")); LOG->WriteLineL(query); } break; case ESymellaCmdSettings: { ActivateLocalViewL(KSettingsViewId); } break; default: break; } }
TVerdict CTestConnectStep::doTestStepL() /** * @return - TVerdict code * Override of base class pure virtual * Demonstrates reading configuration parameters fom an ini file section */ { if(TestStepResult()==EPass) { INFO_PRINTF1(_L("In Test Step ConnectWithOverrides")); // When bootstrapping C32 we have to avoid the PhBkSyncServer being started, since // it needs a different CommDB TInt ret = StartC32WithCMISuppressions(KPhbkSyncCMI); if((ret!=KErrNone) && (ret!=KErrAlreadyExists)) { INFO_PRINTF2(_L("error is : %d \n"),ret); } else { INFO_PRINTF1(_L("Started C32\n")); } RHostResolver hr; INFO_PRINTF1(_L("Connect to RSocketServ")); User::LeaveIfError(iSocketServ.Connect()); // Set up the connections, both overridden as host resolver won't work // on the default interface INFO_PRINTF1(_L("Open the RConnection interface")); User::LeaveIfError(iConnection.Open(iSocketServ)); // get the IapNumber value from the ini file if(!GetIntFromConfig(ConfigSection(), KIapNumber, iIapNumber)) { if(!GetIntFromConfig(KIap, KIapNumber, iIapNumber)) { iIapNumber=1; INFO_PRINTF1(_L("Failed to read Iap from ini file, using default")); } } INFO_PRINTF2((_L("IapNumber = %d")), iIapNumber); TRequestStatus status; #ifdef SIROCCO_CODE_MIGRATION TCommDbConnPref prefs; prefs.SetIapId(iIapNumber); prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); const TUid KMyPropertyCat = {0x101FD9C5}; const TUint32 KMyPropertyDestPortv4 = 67; TInt err = RProperty::Define(KMyPropertyCat, KMyPropertyDestPortv4, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass), TSecurityPolicy(ECapabilityWriteDeviceData)); User::LeaveIfError(RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 93)); #else TInt rank = 1; // Create a multiple connection preference object TCommDbMultiConnPref prefs; for(TInt i=0;i<iapCount;i++) { TCommDbConnPref pref; // Set the direction pref.SetDirection(ECommDbConnectionDirectionOutgoing); // Set the bear ser pref.SetBearerSet(KCommDbBearerPSD | KCommDbBearerCSD); // Set the IAP pref.SetIapId(iIapNumber + i); // Set the dialog preference to Do Not Prompt pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); // Set the rank User::LeaveIfError(prefs.SetPreference(rank, pref)); rank++; } prefs.SetConnectionAttempts(rank-1); #endif // Start the connection iConnection.Start(prefs, status); User::WaitForRequest(status); TInt result = status.Int(); if(result!=KErrNone) { ERR_PRINTF2(_L("Failed to start connection. Error %d"), result); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Connection started with overrides")); } // Set up the host resolver INFO_PRINTF1(_L("Initialise a host resolver service")); User::LeaveIfError(hr.Open(iSocketServ, KAfInet, KProtocolInetTcp, iConnection)); CleanupClosePushL(hr); // Test the interfaces conn, host resolution should work ok TBuf<64> hostname; TRequestStatus status1; TNameEntry nameEntry; TPtrC temphost; if(GetStringFromConfig(KTCPConfig, KHostName, temphost)) { INFO_PRINTF2(_L("Hostname is : %S"), &temphost); } else { ERR_PRINTF1(_L("No hostname")); SetTestStepResult(EFail); User::Leave(EFail); } hostname = temphost; hr.GetByName(hostname, nameEntry, status1); User::WaitForRequest(status1); TInt result1 = status1.Int(); if(result1!=KErrNone) { ERR_PRINTF2(_L("Failed to resolve the name. Error %d"), result1); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Resolved the name successfully")); } // open socket INFO_PRINTF1(_L("Open the socket")); User::LeaveIfError(iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iConnection)); CleanupClosePushL(iSocket); // print the host resolver's ip address TInetAddr inetAddr; inetAddr = TInetAddr(nameEntry().iAddr); TBuf<50> addr; inetAddr.Output(addr); INFO_PRINTF2(_L("The host resolver's ip address is: %S"), &addr); // get the port number from the ini file if(!GetIntFromConfig(KTCPConfig, KPort, iPort)) { ERR_PRINTF1(_L("Failed to read Port from ini file")); SetTestStepResult(EFail); User::Leave(EFail); } INFO_PRINTF2((_L("Port = %d")), iPort); // connect to the socket inetAddr.SetPort(iPort); //nameEntry().iAddr.SetPort(iPort); TRequestStatus status2; //iSocket.Connect(nameEntry().iAddr,status2); iSocket.Connect(inetAddr,status2); User::WaitForRequest(status2); TInt result2 = status2.Int(); if(result2!=KErrNone) { ERR_PRINTF2(_L("Failed to connect to the socket. Error %d"), result2); SetTestStepResult(EFail); User::Leave(EFail); } else { INFO_PRINTF1(_L("Connect to the socket successfully")); } TPtrC ptrDNSName; if(GetStringFromConfig(KTCPConfig, KDNSName, ptrDNSName)) { INFO_PRINTF2(_L("DNSName is : %S"), &ptrDNSName); } else { ERR_PRINTF1(_L("No DNSName")); SetTestStepResult(EFail); User::Leave(EFail); } TBuf8<256> bufDnsName; bufDnsName.Copy(ptrDNSName); // connect to the secure socket CTestSecureSocket* iTestSecureSocket = CTestSecureSocket::NewL(*this, iSocket, bufDnsName); CleanupStack::PushL(iTestSecureSocket); iTestSecureSocket->StartHandshake(); CActiveScheduler::Start(); CleanupStack::PopAndDestroy(3); //iTestSecureSocket, iSocket, hr } return TestStepResult(); }
// --------------------------------------------------------------------------- // 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 ); }
/** Initiates the start (creation & activation) of a secondary PDP context, but does not wait/verify that the context was actually created / activated Set Qos R5 parameters on secondary pdp context. @leave if the start cannot be initiated: a socket cannot be opened, etc */ void CSpudQosR5TestBase::InitiateSecondaryStartL() { #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY ReadQosParameterSettingsFromConfigL(); UpdatePolicySelector2QosParametersTableL(iPolicySelector, iQosParametersRecord); #endif TestL(iSocket.Open(iEsock, KAfInet, KSockDatagram, KProtocolInetUdp), _L("RSocket::Open")); TInetAddr localAddr; localAddr.SetPort(KConfiguredTftFilter1DestPort); TestL(iSocket.Bind(localAddr), _L("Binding the local Socket")); TInetAddr dstAddr; dstAddr.SetPort(KConfiguredTftFilter1SrcPort); dstAddr.Input(KConfiguredTftFilter1SrcAddr); TRequestStatus status; iSocket.Connect(dstAddr, status); User::WaitForRequest(status); TestL(status.Int(), _L("Connecting to local socket")); #ifndef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY TQoSSelector selector; selector.SetAddr(iSocket); TestL(iQoSPolicy_1.Open(selector), _L("Opening Policy")); TestL(iQoSPolicy_1.NotifyEvent(*this), _L("Requesting Event notification on QosChannel")); CQoSParameters *parameters = new(ELeave) CQoSParameters; CleanupStack::PushL(parameters); SetQoSParameters(*parameters); TUmtsR5QoSParameters* umtsParameters = new(ELeave) TUmtsR5QoSParameters; CleanupStack::PushL(umtsParameters); SetQoSR5Parameters(*umtsParameters); CUmtsR5QoSPolicy *umtsR5Policy = CUmtsR5QoSPolicy::NewL(); CleanupStack::PushL(umtsR5Policy); umtsR5Policy->SetQoSRequested(*umtsParameters); TEST(parameters->AddExtensionL(*umtsR5Policy) == KErrNone); TImsParameter* imsParameters = new(ELeave) TImsParameter; CleanupStack::PushL(imsParameters); SetIMSParameters(*imsParameters); CImsPolicy *imsPolicy = CImsPolicy::NewL(); CleanupStack::PushL(imsPolicy); imsPolicy->SetImsParameter(*imsParameters); TEST(parameters->AddExtensionL(*imsPolicy) == KErrNone); TestL(iQoSPolicy_1.SetQoS(*parameters), _L("Setting R5 Qos Parameters")); WaitForQoSEventL(_L("SecondaryActivationEvent1"),KErrNone); CleanupStack::PopAndDestroy(5); #endif }
TVerdict CmoveConnectedSocketToSubconnectionStep::doSingleTestStep() { RSocket socket; TInetAddr dstAddr; RSocketServ socketServer; RConnection conn; RSubConnection subconn; TRequestStatus status; TRequestStatus eventStatus; TNotificationEventBuf subconnNotifBuf; TInt ret; CleanupClosePushL(socketServer); CleanupClosePushL(conn); CleanupClosePushL(socket); CleanupClosePushL(subconn); // Connect to ESOCK ret = socketServer.Connect(); if (ret != KErrNone) { INFO_PRINTF2(_L("Failed to connect toEsock due to Error: %d."),ret); return EFail; } // Open a connection ret = conn.Open(socketServer); if (ret != KErrNone) { INFO_PRINTF2(_L("Failed to open connection due to Error: %d."),ret); return EFail; } // Start the connection conn.Start(status); User::WaitForRequest(status); if (status != KErrNone) { INFO_PRINTF2(_L("Failed to start connection due to Error: %d."),status.Int()); return EFail; } // Open UDP socket ret = socket.Open(socketServer, KAfInet, KSockDatagram, KProtocolInetUdp, conn); if (ret != KErrNone) { INFO_PRINTF2(_L("Failure to open socket due to Error: %d."),ret); return EFail; } dstAddr.SetPort(3441); _LIT(KText50, "127.0.0.1"); dstAddr.Input( KText50 ); ret = socket.SetLocalPort(3442); if (ret != KErrNone) { INFO_PRINTF2(_L("Failed to set port on socket due to Error: %d."),ret); return EFail; } socket.Connect(dstAddr, status); User::WaitForRequest(status); if (status != KErrNone) { INFO_PRINTF2(_L("Socket failed to connect to dst addr due to Error: %d."),status.Int()); return EFail; } // Create a new sub-connection ret = subconn.Open(socketServer, RSubConnection::ECreateNew, conn); if (ret != KErrNone) { INFO_PRINTF2(_L("Failed to create new sub-connection due to Error: %d."),ret); return EFail; } // Move the connected socket onto the new sub-connection subconn.Add(socket, status); User::WaitForRequest(status); if (status != KErrNotReady) { INFO_PRINTF2(_L("Socket could not be added to subconn due to Error: %d."),status.Int()); return EFail; } // close and destroy CleanupStack::PopAndDestroy(&subconn); CleanupStack::PopAndDestroy(&socket); CleanupStack::PopAndDestroy(&conn); CleanupStack::PopAndDestroy(&socketServer); return EPass; }
void CTlsUnitTestWrapper::DoConnect(const TDesC& aSection) { TInt error = KErrNone; TInt recvBufSize = KErrNotFound, sendBufSize = KErrNotFound; TInt noDelayEnabled = KErrNotFound; User::LeaveIfError(isocketserv->Connect()); // Open a socket User::LeaveIfError(isocket.Open( *isocketserv, KAfInet, KSockStream, KProtocolInetTcp )); TPtrC ptrToReadFromConfig(KNameDefault()); // Get destination address from config file TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig); if (!returnValue) { ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr")); SetError(KErrUnknown); return; } else { iAddress.Copy(ptrToReadFromConfig) ; } // Create address TInetAddr ipAddr; TInt err = ipAddr.Input(ptrToReadFromConfig); if(err != KErrNone) { INFO_PRINTF2(KInetInputFail, err); SetError(err); return; } // Get destination Port number from config file returnValue = GetIntFromConfig(aSection, KPortNum, iport); if (!returnValue) { ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr")); SetError(KErrUnknown); return; } // set port number ipAddr.SetPort(iport); if(err != KErrNone) { INFO_PRINTF2(KInetInputFail, err); SetError(err); return; } //Socket connect() call. isocket.Connect(ipAddr, istatus); User::WaitForRequest(istatus); if(istatus.Int() != KErrNone) { INFO_PRINTF1( _L("Connection failed to specified address and port.") ); User::Leave(KErrCouldNotConnect); } else { INFO_PRINTF1( _L("Connected to the specified address and port.") ); } }
void UT_CIceConnectivityCheck::UT_CICEConnectivityCheck_PerformConnCheckL3L() { const TUint priority = 100; const TUint remotePriority = 100; const TBool remoteFavored = ETrue; iConnCheck->SetRemoteCheckInfo( remotePriority, remoteFavored ); if ( TIceTestUtils::AllocTestEnabled() ) { EUNIT_ASSERT_LEAVE( iConnCheck->PerformConnCheckL( CIceConnectivityCheck::EIceCheckTypePeriodic, priority, KTaTimerValueForChecks ) ); } else { iConnCheck->PerformConnCheckL( CIceConnectivityCheck::EIceCheckTypePeriodic, priority, KTaTimerValueForChecks ); TInetAddr fromAddr = iRemoteCand->TransportAddr(); TInetAddr destAddr = iLocalCand->TransportAddr(); TInetAddr mappedAddr( KMappedAddr ); mappedAddr.SetPort( KMappedPort ); mappedAddr.SetFamily( KAfInet ); // Invalid addresses fromAddr.SetPort( 1000 ); EUNIT_ASSERT_NO_LEAVE( iConnCheck->ConnCheckCompletedL( KErrNone, fromAddr, destAddr, mappedAddr ) ); fromAddr.SetPort( KRemotePort ); EUNIT_ASSERT( KErrNone != iCheckResult ); EUNIT_ASSERT( !iValidatedPair ); iConnCheck->iState = CIceConnectivityCheck::EIceCheckInProgress; /* // no way to check currently that destination address matches destAddr.SetPort( 1000 ); EUNIT_ASSERT_NO_LEAVE( iConnCheck->ConnCheckCompletedL( KErrNone, fromAddr, destAddr, mappedAddr ) ); destAddr.SetPort( KLocalPort ); EUNIT_ASSERT( KErrNone != iCheckResult ); EUNIT_ASSERT( !iValidatedPair ); iConnCheck->iState = CIceConnectivityCheck::EICECheckInProgress; */ EUNIT_ASSERT_NO_LEAVE( iConnCheck->ConnCheckCompletedL( KErrUnknown, fromAddr, destAddr, mappedAddr ) ); EUNIT_ASSERT( KErrNone != iCheckResult ); EUNIT_ASSERT( !iValidatedPair ); // Wrong state iConnCheck->iState = CIceConnectivityCheck::EIceCheckWaiting; EUNIT_ASSERT_LEAVE( iConnCheck->ConnCheckCompletedL( KErrNone, fromAddr, destAddr, mappedAddr ) ); delete iConnCheck; iConnCheck = NULL; iLocalCand->SetType( CNATFWCandidate::EServerReflexive ); iConnCheck = CIceConnectivityCheck::NewL( *this, *iLocalCand, *iRemoteCand, *iConnHandler, *iCandStorage ); EUNIT_ASSERT_SPECIFIC_LEAVE( iConnCheck->PerformConnCheckL( CIceConnectivityCheck::EIceCheckTypePeriodic, priority, KTaTimerValueForChecks ), KErrArgument ); } }
void CRoadMapNativeSocket::ConnectWithParamsL() { TInetAddr addr; TBuf<256> hostName; char *hostname = NULL; char *separator = NULL; char *separator_slash = NULL; bool isIPAddr = false; int port = -1; int err = 0; hostname = strdup(m_hostname); roadmap_check_allocated(hostname); isIPAddr = isdigit(m_hostname[0]); separator = strchr (m_hostname, ':'); // Get port number, either parsing or default to the one supplied if (separator != NULL) { //TODO fix //port = s->GetPortFromService(separator+1); if (port < 0) { if (isdigit(separator[1])) { port = atoi(separator+1); if (port == 0) { roadmap_log (ROADMAP_ERROR, "invalid port in '%s'", m_hostname); free(hostname); User::Leave(KErrArgument); // bad params } } else { roadmap_log (ROADMAP_ERROR, "invalid service in '%s'", m_hostname); free(hostname); User::Leave(KErrArgument); // bad params } } *(strchr(hostname, ':')) = 0; } else { port = m_port; } // init addr with port addr.SetPort(port); // init addr with hostname (if any) GSConvert::CharPtrToTDes16(hostname, hostName); free(hostname); if (isIPAddr == true) { addr.Input(hostName); ConnectL(addr); } else { ConnectL(hostName, port); } }
void CEsockTest29::SetPort(TInetAddr &aAddr, const TInt aPort, const TDesC &aIPAddr) { aAddr.SetPort(aPort); aAddr.Input(aIPAddr); }
void CMSocketC::Connect(const CMString& sHost, UINT16 nPort) { //网络接入连接检查 CMNetConnMgr& mgr = CMNetConnMgr::Instance(); if (mgr.CurrentType() == CMNetConnMgr::NONE) { //未接入,开始接入 m_cTimer.SetTimerID(1); //使用TimerID来记重复次数 m_cTimer.Set(3*1000); //3秒检查 m_sHost = sHost; m_nPort = nPort; m_cTimer.Start(); return; } if (m_status != NOTCONNECTED) {//当前已有连接 // if (m_sHost == sHost && m_nPort == nPort) // { // //新连接于原始连接相同,重用 // if (m_status == CONNECTED) // {//取消现有操作 // CM_ERR("CMSocketC::Connect connect reserved"); // m_status = CONNECTED; // m_pNotify->OnConnect(MER_OK); // return; // } // CM_ERR("CMSocketC::Connect cancel!"); // Cancel(); // } // else { //关闭连接 Close(); } } CMString sTmp; if (!CMUrl::IsIP(sHost)) { CM_LOGP(CM_LOGL_DEBUG, "CMSocketC::Connect HostNameToIP %s", (const CHAR*)(CMString)sHost); sTmp = mgr.HostNameToIP(sHost); if (sTmp.IsEmpty()) { CM_ERRP("Host %s can't to addr", (const CHAR*)(CMString)sHost); m_pNotify->OnConnect(MERN_WRONG_PARAM); return; } } else { sTmp = sHost; } TInetAddr addr; TBuf<20> buf; buf = (const UINT16*)((const WCHAR*)(sTmp)); addr.SetPort(nPort); INT32 nErr = addr.Input(buf); if (nErr != KErrNone) { m_pNotify->OnConnect(MERN_WRONG_PARAM); return; } CM_LOGP(CM_LOGL_DEBUG, "CMSocketC::Connect Open start ip %s, port %d", (const CHAR*)sTmp, nPort); nErr = m_sk.Open(mgr.SocketServer(), KAfInet, KSockStream, KProtocolInetTcp //#if !defined(__WINSCW__) , mgr.Connection()); //#else // ); //#endif if (nErr != KErrNone && nErr != KErrAlreadyExists) { m_pNotify->OnConnect(MERN_INITIALIZE); return; } // iStatus = KErrNone; m_sk.Connect(addr, iStatus); m_status = CONNECTING; m_sHost = sHost; m_nPort = nPort; m_cTimer.Stop(); m_cTimer.Set(60 * 1000); //超时默认60秒 m_cTimer.Start(); SetActive(); return; }
//Check that XOR-MAPPED-ADDRESS is encoded correctly. void UT_CNATFWUNSAFMessage::TestEncodeMessageWithXorMappedAddrAttrL() { const TInt KMessageLength = 2 * CNATFWUNSAFAttribute::EValueOffset + CNATFWUNSAFXorMappedAddressAttribute::EAttributeValueSizeIPv4 + CNATFWUNSAFXorMappedAddressAttribute::EAttributeValueSizeIPv6; const TUint8 KExpectedResult[] = { 0, 1, //UNSAF message type: Binding Request 0, KMessageLength, //Message length (one XOR-MAPPED-ADDRESS attribute) 0x21, 0x12, 0xa4, 0x42, //Magic cookie 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, //TransactionID //XOR-MAPPED-ADDRESS attribute with IPv4 address 0, 0x20, //type //length of value element 0, CNATFWUNSAFXorMappedAddressAttribute::EAttributeValueSizeIPv4, 0, //undefined CNATFWUNSAFAddressAttribute::KAddressFamilyIPv4, //family 0x31, 0x0f, //x-port 0x2b, 0x46, 0x23, 0xb3, //x-address //XOR-MAPPED-ADDRESS attribute with IPv6 address 0, 0x20, //type //length of value element 0, CNATFWUNSAFXorMappedAddressAttribute::EAttributeValueSizeIPv6, 0, //undefined CNATFWUNSAFAddressAttribute::KAddressFamilyIPv6, //family 0x32, 0xd6, //x-port 0x8b, 0xa3, 0xaa, 0x32, //x-address 0x60, 0x62, 0x28, 0x9b, 0xff, 0x66, 0x67, 0x58, 0x65, 0x7b, 0x85, 0x07 }; //Add first attribute _LIT(KAddr, "10.84.135.241"); _LIT8(KTransactionId, "abcdefghijkl"); TInetAddr addr; User::LeaveIfError(addr.Input(KAddr)); addr.SetPort(4125); TNATFWUNSAFTransactionID taID(KTransactionId); CNATFWUNSAFAttribute* attr = CNATFWUNSAFXorMappedAddressAttribute::NewLC(addr, taID); iMsg->AddAttributeL(attr); CleanupStack::Pop(attr); attr = NULL; //Add second attribute TIp6Addr ip6addr; ip6addr.u.iAddr8[0] = 0xaa; ip6addr.u.iAddr8[1] = 0xb1; ip6addr.u.iAddr8[2] = 0x0e; ip6addr.u.iAddr8[3] = 0x70; ip6addr.u.iAddr8[4] = 0x01; ip6addr.u.iAddr8[5] = 0x00; ip6addr.u.iAddr8[6] = 0x4b; ip6addr.u.iAddr8[7] = 0xff; ip6addr.u.iAddr8[8] = 0x9a; ip6addr.u.iAddr8[9] = 0x00; ip6addr.u.iAddr8[10] = 0x00; ip6addr.u.iAddr8[11] = 0x30; ip6addr.u.iAddr8[12] = 0x0c; ip6addr.u.iAddr8[13] = 0x11; ip6addr.u.iAddr8[14] = 0xee; ip6addr.u.iAddr8[15] = 0x6b; TInetAddr addrIPv6; addrIPv6.SetAddress(ip6addr); addrIPv6.SetPort(5060); attr = CNATFWUNSAFXorMappedAddressAttribute::NewLC(addrIPv6, taID); iMsg->AddAttributeL(attr); CleanupStack::Pop(attr); attr = NULL; //Create encoded message CBufBase* msg = iMsg->EncodeL(); CleanupStack::PushL(msg); EUNIT_ASSERT(CNATFWUNSAFMessage::EHeaderSize + KMessageLength == msg->Size()); CompareEncodedUNSAFMessageL(KExpectedResult, *msg); CleanupStack::PopAndDestroy(msg); }