本文整理汇总了C++中TInetAddr类的典型用法代码示例。如果您正苦于以下问题:C++ TInetAddr类的具体用法?C++ TInetAddr怎么用?C++ TInetAddr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TInetAddr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OstTraceDef0
/**
* Called when the context has been activated to set our IP address and get
* any other required settings from CommDB.
*
* @param aConfig The new context config
*/
void CIPv4Binder::UpdateContextConfigL(const TPacketDataConfigBase& aConfig)
{
OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV4BINDER_UPDATECONTEXTCONFIGL_1, "CIPv4Binder::UpdateContextConfig");
// Get our IP address from the GPRS context config.
TInetAddr address;
TBuf<RPacketContext::KMaxPDPAddressLength> tempAddr;
const RPacketContext::TProtocolConfigOptionV2* pco;
TInt rel = const_cast<TPacketDataConfigBase&>(aConfig).ExtensionId();
if (rel == TPacketDataConfigBase::KConfigGPRS)
{
tempAddr.Copy(static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iPdpAddress);
pco = &static_cast<const RPacketContext::TContextConfigGPRS&>(aConfig).iProtocolConfigOption;
}
else
{
ASSERT(rel == TPacketDataConfigBase::KConfigRel99Rel4 || rel == TPacketDataConfigBase::KConfigRel5);
tempAddr.Copy(static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iPdpAddress);
pco = &static_cast<const RPacketContext::TContextConfigR99_R4&>(aConfig).iProtocolConfigOption;
}
TInt ret = address.Input(tempAddr);
// We've got our IP address! Let's save it.
if (ret == KErrNone)
{
iSettings.iLocalAddr = address.Address();
OstTraceDefExt4(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV4BINDER_UPDATECONTEXTCONFIGL_2, "Got local IP address from context = %u.%u.%u.%u",iSettings.iLocalAddr >> 24, (iSettings.iLocalAddr >> 16) & 0xFF, (iSettings.iLocalAddr >> 8) & 0xFF, iSettings.iLocalAddr & 0xFF);
iSettings.iDefGateway = address.Address();
OstTraceDef0(OST_TRACE_CATEGORY_DEBUG, TRACE_INTERNALS, CIPV4BINDER_UPDATECONTEXTCONFIGL_3, "Set Default Gateway to local IP address");
}
示例2: args
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;
}
示例3: SetLocalIpAddrL
/**
* Function that takes an IP address from user input, accesses the
* Bluetooth PAN Profile table in the CommDb and updates the IpAddr
* field with the supplied address.
*/
void CPanConnections::SetLocalIpAddrL(TUint32 addr)
{
iLocalIpAddr = addr;
iSrcAddr.SetAddress(iLocalIpAddr);
CCommsDatabase* db = CCommsDatabase::NewL();
CleanupStack::PushL(db);
// Get the LAN service table
CCommsDbTableView* tableView = db->OpenTableLC(TPtrC(LAN_SERVICE));
TBuf<KMaxBufferSize> tableName;
TInt err = tableView->GotoFirstRecord();
if(err == KErrNone)
{
// Get the name of the table
tableView->ReadTextL(TPtrC(COMMDB_NAME), tableName);
if(tableName == TPtrC(_S("BluetoothPANProfile")))
{
TInetAddr tempAddr;
TBuf<KMaxBufferSize> dispBuf;
tempAddr.SetAddress(iLocalIpAddr);
tempAddr.Output(dispBuf);
User::LeaveIfError(tableView->UpdateRecord());
tableView->WriteTextL(_L("IpAddr"), dispBuf);
User::LeaveIfError(tableView->PutRecordChanges());
User::LeaveIfError(db->CommitTransaction());
}
}
else
{
User::Leave(KErrNotFound);
}
CleanupStack::PopAndDestroy(2);//db & tableView
}
示例4: parser
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;
}
示例5: OpenHostResolver
//------------------------------------------------------------------------------------------------------
// testing
// EHRGetByAddress
// Requires alive connection. Uses Ethernet one
//------------------------------------------------------------------------------------------------------
TInt CPARAM_MESS_NAMEStep::do_execute(Int2Type<EHRGetByAddress>)
{
TInt result;
//-- 1. Create a connection.
result = OpenHostResolver();
if(result != KErrNone)
{
//-- close connection
SendReceive(EHRClose,TIpcArgs(0,0,0,iSSRes));
return result;
}
_LIT(KName, "127.0.0.1");
TBufC<20> aName(KName);
TInetAddr addr;
addr.Input(aName);
TNameEntry aResult;
result =SendReceive(EHRGetByAddress,TIpcArgs(&addr,&aResult,0, iSSRes));
if(result != KErrNone)
return result;
//-- stop connection
result = SendReceive(EHRClose,TIpcArgs(0,0,0,iSSRes));
return result;
}
示例6: ConstructL
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 "));
}
}
示例7: ConnectionAcceptedL
// -----------------------------------------------------------------------------
// CUpnpHttpServer::ConnectionAcceptedL
//
// -----------------------------------------------------------------------------
//
CUpnpTcpSession* CUpnpHttpServer::ConnectionAcceptedL( RSocket aSocket )
{
LOG_FUNC_NAME;
#ifdef _DEBUG
TInetAddr tempAddr;
aSocket.RemoteName( tempAddr );
tempAddr.ConvertToV4();
const TInt KMaxAdressLength = 20;
TBuf<KMaxAdressLength> addrBuf;
tempAddr.Output( addrBuf );
HBufC8* addrBuf8 = UpnpString::FromUnicodeL( addrBuf );
CleanupStack::PushL( addrBuf8 );
LOGS( "CUpnpHttpServer::ConnectionAcceptedL - Remote socket connected" );
LOGT( addrBuf8->Des() );
LOGS1("CUpnpHttpServer::ConnectionAcceptedL - Creating a new Http session. Session count: %i", iSessionList.Count());
CleanupStack::PopAndDestroy(addrBuf8);
#endif //_DEBUG
CUpnpHttpSession* sess = CUpnpHttpSession::NewL( aSocket, this,
CUpnpHttpMessage::NewSessionIdL(), EPriorityNormal );
return sess;
}
示例8:
TSAHostCacheEntry::TSAHostCacheEntry(const TInetAddr& aAddress, TInt aQuality)
{
iPort = aAddress.Port();
iAddress = aAddress.Address();
iQuality = aQuality;
}
示例9: TESTL
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;
}
示例10: SetDefaultNetTypeAndAddrType
// ---------------------------------------------------------------------------
// SdpUtil::SetDefaultNetTypeAndAddrType
// Sets network type and address type to their "default" values
// ---------------------------------------------------------------------------
//
void SdpUtil::SetDefaultNetTypeAndAddrType(
RStringPool aPool,
const TInetAddr& aAddress,
RStringF& aNetType,
RStringF& aAddressType )
{
// Sets network type to IN
aNetType.Close();
aNetType = aPool.StringF( SdpCodecStringConstants::ENetType,
SdpCodecStringConstants::Table ).Copy();
// Address type
aAddressType.Close();
TBuf16 <KMaxAddressLength> output;
aAddress.Output(output);
//addresstype for IPv4
if((aAddress.Address() && !aAddress.IsV4Mapped()) ||
(!aAddress.Address() && aAddress.IsWildAddr() &&
output.Match(KWildAddr) == 0))
{
aAddressType = aPool.StringF( SdpCodecStringConstants::EAddressTypeIP4,
SdpCodecStringConstants::Table ).Copy();
}
else
{
//addresstype for IPv4-Mapped IPv6 && IPv6
aAddressType = aPool.StringF( SdpCodecStringConstants::EAddressType,
SdpCodecStringConstants::Table ).Copy();
}
}
示例11: ChangedAddress
// Help function for address loading, returns
// = 0, if address did not change
// = 1, if address has changed
//
static TInt ChangedAddress(TInetAddr &aAddr, const TInetAddr &aNewAddr)
{
// "Normalize" new address
// - convert IPv4 addresess into IPv4 mapped
// - anything other then KAfInet6 will be set as None
TInetAddr tmp(aNewAddr);
if (tmp.Family() == KAfInet)
{
tmp.ConvertToV4Mapped();
tmp.SetScope(0); // [is already part of "convert" in newer insocks]
}
else if (tmp.Family() != KAfInet6)
tmp.SetAddress(KInet6AddrNone);
if (tmp.CmpAddr(aAddr) && // address and port same?
tmp.FlowLabel() == aAddr.FlowLabel())
{
// If the scope id in new addres is zero, then the
// scope id is not part the address compare.
// (this will optimize unconnected sockets where application
// gives destination without scope -- eliminates unnecessary
// flow connect operations.
if (tmp.Scope() == aAddr.Scope() || tmp.Scope() == 0)
return 0; // No Change to the previous value
}
// Address is being changed
aAddr = tmp;
return 1;
}
示例12: TESTL
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;
}
示例13: addressPtr
TInt RWin32Socket::SendTo(const TDesC8& aSendBuffer, const TInetAddr& aAddress, TRequestStatus& aStatus)
{
WSP_LOG(WspLog::Printf(_L("RWin32Socket::SendTo: this: 0x%x, bytes to send: %d"), this, aSendBuffer.Length()));
TPtr8 addressPtr(const_cast<TUint8*>(aAddress.Ptr()), aAddress.Length(), aAddress.MaxLength()); // Slight hack - need to send two read buffers, but the framework doesn't support this, so send the address as a write buffer.
iWin32Message.Set(CWin32Socket::ESendTo, aSendBuffer, addressPtr, aStatus);
return MakeRequest(iWin32Message);
}
示例14: __ASSERT_DEBUG
void CWin32Socket::SendTo(TWin32Message& aMessage)
{
__ASSERT_DEBUG((iSendMessage == NULL) && (iBytesSent == 0), Panic(EWinSockPrtCWin32SocketMultipleSendToRequests));
iSendMessage = &aMessage;
WSP_LOG(WspLog::Printf(_L("CWin32Socket::SendTo: this: 0x%x, bytes to send: %d"), this, iSendMessage->ReadBuffer().Length()));
TPtrC8 bufPtr(iSendMessage->ReadBuffer());
iSendBuffer.buf = reinterpret_cast<char*>(const_cast<TUint8*>(bufPtr.Ptr()));
iSendBuffer.len = bufPtr.Length();
iSendOverlapped.hEvent = (void*) this;
TInetAddr address;
address.Copy(iSendMessage->WriteBuffer());
SOCKADDR_IN winSockAddress;
ConvertAddress(address, winSockAddress);
DWORD numberOfBytesSent;
TInt ret = WSASendTo(iSocket, &iSendBuffer, 1, &numberOfBytesSent, 0, (LPSOCKADDR)&winSockAddress, sizeof(struct sockaddr_in), &iSendOverlapped, &SendToCompletion);
if (ret == SOCKET_ERROR)
{
TInt err = WSAGetLastError();
if (err != WSA_IO_PENDING)
{
WSP_LOG(WspLog::Printf(_L("\tsocket error: %d"), err));
Complete(iSendMessage, MapWinSockError(err));
}
}
}
示例15: EUNIT_ASSERT
void UT_CTBCPFloorControlImpl::UT_CTBCPFloorControlImpl_ConnectionStarted2LL( )
{
iPlugIn->SetIapId(KIAPID);
TBuf<KBufLength> addressbuffer;
TInetAddr addr;
addr.Input(KAddr3);
addr.Output(addressbuffer);
iPlugIn->SetAddressL(addressbuffer, KPort1);
iPlugIn->SetLocalPort(KPort2);
iPlugIn->ConnectL( ETrue );
iPlugIn->ConnectionStarted(0);
EUNIT_ASSERT(iError==0);
TBuf<KBufLength> addressbuffer2;
TInetAddr addr2;
addr2.Input(KAddr2);
addr2.Output(addressbuffer2);
iPlugIn->SetAddressL(addressbuffer2, KPort1);
iPlugIn->iConnection->Cancel();
iPlugIn->iConnection->iStatus = KErrNone;
iPlugIn->iConnection->RunL();
FC_EUNIT_ASSERT_EQUALS( iError, KErrNone );
}