本文整理汇总了C++中TInetAddr::SetAddress方法的典型用法代码示例。如果您正苦于以下问题:C++ TInetAddr::SetAddress方法的具体用法?C++ TInetAddr::SetAddress怎么用?C++ TInetAddr::SetAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TInetAddr
的用法示例。
在下文中一共展示了TInetAddr::SetAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
enum TVerdict CEsockTest19_1::easyTestStepL()
{
TInetAddr addr;
TBuf<39> buf;
// setting the IP address
const TIp6Addr KInet6Addr19_1 = {{{0xff,0xfe,0,0,0,0,0,0,0,0,0,0,0,0,0x29,0xfe}}};
const TIp6Addr KInet6Addr19_2 = {{{0xff,0xf1,0,1,0,1,0,1,0,1,0,1,0,1,0x29,0xff}}};
// setting the IP address
// set the address
addr.SetAddress(KInet6Addr19_1);
// check it has been set correctly
addr.OutputWithScope(buf);
TESTL(buf==_L("fffe::29fe"));
// check port number initialised to 0
TESTL(addr.Port()==0);
// change the address
addr.SetAddress(KInet6Addr19_2);
// check it has been set correctly
addr.OutputWithScope(buf);
TESTL(buf==_L("fff1:1:1:1:1:1:1:29ff"));
// check port number is still set to 0
TESTL(addr.Port()==0);
return EPass;
}
示例2: 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
}
示例3: ILibSocketWrapper_joinmulticastgroup
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);
}
}
示例4: FetchCandidateL
// ---------------------------------------------------------------------------
// CNATFWStunConnectionHandler::FetchCandidateL
// ---------------------------------------------------------------------------
//
void CNATFWStunConnectionHandler::FetchCandidateL( TUint aStreamId,
TUint /*aRtoValue*/, TUint /*aAddrFamily*/,
const TInetAddr& aBaseAddr )
{
__STUNPLUGIN( "CNATFWStunConnectionHandler::FetchCandidateL start" )
// Store data in array
TStreamData streamData;
streamData.iStreamId = aStreamId;
CNATFWCandidate* newCandidate = CNATFWCandidate::NewLC();
TInetAddr publicAddr;
if ( KAfInet6 == aBaseAddr.Family() )
{
const TIp6Addr KIp6Addr = {{{1,2,3,4,5,6,7,8,9,0,0,0,0,0,0,1}}};
publicAddr.SetAddress( KIp6Addr );
}
else
{
publicAddr.SetAddress( INET_ADDR( 1,2,3,4 ) );
}
// Set candidate parameters
newCandidate->SetStreamId( aStreamId );
newCandidate->SetType( CNATFWCandidate::EServerReflexive );
newCandidate->SetTransportAddrL( publicAddr );
newCandidate->SetTransportProtocol( KProtocolInetUdp );
TConnectionData connData;
connData.iLocalCandidate = newCandidate;
streamData.iConnArray.AppendL( connData );
iStreamArray.AppendL( streamData );
TCallBackCmd cmd
= TCallBackCmd( aStreamId, EFetchCandidate, 0, newCandidate );
iCallBackCmds.AppendL( cmd );
CleanupStack::Pop( newCandidate );
if ( !IsActive() )
{
After( KWaitTime );
}
// wait MNcmConnectionObserver::ConnectionNotify
__STUNPLUGIN( "CNATFWStunConnectionHandler::FetchCandidateL end" )
}
示例5: net_if_getaddr4
/**
* 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;
}
示例6: PrintConns
/**
* Function to print the current connections we have.
*/
void CPanConnections::PrintConns()
{
iConsole.Printf(_L("\nRemotenames : %d\n"), iRemoteNames.Count());
PrintTcpSocketConnections();
iConsole.Printf(_L("--------------------------------------------------\n"));
iConsole.Printf(_L("Listening Mode: "));
iListening ? iConsole.Printf(_L("Enabled ")) : iConsole.Printf(_L("Disabled "));
if(iIapStarted)
{
iConsole.Printf(_L(" IAP Started"));
TInt err = UpdateCurrentConnections();
if(err != KErrNone)
{
iConsole.Printf(_L("FAILED TO ENUMERATE CONNECTIONS. Err %d\n"), err);
}
else
{
iConsole.Printf(_L("\n------------------ CONNECTIONS -------------------\n"));
iConsole.Printf(_L("Index Remote Addr\n"));
for(TInt i=0;i<iActiveConnections.Count();i++)
{
TBuf<KMaxBufferSize> dispBuf;
iActiveConnections[i].GetReadable(dispBuf);
if(iActivePanConn == i)
{
iConsole.Printf(_L("-> "));
}
else
{
iConsole.Printf(_L(" "));
}
iConsole.Printf(_L("%d 0x%S\n"), i, &dispBuf);
}
}
}
if(iLocalIpAddr == 0)
{
iConsole.Printf(_L("\nNo local IP address set\n"));
}
else
{
TInetAddr tempAddr;
TBuf<KMaxBufferSize> dispBuf;
tempAddr.SetAddress(iLocalIpAddr);
tempAddr.Output(dispBuf);
iConsole.Printf(_L("\nLocal IP address: %S\n"), &dispBuf);
}
}
示例7: Connect
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();
}
示例8: SetAddress
void CFTPResolver::SetAddress(TInetAddr& aAddress)
{
// Get the 1st entry resolved
iNameRecord = iNameEntry();
// Save the address (take care not to overwrite the port, might have been already set)
if (TInetAddr::Cast(iNameRecord.iAddr).Family() == KAfInet)
aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Address());
else
aAddress.SetAddress(TInetAddr::Cast(iNameRecord.iAddr).Ip6Address());
#if defined(__FTPPROTDEBUG__)
TBuf<512> debugBuffer; // A Buffer to output the resolved IP
aAddress.Output(debugBuffer);
debugBuffer.Append(_L(","));
debugBuffer.AppendNum(aAddress.Port(), EDecimal);
debugBuffer.Append(_L("\n"));
#endif
FTPPROTDEBUG(_DBGResolver,_L("Resolved address is:"));
FTPPROTDEBUG(_DBGResolver,debugBuffer);
}
示例9: GetDomainNameServer
TBool CDHCPOptionDNSServers::GetDomainNameServer( TInt aIndex, TInetAddr& addr )
{
TInt pos = aIndex * KIp6AddressLength;
TBool ret = GetLength() >= pos + KIp6AddressLength;
if ( ret )
{
// Must ensure IP6 address is word aligned! So declare it locally
TIp6Addr ip6addr;
Mem::Copy(&ip6addr,GetBodyPtr() + pos,KIp6AddressLength);
addr.SetAddress(ip6addr);
}
return ret;
}
示例10: Resolve
void CDnsResolver::Resolve(const TDesC& aHostName)
{
if (IsActive())
{
User::Invariant();
return;
}
_LIT(KLocalHostName, "localhost");
if (aHostName == KLocalHostName)
{
const TUint32 KLocalIpAddr = INET_ADDR(127,0,0,1);
TInetAddr localIpAddr;
localIpAddr.SetAddress(KLocalIpAddr);
iNameEntry().iAddr = localIpAddr; // copy
iStatus = KRequestPending;
SetActive();
TRequestStatus* status = &iStatus;
User::RequestComplete(status, KErrNone);
return;
}
// ensure that we have a resolver session we can use
if (!IS_SUBSESSION_OPEN(iHostResolver))
{
TInt error;
if (iConnection)
{
error = iHostResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp,
*iConnection);
}
else
{
error = iHostResolver.Open(iSocketServ, KAfInet, KProtocolInetUdp);
}
if (error != KErrNone && error != KErrAlreadyExists)
{
iStatus = KRequestPending;
SetActive();
TRequestStatus* status = &iStatus;
User::RequestComplete(status, error);
return;
}
}
SET_SESSION_OPEN(iHostResolver);
iHostResolver.GetByName(aHostName, iNameEntry, iStatus);
SetActive();
}
示例11:
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;
}
示例12: FetchIpAddressL
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
}
示例13: AddSrcAddr
void CQoSMsg::AddSrcAddr(const TInetAddr &aAddr)
/**
Adds Source Address Information to the QoS PRT Message
@param aAddr Source Address
*/
{
TInetAddr srcInetAddr(aAddr);
srcInetAddr.SetFamily(KAFUnspec);
srcInetAddr.SetAddress(KInet6AddrNone);
TInetAddr mask;
mask.SetAddress(KInet6AddrMask);
iMsg->AddSrcAddress(srcInetAddr, mask, (TUint16)srcInetAddr.Port());
}
示例14: AddDstAddr
void CQoSMsg::AddDstAddr(const TInetAddr &aAddr)
/**
Adds Destination Address Information to the QoS PRT Message
@param aAddr Destination Address
*/
{
TInetAddr dstInetAddr(aAddr);
if (dstInetAddr.Family() == KAfInet)
{
dstInetAddr.ConvertToV4Mapped();
}
TInetAddr mask;
mask.SetAddress(KInet6AddrMask);
iMsg->AddDstAddress(dstInetAddr, mask, (TUint16)dstInetAddr.Port());
}
示例15: GetSipServerAddr
TBool CDHCPOptionSipServerAddrs::GetSipServerAddr(TInt aIndex, TInetAddr& addr)
{
__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CDHCPOptionSipServerAddrs::GetSipServerAddr index = %d"),aIndex));
TInt pos = aIndex * KIp6AddressLength;
TInt len = GetLength();
TBool ret = len >= pos + KIp6AddressLength;
__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("pos = %d, len = %d, ret = %d"), pos, len, ret));
if (ret)
{
// Must ensure IP6 address is word aligned! So declare it locally
TIp6Addr ip6addr;
Mem::Copy(&ip6addr,GetBodyPtr() + pos,KIp6AddressLength);
addr.SetAddress(ip6addr);
}
return ret;
}