コード例 #1
0
ファイル: udp.cpp プロジェクト: ClearwaterCore/libre-upstream
int CUdpSocket::Open()
{
	TInt err;

	if (socketServer) {
		DEBUG_INFO("UDPsock(%p): Using RSocketServ=%p (handle=%d)\n",
			   us, socketServer, socketServer->Handle());

		iSocketServer = *socketServer;
	}
	else {
		err = iSocketServer.Connect();
		if (KErrNone != err) {
			DEBUG_WARNING("iSocketServer.Connect failed\n");
			return kerr2errno(err);
		}
	}

	if (rconnection) {
		DEBUG_INFO("UDPsock: Using RConnection=%p\n", rconnection);
		err = iSocket.Open(iSocketServer, KAfInet, KSockDatagram,
				   KProtocolInetUdp, *rconnection);
	}
	else {
		err = iSocket.Open(iSocketServer, KAfInet, KSockDatagram,
				   KProtocolInetUdp);
	}
	if (KErrNone != err) {
		DEBUG_WARNING("iSocket.Open failed (err=%d)\n", err);
		return kerr2errno(err);
	}

	return 0;
}
コード例 #2
0
int ILibSocketWrapper_socket(int socketType)
{
	int RetVal;

  // create a new connection for the socket
  RConnection* pConnection = new RConnection;

  // open a connection
  pConnection->Open(socketServer);

  TCommDbConnPref prefs;
  // set the preference for the requested interface
  prefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
  pConnection->Start(prefs);	

	if ( (socketType == SOCK_DGRAM) ||
       (socketType == SOCK_STREAM) )
	{
    RSocket *pSocket = new RSocket();

    if ( socketType == SOCK_DGRAM )
    {
      pSocket->Open(socketServer,
                    KAfInet,
                    KSockDatagram,
                    KProtocolInetUdp,
                    *pConnection);
    }
    else
    {
      pSocket->Open(socketServer,
                    KAfInet,
                    KSockStream,
                    KProtocolInetTcp,
                    *pConnection);
    }

    RetVal = ILibSocketWrapper_GetNextAvailableHandle();

    if( RetVal >= 0 )
    {
      SocketArray[RetVal] = (int)pSocket;
      ConnectionArray[RetVal] = pConnection;
    }
    else
    {
      pSocket->Close();
      delete pSocket;
      pConnection->Close();
      delete pConnection;
      RetVal = -1;
    }
  }

  return RetVal;
}
コード例 #3
0
void UT_CNATTraversalController::TestTlsSocketIdleL()
    {
     RSocket tcpSocket;
    User::LeaveIfError(tcpSocket.Open(iSocketServ,KAfInet,KSockStream,
                                      KProtocolInetTcp,iConnection));
    CleanupClosePushL(tcpSocket);
    _LIT(KTLS1,"TLS1.0");
    CSecureSocket* secureSocket = CSecureSocket::NewL(tcpSocket,KTLS1);
    CleanupStack::PushL(secureSocket);
    TBool asyncInitiated = EFalse;

    // Bindings do not exist
    iController->SocketIdle(EFalse,*secureSocket);
    iController->SocketIdle(ETrue,*secureSocket);

    // Binding exists
     CNATTraversalConfig* config =
        CNATTraversalConfig::NewLC(KIapId,KDomain);
    iController->CreateBindingL(1,config,iConnection,iLocalAddr,iSocket,
                                iNextHopAddr,*this,*this,asyncInitiated);
    CleanupStack::Pop(config);
    iController->SocketIdle(EFalse,*secureSocket);
    iController->SocketIdle(ETrue,*secureSocket);

    CleanupStack::PopAndDestroy(secureSocket);
    CleanupStack::PopAndDestroy(&tcpSocket);
    }
コード例 #4
0
// -----------------------------------------------------------------------------
// CTCPPortListener::RunL
// -----------------------------------------------------------------------------
//
void CTCPPortListener::RunL()
    {
    if ( iStatus.Int() == KErrNone )
        {
        // Allocate new RSocket first
        RSocket* next = new ( ELeave ) RSocket;
        CleanupStack::PushL( next );
        User::LeaveIfError( next->Open( iSocketServer ) );
        CleanupClosePushL( *next );

        // temp will be passed to observer
        RSocket* temp = iAcceptedSocket;

        // Takes ownership of temp immediately
        iObserver->ConnectionAcceptedL( temp );

        CleanupStack::Pop();        // *next
        CleanupStack::Pop( next );
        iAcceptedSocket = next;

        iListeningSocket.Accept( *iAcceptedSocket, iStatus );
        SetActive();
        DEBUG_PRINT( DEBUG_STRING(
            "CTCPPortListener::RunL(), connection accepted, port %d" ), iPort );
        }
    }
コード例 #5
0
TVerdict CRtpNegTests_02::doTestStepL()
/**
 * @return - TVerdict code
 */
	{
    SetTestStepResult(EFail);
    TInt err;
    TRequestStatus stat;
    if(KErrNone == InitSubConL())
    	{
    	RSocket sock;
    	err = sock.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iSubCon);
    	if(KErrNone == err)
    		{
    		iIpAddrLocal.SetPort(iLocalPort1);
    		sock.Bind(iIpAddrLocal);
    		iIpAddrDest1.SetPort(iDestPort1);
    		sock.Connect(iIpAddrDest1,stat);
    		User::WaitForRequest(stat);
    		if(KErrNone != stat.Int())
    			{
    			SetTestStepResult(EPass);
    			}
			sock.Close();
    		}
    	
	 	}    
    return TestStepResult();
	}
コード例 #6
0
TBool CSmsReplyToStep::WatchersAlreadyRunningL()
	{
	RSocketServ server;
	RSocket socket;

	User::LeaveIfError(server.Connect());
	CleanupClosePushL(server);

		// test if it's there... 
	TProtocolDesc protoInfo;
	TProtocolName protocolname;
	protocolname.Copy(KSmsDatagram);
	User::LeaveIfError(server.FindProtocol(protocolname,protoInfo));

	User::LeaveIfError(socket.Open(server,
										protoInfo.iAddrFamily,
										protoInfo.iSockType, 
										protoInfo.iProtocol));
	CleanupClosePushL(socket);
	

	TSmsAddr addr;
	addr.SetSmsAddrFamily(ESmsAddrRecvAny);
	TInt err = socket.Bind(addr);

	CleanupStack::Pop(2, &server);
	socket.CancelAll();
	socket.Close();
	server.Close();
	return (err == KErrAlreadyExists);
	}
コード例 #7
0
void CGetPortCommand::DoExecuteL()
    {
	TInt errorCode = KErrNone;
	RSocketServ	socketServer;
	errorCode = socketServer.Connect();
	if(errorCode  == KErrNone)
		{
	    RSocket listeningSocket;
		TSockAddr localAddress;
		//TODO: add retrying to find ports
		for(int i = 0; errorCode == KErrNone && i < iFreePortsNum; i++)
			{
			TInt port = iDriver->NextRandomPort();
			listeningSocket.Open(socketServer, KAfInet, KSockStream, KProtocolInetTcp);
			localAddress.SetPort(port); 
			errorCode = listeningSocket.Bind(localAddress);
			if(errorCode == KErrNone)
				{
				iFreePorts.Append(port);
				}
			listeningSocket.Close();
			}
		}
	socketServer.Close();
	User::LeaveIfError(errorCode);
    }
コード例 #8
0
ファイル: tcp.cpp プロジェクト: anchowee/traversal_server
int CTcpSock::Bind(TInetAddr &ia)
{
	TInt ret;

	ret = iSocket.Open(ts->cts->iSockServer->iSocketServer, ia.Family(),
			   KSockStream, KProtocolInetTcp);
	if (KErrNone != ret) {
		DEBUG_WARNING("bind: Open (ret=%d)\n", ret);
		goto error;
	}

	ret = iSocket.SetOpt(KSoReuseAddr, KSolInetIp, 1);
	if (KErrNone != ret) {
		DEBUG_WARNING("SetOpt ReuseAddr: ret=%d\n", ret);
	}

	ret = iSocket.Bind(ia);
	if (KErrNone != ret) {
		DEBUG_WARNING("bind: Bind (ret=%d)\n", ret);
		goto error;
	}

 error:
	return kerr2errno(ret);
}
コード例 #9
0
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;
	}
コード例 #10
0
TBool TestFrameworkActionsUtils::CheckIfSmsWatcherAlreadyRunningL()
	{
	RSocketServ socketServer;
	RSocket socket;
	
	User::LeaveIfError(socketServer.Connect());
	CleanupClosePushL(socketServer);

	TProtocolDesc protoInfo;
	TProtocolName protocolname;
	protocolname.Copy(KSmsDatagram);
	User::LeaveIfError(socketServer.FindProtocol(protocolname,protoInfo));
	User::LeaveIfError(socket.Open(socketServer,
										protoInfo.iAddrFamily,
										protoInfo.iSockType, 
										protoInfo.iProtocol));

	CleanupClosePushL(socket);
	
	TSmsAddr addr;
	addr.SetSmsAddrFamily(ESmsAddrRecvAny);
	TInt err = socket.Bind(addr);
	
	socket.CancelAll();
	CleanupStack::PopAndDestroy(2); //socketServer, socket
		
	return (err == KErrAlreadyExists);
	}
コード例 #11
0
TVerdict CSmsCapsWapSetLocalName::doTestStepL()
	{
	RSocket wapsock;
	TInt ret=wapsock.Open(iSocketServer,KWAPSMSAddrFamily,KSockDatagram,KWAPSMSDatagramProtocol);
	User::LeaveIfError(ret);
	CleanupClosePushL(wapsock);

	TWapAddr  wapAddr;

	wapAddr.SetWapPort(TWapPortNumber(9204));

	ret=wapsock.Bind(wapAddr);

	if(RProcess().HasCapability(ECapabilityNetworkServices))
		{
		TEST(ret != KErrPermissionDenied);
		}
	else
		{
		TEST(ret == KErrPermissionDenied);
		}

	CleanupStack::PopAndDestroy(&wapsock);

	return	TestStepResult() ;
	}
コード例 #12
0
TVerdict CSmsCapsSmsSetLocalName::doTestStepL()
	{

	RSocket socket;
	TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol);
	if(ret!=KErrNone)
		User::Leave(ret);
	CleanupClosePushL(socket);

	TSmsAddr smsaddr;
	smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny);

	ret=socket.Bind(smsaddr);

	if(RProcess().HasCapability(ECapabilityNetworkServices))
		{
		TEST(ret != KErrPermissionDenied);
		}
	else
		{
		TEST(ret == KErrPermissionDenied);
		}

	CleanupStack::PopAndDestroy(&socket);

	return	TestStepResult() ;
	}
コード例 #13
0
//
// Start asynchronous accept() operation.
//
pj_status_t CIoqueueCallback::StartAccept(pj_ioqueue_op_key_t *op_key,
        pj_sock_t *new_sock,
        pj_sockaddr_t *local,
        pj_sockaddr_t *remote,
        int *addrlen )
{
    PJ_ASSERT_RETURN(IsActive()==false, PJ_EBUSY);
    PJ_ASSERT_RETURN(pending_data_.common_.op_key_==NULL, PJ_EBUSY);

    // addrlen must be specified if local or remote is specified
    PJ_ASSERT_RETURN((!local && !remote) ||
                     (addrlen && *addrlen), PJ_EINVAL);

    pending_data_.accept_.op_key_ = op_key;
    pending_data_.accept_.new_sock_ = new_sock;
    pending_data_.accept_.local_ = local;
    pending_data_.accept_.remote_ = remote;
    pending_data_.accept_.addrlen_ = addrlen;

    // Create blank socket
    blank_sock_.Open(PjSymbianOS::Instance()->SocketServ());

    type_ = TYPE_ACCEPT;
    sock_->Socket().Accept(blank_sock_, iStatus);

    SetActive();
    return PJ_EPENDING;
}
コード例 #14
0
// -----------------------------------------------------------------------------
// CLocalAddrResolver::GetLocalAddrL
// -----------------------------------------------------------------------------
//
void CLocalAddrResolver::GetLocalAddrL(TInetAddr& aAddr, TUint32 aIap)
	{
	RSocket socket;
	User::LeaveIfError( socket.Open( *iServer, KAfInet, KSockDatagram, 
		                             KProtocolInetUdp ) );

	if (socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) == KErrNone )
		{
		TPckgBuf<TSoInetInterfaceInfo> opt;
		
		while ( socket.GetOpt( KSoInetNextInterface, KSolInetIfCtrl, opt ) == KErrNone)
			{
			TPckgBuf<TSoInetIfQuery> optifquery;
			optifquery().iName = opt().iName;
		
			if(socket.GetOpt( KSoInetIfQueryByName, KSolInetIfQuery, optifquery ) == KErrNone)
				{
				CheckAndSetAddr( aAddr, ( TInetAddr& )opt().iAddress,
				                 optifquery().iZone[1], aIap );
				}
			}
		}
		
	socket.Close();
	}
コード例 #15
0
// -----------------------------------------------------------------------------
// CMceLocalAddrResolver::RefreshLocalAddressesL
// -----------------------------------------------------------------------------
//
void CMceLocalAddrResolver::RefreshLocalAddressesL()
    {
    RSocket socket;
	User::LeaveIfError( socket.Open( iSocketServ, KAfInet, KSockDatagram, 
		                             KProtocolInetUdp ) );

	iAddr.Init( KAfInet );
	iIPv4Addr.Init( KAfInet );

	if ( socket.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) == KErrNone )
		{
		TPckgBuf<TSoInetInterfaceInfo> info;
		while ( socket.GetOpt( KSoInetNextInterface,
		                       KSolInetIfCtrl, info ) == KErrNone )
			{
			TPckgBuf<TSoInetIfQuery> query;
			query().iName = info().iName;
			if ( socket.GetOpt( KSoInetIfQueryByName,
			                    KSolInetIfQuery, query ) == KErrNone )
				{
				if ( Match( info(), query() ) )
				    {
                    SetAddressesIfNotSet( info().iAddress );
				    }
				}
			}
		}
		
	socket.Close();
	}	
コード例 #16
0
/**
   Create a UDP Socket and bind it to an arbitrary address

   @param aSocket The socket
   @param aAddress On return, contains the local socket name
   @return ETrue on success, EFalse otherwise
*/
TBool CEsockTest9_6::CreateUdpSocket( RSocket& aSocket, TSockAddr& aAddress )
	{
	// Open the socket
	TInt nRet = aSocket.Open( iEsockSuite->iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp );
	if( KErrNone != nRet )
		{
		Logger().WriteFormat(_L("Failed to open socket: return value = <%d>"), nRet );
		return EFalse;
		}

	// Bind to any address.
	//TInetAddr myAddress( KInetAddrAny, KInetPortAny );
	TInetAddr myAddress( KInetAddrLoop, KInetPortAny );
	nRet = aSocket.Bind( myAddress );
	if( KErrNone != nRet )
		{
		Logger().WriteFormat(_L("Failed to bind socket: return value = <%d>"), nRet );
		return EFalse;
		}

	// Retrieve the bound address
	aSocket.LocalName( aAddress );

	// Happy shiny
	return ETrue;
	}
コード例 #17
0
ファイル: netImpl.cpp プロジェクト: Felard/MoSync
SYSCALL(int, maConnGetAddr(MAHandle conn, MAConnAddr* addr)) {
	LOGST("maConnGetAddr(%i, 0x%08X)", conn, addr);
	if(conn == HANDLE_LOCAL) {
		if(addr->family == CONN_FAMILY_BT) {
			TBTDevAddr btaddr;
			//TPckgBuf<TBTDevAddr> pckg(btaddr);

			//old style, might work on Symbian 7.0 and earlier
			//update: doesn't work on 6630.
#if 0//!defined(__SERIES60_3X__)
			RSocket socket;
			socket.Open(gSocketServ, KBTAddrFamily, KSockSeqPacket, KL2CAP);
			TRequestStatus status;
			socket.Ioctl(KHCILocalAddressIoctl, status, &pckg, KSolBtHCI);
			User::WaitForRequest(status);
			LOG("KHCILocalAddressIoctl result: %i\n", status.Int());
			socket.Close();
			if(status != KErrNone) {
				return CONNERR_GENERIC;
			}
#else
#if 0	//doesn't work; bug in Symbian.
			int result = RProperty::Get(KUidSystemCategory,
				KPropertyKeyBluetoothGetLocalDeviceAddress, pckg);
			LOG("KPropertyKeyBluetoothGetLocalDeviceAddress result: %i\n", result);
			if(result != KErrNone) {
				return CONNERR_GENERIC;
			}
#else
			//open a server socket and read its address.
			RSocket socket;
			socket.Open(gSocketServ, KBTAddrFamily, KSockStream, KRFCOMM);
			int channel;
			LHEL_BASE(socket.GetOpt(KRFCOMMGetAvailableServerChannel, KSolBtRFCOMM, channel),
				return CONNERR_GENERIC);
			TBTSockAddr btsockaddr;
			btsockaddr.SetPort(channel);
			LHEL_BASE(socket.Bind(btsockaddr), return CONNERR_GENERIC);
			socket.LocalName(btsockaddr);
			socket.Close();
			btaddr = btsockaddr.BTAddr();
#endif	//0
#endif	//0//__SERIES60_3X__
			storeBtAddr(btaddr, addr);
			return 1;
		} else {	//TCP server
			return CONNERR_INTERNAL;
コード例 #18
0
ファイル: tcp.cpp プロジェクト: anchowee/traversal_server
int CTcpConn::Open(TInetAddr &ia)
{
	TInt ret;
	if (rconnection) {
		DEBUG_INFO("TCP Socket Open: Using RConnection=%p\n",
			   rconnection);
		ret = iSocket.Open(iSockServer->iSocketServer, ia.Family(),
				   KSockStream, KProtocolInetTcp,
				   *rconnection);
	}
	else {
		ret = iSocket.Open(iSockServer->iSocketServer, ia.Family(),
				   KSockStream, KProtocolInetTcp);
	}

	return kerr2errno(ret);
}
コード例 #19
0
enum TVerdict CSocketTest8_2::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Ioctl observes InternalOptionBit"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// get a protocol
	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
	TProtocolDesc protoInfo;
	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// check internal options bit
	RSocket socket;
	Logger().WriteFormat(_L("Opening a new socket"));
	ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Trying Ioctl on internal options bit"));
	TRequestStatus stat;
	socket.Ioctl(KInternalIoctlBit, stat);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrAccessDenied == stat.Int());
	
	Logger().WriteFormat(_L("Trying to SetOpt internal options bit"));
	ret = socket.SetOpt(KSocketInternalOptionBit, KSOLSocket);
	Logger().WriteFormat(_L("SetOpt returned %S"), &EpocErrorToText(ret));
	TESTL(KErrAccessDenied == ret);
	
	Logger().WriteFormat(_L("Trying to GetOpt internal options bit"));
	TPckgBuf<TBool> boolean;
	ret = socket.GetOpt(KSocketInternalOptionBit, KSOLSocket, boolean);
	Logger().WriteFormat(_L("GetOpt returned %S"), &EpocErrorToText(ret));
	TESTL(KErrAccessDenied == ret);
	
	Logger().WriteFormat(_L("Testing StartL() with Ioctl KDummyIoctlCheckStarted"));
	socket.Ioctl(KDummyIoctlCheckStarted, stat, NULL, KIoctlDummyLevel);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrNone == stat.Int());
	
	CleanupStack::Pop(&ss);
	ss.Close();
	
	SetTestStepResult(verdict);
	return verdict;
	}
コード例 #20
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;
}
コード例 #21
0
ファイル: sock_symbian.cpp プロジェクト: avble/natClientEx
/*
 * Create new socket/endpoint for communication and returns a descriptor.
 */
PJ_DEF(pj_status_t) pj_sock_socket(int af, 
				   int type, 
				   int proto,
				   pj_sock_t *p_sock)
{
    TInt rc;

    PJ_CHECK_STACK();

    /* Sanity checks. */
    PJ_ASSERT_RETURN(p_sock!=NULL, PJ_EINVAL);

    // Return failure if access point is marked as down by app.
    PJ_SYMBIAN_CHECK_CONNECTION();
    
    /* Set proto if none is specified. */
    if (proto == 0) {
	if (type == pj_SOCK_STREAM())
	    proto = KProtocolInetTcp;
	else if (type == pj_SOCK_DGRAM())
	    proto = KProtocolInetUdp;
    }

    /* Create Symbian RSocket */
    RSocket rSock;
    if (PjSymbianOS::Instance()->Connection())
    	rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
    			af, type, proto,
    			*PjSymbianOS::Instance()->Connection());
    else
    	rc = rSock.Open(PjSymbianOS::Instance()->SocketServ(), 
    			af, type, proto);
        
    if (rc != KErrNone)
	return PJ_RETURN_OS_ERROR(rc);


    /* Wrap Symbian RSocket into PJLIB's CPjSocket, and return to caller */
    CPjSocket *pjSock = new CPjSocket(af, type, rSock);
    *p_sock = (pj_sock_t)pjSock;

    return PJ_SUCCESS;
}
コード例 #22
0
enum TVerdict CSocketTest8_3::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Ioctl auto bind and check started"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
	CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// get a protocol
	Logger().WriteFormat(_L("Attempting to FindProtocol dummy protocol 1"));
	TProtocolDesc protoInfo;
	ret = ss.FindProtocol(_L("Dummy Protocol 1"), protoInfo);
	Logger().WriteFormat(_L("FindProtocol returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Opening a new socket"));
	RSocket socket;
	ret = socket.Open(ss, protoInfo.iAddrFamily, protoInfo.iSockType, protoInfo.iProtocol);
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	Logger().WriteFormat(_L("Testing StartL() with Ioctl KDummyIoctlCheckStarted"));
	TRequestStatus stat;
	socket.Ioctl(KDummyIoctlCheckStarted, stat, NULL, KIoctlDummyLevel);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrNone == stat.Int());
	
	Logger().WriteFormat(_L("Testing AutoBind()"));
	TSockAddr addr;
	Logger().WriteFormat(_L("Trying to Connect socket"));
	socket.Connect(addr, stat);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Connect returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrNone == stat.Int());
	
	Logger().WriteFormat(_L("Checking bound status with Ioctl"));
	socket.Ioctl(KDummyIoctlCheckBound, stat, NULL, KIoctlDummyLevel);
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrNone == stat.Int());
	
	CleanupStack::Pop(&ss);
	ss.Close();
	
	SetTestStepResult(verdict);
	return verdict;
	}
コード例 #23
0
TVerdict CSmsCapsSmsIoctlDeleteSms::doTestStepL()
	{

	RSocket socket;
	TRequestStatus status;
	TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol);
	if(ret!=KErrNone)
		User::Leave(ret);
	CleanupClosePushL(socket);

	TSmsAddr smsaddr;
	smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny);
	ret=socket.Bind(smsaddr);

	if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData))
		{
		TESTL(ret != KErrPermissionDenied);
		}
	else
		{
		// skip this one
		CleanupStack::PopAndDestroy(&socket);
		return TestStepResult() ;
		}



	// Create message with SRR
	_LIT(KText,"This is a simple SMS!");
	CSmsMessage* msg=CreateSmsMessageL(KText,TSmsDataCodingScheme::ESmsAlphabet7Bit);
	CleanupStack::PushL(msg);

	RSmsSocketWriteStream writestream(socket);
	writestream << *msg;
	writestream.CommitL();
	CleanupStack::PopAndDestroy(msg);

	socket.Ioctl(KIoctlDeleteSmsMessage, status, NULL, KSolSmsProv);
	User::WaitForRequest(status);

	if(RProcess().HasCapability(ECapabilityWriteUserData))
		{
		TEST(status.Int() != KErrPermissionDenied);
		}
	else
		{
		TEST(status.Int() == KErrPermissionDenied);
		}

	CleanupStack::PopAndDestroy(&socket);

	return TestStepResult();
	}
コード例 #24
0
TVerdict CSmsCapsSmsIoctlReadParamsSms::doTestStepL()
	{
	TInt testNo=13;

	RProperty testNumberProperty;
	User::LeaveIfError(testNumberProperty.Attach(KUidPSSimTsyCategory, KPSSimTsyTestNumber));
	CleanupClosePushL(testNumberProperty);

	TRequestStatus status;
	testNumberProperty.Subscribe(status);
	User::LeaveIfError(testNumberProperty.Set(KUidPSSimTsyCategory,KPSSimTsyTestNumber,testNo));
	User::WaitForRequest(status);
	TEST(status.Int() == KErrNone);
	TInt testNumberCheck;
	User::LeaveIfError(testNumberProperty.Get(testNumberCheck));
	if (testNo != testNumberCheck)
		User::Leave(KErrNotFound);

	CleanupStack::PopAndDestroy(&testNumberProperty);

	RSocket socket;
	TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol);
	if(ret!=KErrNone)
		User::Leave(ret);
	CleanupClosePushL(socket);

	TSmsAddr smsaddr;
	smsaddr.SetSmsAddrFamily(ESmsAddrLocalOperation);

	ret=socket.Bind(smsaddr);

	if(RProcess().HasCapability(ECapabilityNetworkServices))
		{
		TESTL(ret != KErrPermissionDenied);
		}
	else
		{
		// skip this one
		CleanupStack::PopAndDestroy(&socket);
		return TestStepResult() ;
		}


	socket.Ioctl(KIoctlReadSmsParams,status,NULL,KSolSmsProv);
	User::WaitForRequest(status);

	TEST(status.Int() != KErrPermissionDenied);

	CleanupStack::PopAndDestroy(&socket);

	return	TestStepResult() ;
	}
コード例 #25
0
void CApConnectEngine::FetchIpAddressL()
{
	RSocket socket;
	CleanupClosePushL( socket);
	while (socket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp,
			iConnect)!= KErrNone)
	{
	};
	TSoInetInterfaceInfo inf;
	TPckg<TSoInetInterfaceInfo> opt( inf);
	TRAPD(err, socket.SetOpt (KSoInetEnumInterfaces, KSolInetIfCtrl ))
	;
	if (err != KErrNone)
	{
		return;
	}

	while ( socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt)== KErrNone)
	{
		if ( inf.iAddress.Address()==0) // if the stored address is not an IPv4 address
		{
		}
		else
		{
			if ( inf.iAddress.IsUnspecified())
			{
				// Interface inf.iName has no address        	
			}
			else
			{
				// have to do this, strange
				TInetAddr addr;
				addr.SetAddress( inf.iAddress.Address());
				addr.Output(iConnInfo.ipAddress);
				// have to do this, strange

				if ( iConnInfo.ipAddress.Compare(KZeroIP)!= 0 && iConnInfo.ipAddress.Compare(KLocalIP)!= 0)
				{
					if ( iConnInfo.ipAddress.Left(3).Compare(_L("169"))!= 0)
					{
						CleanupStack::PopAndDestroy(); // socket
						return;
					}
				}
			}
		}
	}
	CleanupStack::PopAndDestroy(); // socket	
}
コード例 #26
0
/* 
 * Open an Explicit UDP Socket
 */
void CMultipleArray::OpenExplicitUdpSocketL(TInt aExtraSocksToJoin, RSocketServ iSocketServer)
	{
   /* Get number of sockets from script
	* Open a UDP socket
	* Store socket handle
	* Return the EFail or EPass
	*/
	RSocket* sock;
	RConnection* conn;
	TCommDbConnPref prefs;
	TInt err = 0;
		
	sock = new (ELeave) RSocket;
	conn = new (ELeave) RConnection;
	CleanupStack::PushL(sock);
	CleanupStack::PushL(conn);

	// Start an outgoing connection
	err = conn->Open(iSocketServer);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open Connection: return value = <%d>"), err);
		User::Leave(err);
		}
		
	// Setup SetBearerSet
	prefs.SetBearerSet(iSetBearerSet[aExtraSocksToJoin]);	
	// Setup IAP
	prefs.SetIapId(iIAP[aExtraSocksToJoin]);

	err = conn->Start(prefs);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err);
		User::Leave(err);
		}

	err = sock->Open(iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp, *conn);
	if (err!=KErrNone)
		{
		iQoSStep->iQoSSuite->Log(_L("Failed to open socket: return value = <%d>"), err);
		User::Leave(err);
		}
		
	AddSocketToListL(sock);
	AddConnectionToListL(conn);

	CleanupStack::Pop(2);	//sock and conn
	}
コード例 #27
0
enum TVerdict CSocketTest8_5::InternalDoTestStepL( void )
	{
	TVerdict verdict = EPass;
	
	Logger().WriteFormat(_L("Test Purpose: Ioctl returns not started on null socket"));
	
	// connect to esock
	Logger().WriteFormat(_L("Attempting to connect to socket server"));
    RSocketServ ss;
	TInt ret = OptimalConnect(ss);
    CleanupClosePushL(ss);
	Logger().WriteFormat(_L("Connect returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// Added test for defect: DEF043787 	SAP never gets told to cancel an Ioctl if client calls RSocket::CancelAll().
	_LIT(KSomeProtocol, "Dummy Protocol 1");
	RSocket socket;
	ret = socket.Open(ss, KSomeProtocol);
	CleanupClosePushL(socket);
	Logger().WriteFormat(_L("Open returned %S"), &EpocErrorToText(ret));
	TESTL(KErrNone == ret);
	
	// Do test IOCTL thats never completes, then cancel it
	Logger().WriteFormat(_L("Do IOCTL/CancelALL."));
	TRequestStatus stat;
	socket.Ioctl(KDummyIoctlIgnore, stat);
	socket.CancelAll();
	User::WaitForRequest(stat);
	Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
	TESTL(KErrCancel == stat.Int());
	
	// Now query for the result of the previous IOCtl.
	socket.Ioctl(KDummyIoctlCancelled, stat);
	User::WaitForRequest(stat);
	if(stat==KErrNotFound)
		{
		Logger().WriteFormat(_L("Ioctl returned with status %S: CancelAll failed to cancel previous IOCTL."), &EpocErrorToText(stat.Int()));
		}
	else
		{
		Logger().WriteFormat(_L("Ioctl returned with status %S"), &EpocErrorToText(stat.Int()));
		}
	TESTL(KErrNone == stat.Int());
	
	CleanupStack::PopAndDestroy(2,&ss); // socket, ss
	SetTestStepResult(verdict);
	return verdict;
	}
コード例 #28
0
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;
}
コード例 #29
0
ファイル: sock.c プロジェクト: AmoebaLabs/pjsip
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;
}
コード例 #30
0
TVerdict CSmsCapsSmsIoctlEnumerateSms::doTestStepL()
	{
	RSocket socket;
	TRequestStatus status;
	TInt ret=socket.Open(iSocketServer,KSMSAddrFamily,KSockDatagram,KSMSDatagramProtocol);
	CleanupClosePushL(socket);

	if(ret!=KErrNone)
		User::Leave(ret);

	TSmsAddr smsaddr;
	smsaddr.SetSmsAddrFamily(ESmsAddrRecvAny);
	ret=socket.Bind(smsaddr);

	if(RProcess().HasCapability(ECapabilityWriteUserData, ECapabilityNetworkServices) && RProcess().HasCapability(ECapabilityReadUserData))
		{
		TESTL(ret != KErrPermissionDenied);
		}
	else
		{
		// skip this one
		CleanupStack::PopAndDestroy(&socket);
		return TestStepResult() ;
		}


	TPckgBuf<TUint> sbuf;
	sbuf()=0;

	// test cancel first - due to Lubbock problems canceled out
	socket.Ioctl(KIoctlEnumerateSmsMessages,status,&sbuf, KSolSmsProv);

	User::WaitForRequest(status);

	if(RProcess().HasCapability(ECapabilityReadUserData))
		{
		TEST(status.Int() != KErrPermissionDenied);
		}
	else
		{
		TEST(status.Int() == KErrPermissionDenied);
		}

	CleanupStack::PopAndDestroy(&socket);

	return	TestStepResult() ;
	}