本文整理汇总了C++中UdpSocket::HandleUdpReceive方法的典型用法代码示例。如果您正苦于以下问题:C++ UdpSocket::HandleUdpReceive方法的具体用法?C++ UdpSocket::HandleUdpReceive怎么用?C++ UdpSocket::HandleUdpReceive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UdpSocket
的用法示例。
在下文中一共展示了UdpSocket::HandleUdpReceive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleMessage
otError Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo)
{
otError error = OT_ERROR_NONE;
UdpHeader udpHeader;
uint16_t payloadLength;
uint16_t checksum;
payloadLength = aMessage.GetLength() - aMessage.GetOffset();
// check length
VerifyOrExit(payloadLength >= sizeof(UdpHeader), error = OT_ERROR_PARSE);
// verify checksum
checksum = Ip6::ComputePseudoheaderChecksum(aMessageInfo.GetPeerAddr(), aMessageInfo.GetSockAddr(),
payloadLength, kProtoUdp);
checksum = aMessage.UpdateChecksum(checksum, aMessage.GetOffset(), payloadLength);
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
VerifyOrExit(checksum == 0xffff, error = OT_ERROR_DROP);
#endif
VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(udpHeader), &udpHeader) == sizeof(udpHeader),
error = OT_ERROR_PARSE);
aMessage.MoveOffset(sizeof(udpHeader));
aMessageInfo.mPeerPort = udpHeader.GetSourcePort();
aMessageInfo.mSockPort = udpHeader.GetDestinationPort();
// find socket
for (UdpSocket *socket = mSockets; socket; socket = socket->GetNext())
{
if (socket->GetSockName().mPort != udpHeader.GetDestinationPort())
{
continue;
}
if (socket->GetSockName().mScopeId != 0 &&
socket->GetSockName().mScopeId != aMessageInfo.mInterfaceId)
{
continue;
}
if (!aMessageInfo.GetSockAddr().IsMulticast() &&
!socket->GetSockName().GetAddress().IsUnspecified() &&
socket->GetSockName().GetAddress() != aMessageInfo.GetSockAddr())
{
continue;
}
// verify source if connected socket
if (socket->GetPeerName().mPort != 0)
{
if (socket->GetPeerName().mPort != udpHeader.GetSourcePort())
{
continue;
}
if (!socket->GetPeerName().GetAddress().IsUnspecified() &&
socket->GetPeerName().GetAddress() != aMessageInfo.GetPeerAddr())
{
continue;
}
}
socket->HandleUdpReceive(aMessage, aMessageInfo);
}
exit:
return error;
}