本文整理汇总了C++中ip6::MessageInfo::GetSockAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageInfo::GetSockAddr方法的具体用法?C++ MessageInfo::GetSockAddr怎么用?C++ MessageInfo::GetSockAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ip6::MessageInfo
的用法示例。
在下文中一共展示了MessageInfo::GetSockAddr方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleUdpReceive
void Dtls::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
switch (mState)
{
case MeshCoP::Dtls::kStateClosed:
ExitNow();
case MeshCoP::Dtls::kStateOpen:
{
Ip6::SockAddr sockAddr;
sockAddr.mAddress = aMessageInfo.GetPeerAddr();
sockAddr.mPort = aMessageInfo.GetPeerPort();
mSocket.Connect(sockAddr);
mPeerAddress.SetPeerAddr(aMessageInfo.GetPeerAddr());
mPeerAddress.SetPeerPort(aMessageInfo.GetPeerPort());
mPeerAddress.SetInterfaceId(aMessageInfo.GetInterfaceId());
if (Get<ThreadNetif>().IsUnicastAddress(aMessageInfo.GetSockAddr()))
{
mPeerAddress.SetSockAddr(aMessageInfo.GetSockAddr());
}
mPeerAddress.SetSockPort(aMessageInfo.GetSockPort());
SuccessOrExit(Setup(false));
break;
}
default:
// Once DTLS session is started, communicate only with a peer.
VerifyOrExit((mPeerAddress.GetPeerAddr() == aMessageInfo.GetPeerAddr()) &&
(mPeerAddress.GetPeerPort() == aMessageInfo.GetPeerPort()));
break;
}
#if OPENTHREAD_ENABLE_BORDER_AGENT || OPENTHREAD_ENABLE_COMMISSIONER
if (mState == MeshCoP::Dtls::kStateConnecting)
{
SetClientId(mPeerAddress.GetPeerAddr().mFields.m8, sizeof(mPeerAddress.GetPeerAddr().mFields));
}
#endif
Receive(aMessage, aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset());
exit:
return;
}
示例2: HandleRequest
void AnnounceBeginServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
MeshCoP::ChannelMask0Tlv channelMask;
MeshCoP::CountTlv count;
MeshCoP::PeriodTlv period;
Ip6::MessageInfo responseInfo(aMessageInfo);
VerifyOrExit(aHeader.GetCode() == OT_COAP_CODE_POST);
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask));
VerifyOrExit(channelMask.IsValid());
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kCount, sizeof(count), count));
VerifyOrExit(count.IsValid());
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kPeriod, sizeof(period), period));
VerifyOrExit(period.IsValid());
SendAnnounce(channelMask.GetMask(), count.GetCount(), period.GetPeriod());
if (aHeader.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
SuccessOrExit(GetNetif().GetCoap().SendEmptyAck(aHeader, responseInfo));
otLogInfoMeshCoP(GetInstance(), "sent announce begin response");
}
exit:
return;
}
示例3: otPlatRandomGet
RequestMetadata::RequestMetadata(bool aConfirmable, const Ip6::MessageInfo &aMessageInfo,
otCoapResponseHandler aHandler, void *aContext)
{
mSourceAddress = aMessageInfo.GetSockAddr();
mDestinationPort = aMessageInfo.GetPeerPort();
mDestinationAddress = aMessageInfo.GetPeerAddr();
mResponseHandler = aHandler;
mResponseContext = aContext;
mRetransmissionCount = 0;
mRetransmissionTimeout = Timer::SecToMsec(kAckTimeout);
mRetransmissionTimeout += otPlatRandomGet() %
(Timer::SecToMsec(kAckTimeout) * kAckRandomFactorNumerator / kAckRandomFactorDenominator -
Timer::SecToMsec(kAckTimeout) + 1);
if (aConfirmable)
{
// Set next retransmission timeout.
mNextTimerShot = Timer::GetNow() + mRetransmissionTimeout;
}
else
{
// Set overall response timeout.
mNextTimerShot = Timer::GetNow() + kMaxTransmitWait;
}
mAcknowledged = false;
mConfirmable = aConfirmable;
}
示例4: IsTmfMessage
bool ThreadNetif::IsTmfMessage(const Ip6::MessageInfo &aMessageInfo)
{
bool rval = true;
// A TMF message must comply with following rules:
// 1. The destination is a Mesh Local Address or a Link-Local Multicast Address or a Realm-Local Multicast Address,
// and the source is a Mesh Local Address. Or
// 2. Both the destination and the source are Link-Local Addresses.
VerifyOrExit(
((mMleRouter.IsMeshLocalAddress(aMessageInfo.GetSockAddr()) ||
aMessageInfo.GetSockAddr().IsLinkLocalMulticast() || aMessageInfo.GetSockAddr().IsRealmLocalMulticast()) &&
mMleRouter.IsMeshLocalAddress(aMessageInfo.GetPeerAddr())) ||
((aMessageInfo.GetSockAddr().IsLinkLocal() || aMessageInfo.GetSockAddr().IsLinkLocalMulticast()) &&
aMessageInfo.GetPeerAddr().IsLinkLocal()),
rval = false);
exit:
return rval;
}
示例5: Receive
void CoapSecure::Receive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
ThreadNetif &netif = GetNetif();
if (!netif.GetDtls().IsStarted())
{
Ip6::SockAddr sockAddr;
sockAddr.mAddress = aMessageInfo.GetPeerAddr();
sockAddr.mPort = aMessageInfo.GetPeerPort();
mSocket.Connect(sockAddr);
mPeerAddress.SetPeerAddr(aMessageInfo.GetPeerAddr());
mPeerAddress.SetPeerPort(aMessageInfo.GetPeerPort());
mPeerAddress.SetInterfaceId(aMessageInfo.GetInterfaceId());
if (netif.IsUnicastAddress(aMessageInfo.GetSockAddr()))
{
mPeerAddress.SetSockAddr(aMessageInfo.GetSockAddr());
}
mPeerAddress.SetSockPort(aMessageInfo.GetSockPort());
netif.GetDtls().Start(false, &CoapSecure::HandleDtlsConnected, &CoapSecure::HandleDtlsReceive,
CoapSecure::HandleDtlsSend, this);
}
else
{
// Once DTLS session is started, communicate only with a peer.
VerifyOrExit((mPeerAddress.GetPeerAddr() == aMessageInfo.GetPeerAddr()) &&
(mPeerAddress.GetPeerPort() == aMessageInfo.GetPeerPort()));
}
netif.GetDtls().SetClientId(mPeerAddress.GetPeerAddr().mFields.m8, sizeof(mPeerAddress.GetPeerAddr().mFields));
netif.GetDtls().Receive(aMessage, aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset());
exit:
return;
}
示例6: HandleRequest
void EnergyScanServer::HandleRequest(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
MeshCoP::CountTlv count;
MeshCoP::PeriodTlv period;
MeshCoP::ScanDurationTlv scanDuration;
MeshCoP::ChannelMask0Tlv channelMask;
Ip6::MessageInfo responseInfo(aMessageInfo);
VerifyOrExit(aHeader.GetCode() == OT_COAP_CODE_POST);
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kCount, sizeof(count), count));
VerifyOrExit(count.IsValid());
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kPeriod, sizeof(period), period));
VerifyOrExit(period.IsValid());
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kScanDuration, sizeof(scanDuration), scanDuration));
VerifyOrExit(scanDuration.IsValid());
SuccessOrExit(MeshCoP::Tlv::GetTlv(aMessage, MeshCoP::Tlv::kChannelMask, sizeof(channelMask), channelMask));
VerifyOrExit(channelMask.IsValid());
mChannelMask = channelMask.GetMask();
mChannelMaskCurrent = mChannelMask;
mCount = count.GetCount();
mPeriod = period.GetPeriod();
mScanDuration = scanDuration.GetScanDuration();
mScanResultsLength = 0;
mActive = true;
mTimer.Start(kScanDelay);
mCommissioner = aMessageInfo.GetPeerAddr();
if (aHeader.IsConfirmable() && !aMessageInfo.GetSockAddr().IsMulticast())
{
SuccessOrExit(GetNetif().GetCoap().SendEmptyAck(aHeader, responseInfo));
otLogInfoMeshCoP(GetInstance(), "sent energy scan query response");
}
exit:
return;
}