enum TVerdict CTestIdna01::doTestStepL()
	{

	INFO_PRINTF1(_L(" Testing GetByName(IDN) 	without IDN Enabled     "));
	INFO_PRINTF1(_L("****************************************************"));
	
	SetTestStepResult(EFail); // By default start the test case with failure.	
	
	RSocketServ pSocketServ;
	User::LeaveIfError(pSocketServ.Connect());
	RConnection myConnection;
	myConnection.Open(pSocketServ, KAfInet);

	TRequestStatus myStatus=KErrNone;
	myConnection.Start(myStatus);
	User::WaitForRequest(myStatus);

	_LIT(KTestName1,"räksmörgås.josefsson.org");
		
	TName myHostName = KTestName1();
	TNameEntry myResolvedName;
	RHostResolver hr;
	hr.Open(pSocketServ,KAfInet,KProtocolInetUdp);

	hr.GetByName(myHostName,myResolvedName,myStatus);
		
	User::WaitForRequest(myStatus);
	TInt err = myStatus.Int();
	
	if(err == KErrDndNameNotFound)
		{
		INFO_PRINTF2(_L(" GetByName(%S) 	without IDN Enabled   returned KErrDndNameNotFound "),&myHostName);
		SetTestStepResult(EPass);
		}
	
	hr.Close();
	myConnection.Close();
	pSocketServ.Close();

	return TestStepResult();

	}
XQAccessPoint XQAccessPointManagerPrivate::systemAccessPointL() const
{
    XQAccessPoint iap;

    RSocketServ serv;
    TInt retVal = serv.Connect();
    if (retVal != KErrNone) {
        return iap;
    }
    CleanupClosePushL(serv);
    RConnection conn;
    retVal = conn.Open(serv);
    if (retVal != KErrNone) {
        CleanupStack::PopAndDestroy(&serv);
        return iap;
    }
    CleanupClosePushL(conn);
    retVal = conn.Start();
    if (retVal != KErrNone) {
        CleanupStack::PopAndDestroy(&conn);
        CleanupStack::PopAndDestroy(&serv);
        return iap;
    }
    
    _LIT(KSetting, "IAP\\Id");
    unsigned long int iapId = 0;
    conn.GetIntSetting(KSetting, iapId);

    CleanupStack::PopAndDestroy(&conn);
    CleanupStack::PopAndDestroy(&serv);

    QList<XQAccessPoint> iaps = accessPoints();
    for (int i=0; i < iaps.count(); i++) {
        if (iaps[i].id() == iapId) {
            iap = iaps[i];
            break;
        }
    }
    
    return iap;
}
示例#3
0
void CTcpProcess::ConstructL()
	{
	//Create the data buffer
	User::LeaveIfError(iSendBuf.Create(iSize));
	User::LeaveIfError(iRecvBuf.Create(iSize));
	iRecvSize = iSize;
	
	iProcessState = ECreateConnection;
	
	User::LeaveIfError(iSockServ.Connect());
	if(iMode)
		{
		//Listen at specified port
		TBuf<5>		 protocol = _L("tcp");
		User::LeaveIfError(iListenSocket.Open(iSockServ, protocol));
		User::LeaveIfError(iListenSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1));
		User::LeaveIfError(iListenSocket.SetLocalPort(iPort));
		User::LeaveIfError(iListenSocket.Listen(5));
		User::LeaveIfError(iSocket.Open(iSockServ));
		iListenSocket.Accept(iSocket, iStatus);
		iConsole.Printf(_L("\nWait for a connection at port[%d].\n"), iPort);
		}
	else
		{
        RConnection conn;  
        User::LeaveIfError(conn.Open(iSockServ));
        TCommDbConnPref pref;
        pref.SetIapId(13);
        pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
        User::LeaveIfError(conn.Start(pref));
        
		//Connect to specified server
		User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockStream, KProtocolInetTcp, conn));
		iSocket.Connect(iAddr, iStatus);

		iConsole.Printf(_L("\nConnecting....\n"));
		}
	SetActive();
	}
示例#4
0
void CUdpProcess::ConstructL()
    {
    //Create the data buffer
    User::LeaveIfError(iSendBuf.Create(iSize));
    User::LeaveIfError(iRecvBuf.Create(iSize));
    iRecvSize = iSize;

    User::LeaveIfError(iSockServ.Connect());

    // Start NCM IAP
    RConnection conn;
    User::LeaveIfError(conn.Open(iSockServ));
    TCommDbConnPref pref;
    pref.SetIapId(13);
    pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    User::LeaveIfError(conn.Start(pref));
    
    User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockDatagram,
            KProtocolInetUdp, conn));
    
    iConsole.Printf(_L("In constructL, port=%d"), iAddr.Port());
    
    if (iMode)
        {
        iProcessState = EDataTransfer;
       
        User::LeaveIfError(iSocket.SetLocalPort(iPort));
        iSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus);
        iConsole.Printf(_L("\nWait for UDP incoming data at port[%d]...\n"),iPort);
        SetActive();
        }
    else 
        {
        iProcessState = EDataSending;
        SetActive();
        TRequestStatus* status = &iStatus;
        User::RequestComplete(status, KErrNone);
        }
    }
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;
	}
示例#6
0
// Main
void MainL()
{
    /* Arguments:
    Not implemented in this test case.
    Note: Implement if necessary
     */


    /* Connection part:
    Here we want to open all requirements:
    	- RSocketServer connection
    	- RSocket
    We also want to start RConnection
     */

    // Connect to socket server
    console->Printf(_L("Connect RSocketServ ... "));
    RSocketServ socketServ;
    CleanupClosePushL(socketServ);
    User::LeaveIfError(socketServ.Connect());
    console->Printf(_L("OK\n"));

    // Open RConnection
    console->Printf(_L("Open RConnection ... "));
    RConnection connect;
    CleanupClosePushL(connect);
    User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault));
    console->Printf(_L("OK\n"));

    // Start RConnection
    console->Printf(_L("Start RConnection ... "));

    /* In a real inetd you would probably want to avoid the IAP prompting.
    You could do it this way:

    TCommDbConnPref prefs;
    prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
    User::LeaveIfError(connect.Start(prefs));	// Handle options here (ie: No Prompt)

    */
    User::LeaveIfError(connect.Start());
    console->Printf(_L("OK\n"));


    /* Configuration file:
    We read configuration file.
    We will create a listener for each line.
    It will listen and accept connection for the
    specified protocol, then it will launch
    the appropriate program and continue
    to listen.

    Our basic inetd.conf file is:
    	==> ServiceName: Contains the name of an Internet service.
    	==> SocketType: Specifies which socket to use.
    	==> ProtocolName: Contains the name of an Internet protocol.
    	==> ProtocolPort: Specifies which port to use.
    	==> ServerName: Contains the name of program to launch.
    	==> ServerArgs: Contains program arguments.
     */

    // Connect to file server
    console->Printf(_L("Connect to file server ... "));
    TListeners listeners;
    CleanupStack::PushL(TCleanupItem(TCleanupOperation(DestroyPointerArray), &listeners));
    RFs fileServ;
    CleanupClosePushL(fileServ);
    User::LeaveIfError(fileServ.Connect());
    console->Printf(_L("OK\n"));

    // Search file
    TFindFile ff(fileServ);
    TInt ret = ff.FindByDir(KConfigFileName, KConfigFileDir);
    if(ret != KErrNone)
    {
        if(ret == KErrNotFound)
        {
            console->Printf(_L("Can't find file '%S'\n"), &KConfigFileName);
        }
        else
        {
            User::LeaveIfError(ret);
        }
    }
    else
    {
        // File Open
        console->Printf(_L("Open file ... "));
        RFile configFile;
        CleanupClosePushL(configFile);
        ret = configFile.Open(fileServ, ff.File(), EFileRead);
        if(ret != KErrNone)
        {
            if(ret == KErrNotFound)
            {
                console->Printf(_L("Can't open file '%S'\n"), &KConfigFileName);
            }
            else
            {
                User::LeaveIfError(ret);
            }
        }
        else
        {
            console->Printf(_L("OK\n"));

            // Read File (Here, we read the whole file as we know it's small. Not optimal)
            ReadConfigFileL(configFile, listeners, socketServ, connect);
        }

        // We have Finished with file
        CleanupStack::PopAndDestroy(&configFile);
    }

    // We have finished with file server
    CleanupStack::PopAndDestroy(&fileServ);

    // Test here for the number of listeners or any config file error.
    // If 0, then we've got no configuration in file
    console->Printf(_L("NbListeners: %d\n"), listeners.Count());

    if(listeners.Count() != 0)
    {
        /* Launch listeners
        Start the active scheduler
         */
        console->Printf(_L("Start ... \n"));
        // Set up timer to stop inetd (Test case implementation)
        CInetdExitTimer* timeToRun = CInetdExitTimer::NewL();
        CleanupStack::PushL(timeToRun);
        timeToRun->After(KRunTime);

        // Start active scheduler for listeners to accept
        CActiveScheduler::Start();

        // End of Inetd, triggered by CInetdExitTimer::RunL()
        console->Printf(_L("Stop\n"));

        CleanupStack::PopAndDestroy(timeToRun);	// Delete timeToRun
    }

    /* Destroy listeners
    Cancel all pending listeners
    Delete them
     */
    console->Printf(_L("Delete listeners ... "));
    CleanupStack::PopAndDestroy(&listeners);
    console->Printf(_L("OK\n"));

    // Close all opened stuff
    console->Printf(_L("Closing ... "));
    CleanupStack::PopAndDestroy(&connect);
    CleanupStack::PopAndDestroy(&socketServ);
    console->Printf(_L("End\n"));
}
示例#7
0
// Main 
void MainL()
	{
	/* Inetd Setup 
	Create a inetd process 
	*/
	RProcess inetd;
	CleanupClosePushL(inetd);
	User::LeaveIfError(inetd.Create(_L("inetd"), _L("")));
	
	// Resume inetd
	inetd.Resume();
	
	// Wait for inetd to be ready
	console->Printf(_L("[ press any key ]"));
	console->Getch();	// Get and ignore character

	
	/* IPEcho Part 
	Connect to socket server 
	*/
	console->Printf(_L("Connect to socket server ... \n"));
	RSocketServ socketServ;
	CleanupClosePushL(socketServ);
	User::LeaveIfError(socketServ.Connect());
	
	// Open RConnection
	console->Printf(_L("Open RConnection ... \n"));
	RConnection connect;
	CleanupClosePushL(connect);
	User::LeaveIfError(connect.Open(socketServ, KConnectionTypeDefault));

	// Start RConnection
	console->Printf(_L("Start RConnection ... \n"));
	TCommDbConnPref prefs;
	prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
	User::LeaveIfError(connect.Start(prefs));	// Handle options here like (ie: No Prompt)

	// Open RSocket
	console->Printf(_L("Open Socket ... \n"));
	RSocket sock;
	CleanupClosePushL(sock);
	User::LeaveIfError(sock.Open(socketServ, KAfInet, KSockStream, KProtocolInetTcp, connect));

	// Connect
	console->Printf(_L("Connect Socket ... \n"));
	TRequestStatus status;
	TInetAddr echoServAddr(KInetAddrLoop, 7);	// 7: TCP port 
	sock.Connect(echoServAddr, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());

	// Wait for the socket transfer to be over 
	console->Printf(_L("[ press any key ]"));
	console->Getch();	// Get and ignore character
	
	// Send a packet
	console->Printf(_L("Send a packet ... \n"));
	HBufC8* packet = HBufC8::NewL(KSocketDefaultBufferSize);
	CleanupStack::PushL(packet);

	packet->Des().SetMax();
	packet->Des().FillZ();
	sock.Send(packet->Des(), 0, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());
	
	// Receive it back
	console->Printf(_L("Received it back ... \n"));
	packet->Des().Zero();
	TPtr8 buff = packet->Des();
	sock.Recv(buff, 0, status);
	User::WaitForRequest(status);
	User::LeaveIfError(status.Int());

	
	// Terminates 
	console->Printf(_L("Terminates ... \n"));
	CleanupStack::PopAndDestroy(packet);
	CleanupStack::PopAndDestroy(&sock);
	CleanupStack::PopAndDestroy(&connect);
	CleanupStack::PopAndDestroy(&socketServ);
	CleanupStack::PopAndDestroy(&inetd);
	}
enum TVerdict CTestStepNullAgtLoopbackTest::doTestStepL(void)
{
    __UHEAP_MARK;

    TInt r;                // the result of various operations
    TRequestStatus status; // status of asynchronous ops

    RSocketServ server;    // connection paraphanelia
    RConnection connection;
    RSocket socket;

    TInetAddr dest;
    dest.SetAddress(KDummyNifLocalAddressBase + 4);
    dest.SetPort(KPortNo);

    TBuf8<KBufferLength> buffer;

    // connect to the socket server
    r = server.Connect();
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(server);

    // this is why we needed a socket server...
    r = connection.Open(server, KAfInet);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(connection);

    // start the connection up (outgoing)
    connection.Start(status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // open a udp socket
    r = socket.Open(server, KAfInet, KSockDatagram, KProtocolInetUdp);
    TESTEL(r == KErrNone, r);
    CleanupClosePushL(socket);
    TESTL(socket.SetOpt(KSoReuseAddr, KSolInetIp, 1)==KErrNone);
    // set the source port number - otherwise will panic cos it's zero
    r = socket.SetLocalPort(KPortNo);
    TESTEL(r == KErrNone, r);

    // build some data to send on the socket
    // this is an ICMP ping request apparently
    buffer.SetMax();
    buffer.FillZ();
    buffer[0] = (TUint8) 0x8;		// ICMP type = 8
    buffer[1] = (TUint8) 0x0;		// ICMP code = 0
    buffer[2] = (TUint8) 0xF7;		// ICMP checksum high byte
    buffer[3] = (TUint8) 0xFF;		// ICMP checksum low byte
    // NB the rest of the buffer is zero
    // hence the checksum (0xFFFF - 0x800) since 0x8
    // is the only non-zero element of the buffer

    // send the data out over the socket
    socket.SendTo(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    buffer.Zero();
    // I expect to get the data looped back from the dummy NIF
    socket.RecvFrom(buffer, dest, 0, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());

    // check that what we sent is what we got back
    if (status.Int() == KErrNone)
    {
        // if the receive times out and we access buffer we get a panic
        TEST(buffer[0] == 0x08);
        TEST(buffer[1] == 0x00);
        TEST(buffer[2] == 0xF7);
        TEST(buffer[3] == 0xFF);
    }

    // close the socket
    socket.Shutdown(RSocket::ENormal, status);
    User::WaitForRequest(status);
    TESTEL(status.Int() == KErrNone, status.Int());
    CleanupStack::Pop();

    // force the destruction of the connection
    r = connection.Stop();
    TESTEL(r == KErrNone, r);
    CleanupStack::Pop();

    // close the socket server
    server.Close();
    CleanupStack::Pop();

    __UHEAP_MARKEND;

    return iTestStepResult;
}
示例#9
0
enum TVerdict CTestStepLoopback::doTestStepL()
	{
	SetTestStepResult(EFail);
	
//	const TUid KPktTxKey = {0x104045dd};
//	const TUid KPktRxKey = {0x104045de};
//	const TUid KMeUid = {0x101F529F};
//	TSecurityPolicy readPolicy(ECapability_None);
//	TSecurityPolicy writePolicy(ECapability_None);
//	TInt result = RProperty::Define(KMeUid, KPktTxKey .iUid, RProperty::EInt, readPolicy, writePolicy);
//	result = RProperty::Define(KMeUid, KPktRxKey .iUid, RProperty::EInt, readPolicy, writePolicy);
	
	
	RSocketServ ss;
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Start: creating + starting connection"));
	User::LeaveIfError(ss.Connect());
	RConnection conn;
	CleanupClosePushL(conn);
	User::LeaveIfError(conn.Open(ss));
	User::LeaveIfError(conn.Start());

	TInt srvPort;
	if(!GetIntFromConfig(_L("TcpLoop"), _L("Port"), srvPort))
		{
		srvPort = 5002;
		}
	Logger().WriteFormat(_L("Start: creating server socket listening on %d"), srvPort);
	RSocket srv;
	CleanupClosePushL(srv);
	User::LeaveIfError(srv.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn));
	TInetAddr srvAddr(KAfInet);
	srvAddr.SetPort(srvPort);
	User::LeaveIfError(srv.Bind(srvAddr));
	User::LeaveIfError(srv.Listen(5));
	RSocket acc;
	CleanupClosePushL(acc);
	User::LeaveIfError(acc.Open(ss));
	TRequestStatus accStat;
	srv.Accept(acc, accStat);
	
	Logger().WriteFormat(_L("Start: connecting client socket"));
	RSocket cli;
	CleanupClosePushL(cli);
	User::LeaveIfError(cli.Open(ss, KAfInet, KSockStream, KProtocolInetTcp, conn));
	srvAddr.SetAddress(0xC0A80707);
	TRequestStatus cliStat;
	cli.Connect(srvAddr, cliStat);
	User::WaitForRequest(cliStat, accStat);
	User::WaitForRequest(cliStat, accStat);
	User::LeaveIfError(cliStat.Int());
	User::LeaveIfError(accStat.Int());

	//_LIT8(KTest, "jackdaws love my big sphinx of quartz");
	
	TInt xferSize = 0;
	if(!GetIntFromConfig(_L("TcpLoop"), _L("xferSize"), xferSize))
		{
		xferSize = 1 * 1000 * 1000;
		}
	TInt fc = User::FastCounter();
	TInt txSize = 0;
	TInt txCnt = 0;
	TRequestStatus txStat(KErrNone);
	TBuf8<4096> txBuf;
	txBuf.SetMax();
	TInt rxSize = 0;
	TInt rxCnt = -1;
	TRequestStatus rxStat(KErrNone);
	TBuf8<4096> rxBuf;
	
	Logger().WriteFormat(_L("Transferring %d bytes"), xferSize);
	while(rxSize < xferSize)
		{
		fc = User::FastCounter();
		if(txStat.Int() != KRequestPending)
			{
			RDebug::Printf("tx status:%d, ", txStat.Int());
			cli.Send(txBuf, 0, txStat);
			++txCnt;
			txSize += txBuf.Length();
			RDebug::Printf("tx #%d, %d, +%d\n", txCnt, fc, txBuf.Length());
			}
		if(rxStat.Int() != KRequestPending)
			{
			RDebug::Printf("rx status:%d, ", rxStat.Int());
			++rxCnt;
			rxSize += rxBuf.Length();
			RDebug::Printf("rx #%d, %d, +%d\n", rxCnt, fc, rxBuf.Length());
			TSockXfrLength dummy;
			acc.RecvOneOrMore(rxBuf, 0, rxStat, dummy);
			}
		User::WaitForRequest(rxStat, txStat);
		}
	
	Logger().WriteFormat(_L("Transferred; %d writes, %d reads"), txCnt, rxCnt);
	
//	RProperty::Get(KUidSystemCategory, KPktTxKey .iUid, txCnt);
//	RProperty::Define(KUidSystemCategory, KPktRxKey .iUid, rxCnt);
//	Logger().WriteFormat(_L("Packet counts; %d sends, %d processes"), txCnt, rxCnt);
	
	
	CleanupStack::PopAndDestroy(5, &ss);
	
	SetTestStepResult(EPass);
	return TestStepResult();
	};