예제 #1
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);
    }
예제 #2
0
파일: Server.cpp 프로젝트: kkskipper/KNOWME
void CServer::ListenL() // for local client
    {
	_LIT(KTCP, "tcp");
    TSockAddr sockAddr;
    sockAddr.SetPort(CProperties::KLocalPort);
	iListener->StartListeningL(KTCP, sockAddr, KMaxConn);
    }
예제 #3
0
void CResolvingConnecter::AoEventOccurred(CActive* aOrig, TInt aError)
{
    if (!IsActive())
    {
        User::Invariant();
        return;
    }
    if ((iState == 1) && (aOrig == iDnsResolver))
    {
        if (aError == KErrNone)
        {
            TSockAddr addr;
            iDnsResolver->GetResult(addr);
            addr.SetPort(iPort);
            iSocketConnecter->Connect(addr);
            iState = 2;

            return;
        }
    }
    else if ((iState == 2) && (aOrig == iSocketConnecter))
    {
        iState = 3;
    }
    else
    {
        User::Invariant();
    }
    TRequestStatus* status = &iStatus;
    User::RequestComplete(status, aError);
}
예제 #4
0
CRtpHandlerBase* CRtpHandlerBase::NewBearerL(CRtpControllerBase* aController,
											 RSocket& aSocket, TInt aPriority)
	{	
	__RTP_LOG(_L("CRtpHandlerBase::NewBearerL() ... "));
	__ASSERT_DEBUG(aController, Panic(ERtpControllerIsNotCreated));
	CRtpHandlerBase* handler = NULL;
	TSockAddr localAddr;
	aSocket.LocalName(localAddr);
	switch (localAddr.Family())
		{
		// BT can be made configurable,  see rtpbthandler.h for more details...
		case KBTAddrFamily:
			{
			handler = CRtpBluetoothHandler::NewL(aSocket, aPriority);
			handler->iRtpController = (CRtpControllerBase *)aController;
			break;
			}
		case KAfInet:
		default:
			{
			handler = CRtpUdpHandler::NewL(aSocket, aPriority);		
			handler->iRtpController = (CRtpControllerBase *)aController;
			break;
			}
		
		}
	handler->SetLocalAddress(localAddr);
	return handler;
	}
예제 #5
0
TInt CIpcProvdBase::SetLocalName(TSockAddr &anAddr)
//
// Set the local name prior to accepting
//
	{
	TInt ret=iProtocol->CheckAndAllocatePortNumber(anAddr.Port());
	if (ret==KErrNone)
		iLocalAddr=anAddr.Port();
	return ret;
	}
예제 #6
0
void CDHCPMessageHeaderIP4::GetCHAddr(TSockAddr& aSockAddr) 
/**
  * Retrieve Your IP Address from message
  *
  * @internalTechnology  *
  */
	{
	aSockAddr.SetFamily(KAFUnspec);
	aSockAddr.SetLength(KHwAddrOffset);
	aSockAddr.Append(iChaddr.GetBodyDes());
	}	
예제 #7
0
void CDHCPMessageHeaderIP4::SetCHAddr(TSockAddr& aAddr)
/**
  * Sets If Hardware Address in message
  *
  * @internalTechnology
  * 
  */
	{
	TUint len = aAddr.Length()-KHwAddrOffset;
	if(len > KIp4ChAddrMaxLength) { len = KIp4ChAddrMaxLength; }
	iChaddr.GetBodyDes().Copy(aAddr.Mid(KHwAddrOffset, len));
	}
예제 #8
0
TBool CRtpHandlerBase::CompareAddresses(const TSockAddr& aAddr1,const TSockAddr& aAddr2)
{
	if(aAddr1.Family() != aAddr2.Family())
		{
		return EFalse;
		}
		
	TInetAddr inetAddr1(aAddr1);
	TInetAddr inetAddr2(aAddr2);
	//Tests the protocol family, IP address, and port values
	TBool flag = inetAddr1.CmpAddr(inetAddr2);
	return flag;
}
예제 #9
0
void CIpcProvdBase::LocalName(TSockAddr &anAddr)const
//
//  Get hte local name
//
	{
	anAddr.SetPort(iLocalAddr);
	}
예제 #10
0
void CIpcProvdBase::RemName(TSockAddr &anAddr)const
//
// Get the remote name we would connect to
//
	{
	anAddr.SetPort(iRemoteAddr);
	}
예제 #11
0
파일: netImpl.cpp 프로젝트: Felard/MoSync
static void storeSockAddr(const TSockAddr& sockaddr, MAConnAddr* addr) {
	LOGS("storeSockAddr %i\n", sockaddr.Family());
	if(sockaddr.Family() == KBTAddrFamily) {
		addr->family = CONN_FAMILY_BT;
		addr->bt.port = sockaddr.Port();
		TBTSockAddr& bt((TBTSockAddr&)sockaddr);
		storeBtAddr(bt.BTAddr(), addr);
	} else if(sockaddr.Family() == KAfInet) {
		addr->family = CONN_FAMILY_INET4;
		addr->inet4.port = sockaddr.Port();
		TInetAddr& inet((TInetAddr&)sockaddr);
		addr->inet4.addr = inet.Address();
	} else {
		DEBIG_PHAT_ERROR;
	}
}
예제 #12
0
TInt  CIpcProvdBase::SetRemName(TSockAddr& anAddr)
//
// Set the remote name prior to connecting (or as part of a send to)
//
	{
	iRemoteAddr=anAddr.Port();
	return KErrNone;
	}
예제 #13
0
void CDHCPMessageHeaderIP4::GetClientHwAddr(TSockAddr& aSockAddr) 
	{
/**
  * Return the Client Hardware Address.
  *
  * @internalTechnology
  */
	aSockAddr.Append(iChaddr.GetBodyDes());
	}
예제 #14
0
// -----------------------------------------------------------------------------
// CTCPPortListener::ConstructL
// -----------------------------------------------------------------------------
//
void CTCPPortListener::ConstructL()
    {
    //Message slots needed is two per socket (read and write) + 1 for
    //synchronous requests.
    User::LeaveIfError(
        iSocketServer.Connect( 2 * KMaxConnectionsInQueue + 1 ) );

    User::LeaveIfError( iListeningSocket.Open(
        iSocketServer, KAfInet, KSockStream, KProtocolInetTcp ) );

    iAcceptedSocket = new (ELeave) RSocket;
    User::LeaveIfError( iAcceptedSocket->Open( iSocketServer ) );

    TSockAddr addr;
    addr.SetPort( iPort );
    User::LeaveIfError( iListeningSocket.Bind( addr ) );

    CActiveScheduler::Add( this );
    }
void ut_cnatfwsockethandler::ut_cnatfwsockethandler_SetAddrL2L(  )
{
    TSockAddr addr;
    RSocket socket;

    User::LeaveIfError( socket.Open( iSocketServer, KAfInet, KSockDatagram, KProtocolInetUdp ) );
    socket.SetLocalPort( KTestPortUdp );

    // RSocket is stubbed and currently the used ports are not stored
    // so we can make the next localportcall fail with this
    TBool shouldItFail = ETrue;
    socket.NextSetLocalPortShouldFail(ETrue, shouldItFail); // fails

    iHandler->SetMediaObserverL( this );
    iHandler->SetLocalAddress( iSocketServer, iAddr );
    // Will try to use same port as KTestPortUdp, but
    // since it's reserved, should switch to KTestPort2
    NATFW_EUNIT_ASSERT_NO_LEAVE( iHandler->SetAddrL( iAddr ) );

    iHandler->LocalAddress( addr );
    EUNIT_ASSERT_EQUALS( KTestPort2, addr.Port() );
}
예제 #16
0
void CAsyncConnect::startConnect(TSockAddr addr)
{
	debug_out(">>-->>>>> CAsyncConnect::startConnect 00 \n");
	if (inProgress)
	{
		DBG_C("EE: cntr busy");
		debug_out(">>-->>>>> CAsyncConnect::startConnect 01 \n");
		return;
	}

	this->addr = addr;

	connected = false;

	_LIT(KL2Cap, "L2CAP");
	if (error0)
	{
		DBG_C("EE:CAsyncCC error0");
		debug_out(">>-->>>>> CAsyncConnect::startConnect 02 \n");
		return;
	}

	SAFE_CLOSEDEL(sock);
	sock =  new RSocket();

	if (sock->Open(ss, KL2Cap) != KErrNone)
	{
		error0 = true;
		DBG_C("EE: CAsyncCC");
		SAFE_DEL(sock);
		debug_out(">>-->>>>> CAsyncConnect::startConnect 03 \n");
		return;
	}
	addr.SetPort(7);

	CAsyncAccept::disableSecurity((TBTSockAddr*)&addr);

//	char tmp[128];
//	resolve(addr, tmp);
//	//DBG_C("II: !con to [%s]", tmp);

	inProgress = true;
	state = S_CONNECTING;
	sock->Connect(addr, iStatus);
	//DBG_C("II: wait con ...");
	debug_out("sock->Connect: %d", iStatus);
	SetActive();
	//debug_out(">>-->>>>> CAsyncConnect::startConnect 04 \n");
}
예제 #17
0
//
// Copy constructor - takes a previously filled TSockAddr and 
// parses it for result fields.  Useful for client code only.
//
EXPORT_C TIrdaSockAddr::TIrdaSockAddr(const TSockAddr &aAddr)
/** Copy constructor. Assumes that the source address is an IrDA socket address.

@param aAddr A socket address assumed to be valid IrDA socket address. */
	{
	SetFamily(KIrdaAddrFamily);
	SetPort(aAddr.Port());
	SetRemoteDevAddr(TIrdaSockAddr::Cast(aAddr).GetRemoteDevAddr());
	SetHostDevAddr(TIrdaSockAddr::Cast(aAddr).GetHostDevAddr());
	SetSniffStatus(TIrdaSockAddr::Cast(aAddr).GetSniffStatus());
	SetSolicitedStatus(TIrdaSockAddr::Cast(aAddr).GetSolicitedStatus());
	SetIrlapVersion(TIrdaSockAddr::Cast(aAddr).GetIrlapVersion());
	SetCharacterSet(TIrdaSockAddr::Cast(aAddr).GetCharacterSet());
	SetFirstServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetFirstServiceHintByte());
	SetSecondServiceHintByte(TIrdaSockAddr::Cast(aAddr).GetSecondServiceHintByte());
    SetServiceHintByteCount(TIrdaSockAddr::Cast(aAddr).GetServiceHintByteCount());
	SetHomePort(TIrdaSockAddr::Cast(aAddr).GetHomePort());
	SetRemotePort(TIrdaSockAddr::Cast(aAddr).GetRemotePort());
	
	SetUserLen(sizeof(SIrdaAddr));
	}
enum TVerdict CTest02IPCSimpleDataTransfer::InternalDoTestStepL(void)
	{
	
	//-------------------substep 00-----------------------------	
	_LIT(aLog00,"00 Open socket server:");Logger().Write(aLog00);
	
	TInt err;
	RSocketServ ss;
	CleanupClosePushL(ss);
	if ( (err = OptimalConnect(ss)) != KErrNone )
		{
		Logger().WriteFormat(_L("Connecting to socket server failed with %d"), err);
		User::Leave(EFail);
		}
	
	//-------------------substep 01-----------------------------	
	_LIT(aLog01,"01 Create a single client/server connection:");
	Logger().Write(aLog01);

	RSocket aClientSock, aNewConn, aServerSock;
	CleanupClosePushL(aNewConn);
	CleanupClosePushL(aClientSock);
	CleanupClosePushL(aServerSock);
	
	TRequestStatus aAcceptStat, aConnectStat;
	TSockAddr aAddr;
	
	if ( (err=aServerSock.Open(ss, iProt)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open server socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	if ( (err=aServerSock.SetLocalPort(1)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not set port. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	if ( (err=aServerSock.Listen(1)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not set up socket to listen. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	if ( (err=aNewConn.Open(ss)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open blank socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	aServerSock.Accept(aNewConn, aAcceptStat);
	
	if ( (err=aClientSock.Open(ss, iProt)) != KErrNone)
		{
		_LIT(aLog,"Error:Could not open client socket. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	aAddr.SetPort(1);
	aClientSock.Connect(aAddr, aConnectStat);
	
	User::WaitForRequest(aConnectStat);
	User::WaitForRequest(aAcceptStat);
	TVerdict verdict = EPass;

	err = aConnectStat.Int();
    if (aConnectStat != KErrNone)
		{
		_LIT(aLog,"Error:Client socket not connected. err = %d");
		Logger().WriteFormat(aLog, err);
		verdict = EFail;
		}
    
    err = aAcceptStat.Int();
    if (aAcceptStat != KErrNone)
		{
		_LIT(aLog,"Error:Connection not accepted on server side. err = %d");
		Logger().WriteFormat(aLog, err);
		verdict = EFail;
		}
    
    if (verdict == EFail)
    	User::Leave(EFail);
	
    CleanupStack::PopAndDestroy(&aServerSock);
	
	//-------------------substep 02-----------------------------	
	_LIT(aLog02,"02 Send 0x100 bytes to the client. Check the content on arrival:");
	Logger().Write(aLog02);
	
	TBuf8<0x100>* aOut, *aIn;
	CleanupStack::PushL( aOut = new (ELeave) TBuf8<0x100>);
	CleanupStack::PushL( aIn  = new (ELeave) TBuf8<0x100>);
	aOut->SetMax();
	aOut->Fill('a');
	aIn->SetMax();
	aIn->Fill('b');
	
	TRequestStatus aWriteStat, aReadStat;
	aClientSock.Read(*aIn, aReadStat);
	aNewConn.Write(*aOut, aWriteStat);
	
	User::WaitForRequest(aWriteStat);
	err = aWriteStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to write. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}

    User::WaitForRequest(aReadStat);
    err = aReadStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to read. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
    
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 03-----------------------------	
	_LIT(aLog03_1,"03 Send 0x100 bytes to the client partially (a byte after byte). Then ...");
	Logger().Write(aLog03_1);
	_LIT(aLog03_2,"   ...receive them on client side and check the content.");
	Logger().Write(aLog03_2);

	TInt i;
	aIn->Fill('b');
	aClientSock.Read(*aIn, aReadStat);
	
	aOut->SetLength(1);
	for (i=0;i<0x100;i++)
		{
		aNewConn.Write(*aOut, aWriteStat);
		User::WaitForRequest(aWriteStat);
		err = aWriteStat.Int();
		if (err != KErrNone)
			{
			_LIT(aLog,"Error:Failed to write. err = %d");
			Logger().WriteFormat(aLog, err);
			User::Leave(EFail);
			}
		}
	
	User::WaitForRequest(aReadStat);
	err = aReadStat.Int();
    if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to read. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	aOut->SetMax();
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 04-----------------------------	
	_LIT(aLog04_1,"04 Send 0x100 bytes to the server. Then...");
	Logger().Write(aLog04_1);
	_LIT(aLog04_2,"   ...receive them partially(byte after byte) on the server side and check the content.");
	Logger().Write(aLog04_2);
	
	aIn->Fill('b');
	aClientSock.Write(*aOut, aWriteStat);
	
	User::WaitForRequest(aWriteStat);
	err = aWriteStat.Int();
	if (err != KErrNone)
		{
		_LIT(aLog,"Error:Failed to write. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	TBuf8<0x01> aInSmall;
	for (i=0;i<0x100;i++)
		{
		aNewConn.Read(aInSmall, aReadStat);
		User::WaitForRequest(aReadStat);
		err = aReadStat.Int();
		if (err != KErrNone)
			{
			_LIT(aLog,"Error:Failed to read. err = %d");
			Logger().WriteFormat(aLog, err);
			User::Leave(EFail);
			}
		(*aIn)[i] = aInSmall[0];
		}
	
	if (aIn->Compare(*aOut))
		{
		_LIT(aLog,"Error:Data received on clent side corrupted. err = %d");
		Logger().WriteFormat(aLog, err);
		User::Leave(EFail);
		}
	
	//-------------------substep 05-----------------------------	
	_LIT(aLog05,"05 Cleanup stack. Close all sockets.  Close socket server");
	Logger().Write(aLog05);
    CleanupStack::PopAndDestroy(5, &ss);
	return EPass;
	}
예제 #19
0
// -----------------------------------------------------------------------------
// TSockAddr::CmpPort
// -----------------------------------------------------------------------------
//
TBool TSockAddr::CmpPort(const TSockAddr& anAddr) const
    {
	return (BasePtr()->iFamily==anAddr.BasePtr()->iFamily) 
		&& (BasePtr()->iPort==anAddr.BasePtr()->iPort);
    }
예제 #20
0
EXPORT_C TEui64Addr::TEui64Addr(const TSockAddr& aAddr) : TSockAddr()
{
	__ASSERT_ALWAYS(aAddr.Family() == KAfEui64 || aAddr.Family() == 0, EuiPanic(EEuiPanicFamilyMismatch));
	Init();
	SetAddress(TEui64Addr::Cast(aAddr).Address());
}