本文整理汇总了C++中HostSwap16函数的典型用法代码示例。如果您正苦于以下问题:C++ HostSwap16函数的具体用法?C++ HostSwap16怎么用?C++ HostSwap16使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HostSwap16函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
ThreadError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
ThreadError error = kThreadError_Parse;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset < end)
{
aMessage.Read(offset, sizeof(Tlv), &tlv);
// skip extended TLV
if (tlv.GetLength() == kExtendedLength)
{
uint16_t length = 0;
offset += sizeof(tlv);
aMessage.Read(offset, sizeof(length), &length);
offset += sizeof(length) + HostSwap16(length);
}
else if (tlv.GetType() == aType && (offset + sizeof(tlv) + tlv.GetLength()) <= end)
{
aOffset = offset;
ExitNow(error = kThreadError_None);
}
else
{
offset += sizeof(tlv) + tlv.GetLength();
}
}
exit:
return error;
}
示例2: GetNetif
void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
ThreadNetif & netif = GetNetif();
otError error;
Coap::Message * message = NULL;
Ip6::MessageInfo messageInfo;
JoinerUdpPortTlv udpPort;
JoinerIidTlv iid;
JoinerRouterLocatorTlv rloc;
ExtendedTlv tlv;
uint16_t borderAgentRloc;
uint16_t offset;
otLogInfoMeshCoP("JoinerRouter::HandleUdpReceive");
SuccessOrExit(error = GetBorderAgentRloc(GetNetif(), borderAgentRloc));
VerifyOrExit((message = NewMeshCoPMessage(netif.GetCoap())) != NULL, error = OT_ERROR_NO_BUFS);
message->Init(OT_COAP_TYPE_NON_CONFIRMABLE, OT_COAP_CODE_POST);
message->SetToken(Coap::Message::kDefaultTokenLength);
message->AppendUriPathOptions(OT_URI_PATH_RELAY_RX);
message->SetPayloadMarker();
udpPort.Init();
udpPort.SetUdpPort(aMessageInfo.GetPeerPort());
SuccessOrExit(error = message->Append(&udpPort, sizeof(udpPort)));
iid.Init();
iid.SetIid(aMessageInfo.GetPeerAddr().mFields.m8 + 8);
SuccessOrExit(error = message->Append(&iid, sizeof(iid)));
rloc.Init();
rloc.SetJoinerRouterLocator(netif.GetMle().GetRloc16());
SuccessOrExit(error = message->Append(&rloc, sizeof(rloc)));
tlv.SetType(Tlv::kJoinerDtlsEncapsulation);
tlv.SetLength(aMessage.GetLength() - aMessage.GetOffset());
SuccessOrExit(error = message->Append(&tlv, sizeof(tlv)));
offset = message->GetLength();
SuccessOrExit(error = message->SetLength(offset + tlv.GetLength()));
aMessage.CopyTo(aMessage.GetOffset(), offset, tlv.GetLength(), *message);
messageInfo.SetSockAddr(netif.GetMle().GetMeshLocal16());
messageInfo.SetPeerAddr(netif.GetMle().GetMeshLocal16());
messageInfo.GetPeerAddr().mFields.m16[7] = HostSwap16(borderAgentRloc);
messageInfo.SetPeerPort(kCoapUdpPort);
SuccessOrExit(error = netif.GetCoap().SendMessage(*message, messageInfo));
otLogInfoMeshCoP("Sent relay rx");
exit:
if (error != OT_ERROR_NONE && message != NULL)
{
message->Free();
}
}
示例3: HostSwap16
otError Udp::UpdateChecksum(Message &aMessage, uint16_t aChecksum)
{
aChecksum = aMessage.UpdateChecksum(aChecksum, aMessage.GetOffset(), aMessage.GetLength() - aMessage.GetOffset());
if (aChecksum != 0xffff)
{
aChecksum = ~aChecksum;
}
aChecksum = HostSwap16(aChecksum);
aMessage.Write(aMessage.GetOffset() + UdpHeader::GetChecksumOffset(), sizeof(aChecksum), &aChecksum);
return OT_ERROR_NONE;
}
示例4: AddMplOption
ThreadError AddMplOption(Message &message, Header &header, IpProto nextHeader, uint16_t payloadLength)
{
ThreadError error = kThreadError_None;
HopByHopHeader hbhHeader;
OptionMpl mplOption;
hbhHeader.SetNextHeader(nextHeader);
hbhHeader.SetLength(0);
sMpl.InitOption(mplOption, HostSwap16(header.GetSource().mFields.m16[7]));
SuccessOrExit(error = message.Prepend(&mplOption, sizeof(mplOption)));
SuccessOrExit(error = message.Prepend(&hbhHeader, sizeof(hbhHeader)));
header.SetPayloadLength(sizeof(hbhHeader) + sizeof(mplOption) + payloadLength);
header.SetNextHeader(kProtoHopOpts);
exit:
return error;
}
示例5: otMessageGetLength
void UdpExample::HandleUdpReceive(otMessage *aMessage, const otMessageInfo *aMessageInfo)
{
uint8_t buf[1500];
int length;
mInterpreter.mServer->OutputFormat("%d bytes from ", otMessageGetLength(aMessage) - otMessageGetOffset(aMessage));
mInterpreter.mServer->OutputFormat(
"%x:%x:%x:%x:%x:%x:%x:%x %d ", HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[0]),
HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[1]), HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[2]),
HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[3]), HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[4]),
HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[5]), HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[6]),
HostSwap16(aMessageInfo->mPeerAddr.mFields.m16[7]), aMessageInfo->mPeerPort);
length = otMessageRead(aMessage, otMessageGetOffset(aMessage), buf, sizeof(buf) - 1);
buf[length] = '\0';
mInterpreter.mServer->OutputFormat("%s\r\n", buf);
}
示例6: otLogInfoMeshCoP
void Leader::HandlePetition(Coap::Header &aHeader, Message &aMessage, const Ip6::MessageInfo &aMessageInfo)
{
CommissioningData data;
CommissionerIdTlv commissionerId;
StateTlv::State state = StateTlv::kReject;
otLogInfoMeshCoP(GetInstance(), "received petition");
SuccessOrExit(Tlv::GetTlv(aMessage, Tlv::kCommissionerId, sizeof(commissionerId), commissionerId));
VerifyOrExit(commissionerId.IsValid());
if (mTimer.IsRunning())
{
VerifyOrExit(!strncmp(commissionerId.GetCommissionerId(), mCommissionerId.GetCommissionerId(),
sizeof(mCommissionerId)));
ResignCommissioner();
}
data.mBorderAgentLocator.Init();
data.mBorderAgentLocator.SetBorderAgentLocator(HostSwap16(aMessageInfo.GetPeerAddr().mFields.m16[7]));
data.mCommissionerSessionId.Init();
data.mCommissionerSessionId.SetCommissionerSessionId(++mSessionId);
data.mSteeringData.Init();
data.mSteeringData.SetLength(1);
data.mSteeringData.Clear();
SuccessOrExit(GetNetif().GetNetworkDataLeader().SetCommissioningData(reinterpret_cast<uint8_t *>(&data),
data.GetLength()));
mCommissionerId = commissionerId;
state = StateTlv::kAccept;
mTimer.Start(TimerMilli::SecToMsec(kTimeoutLeaderPetition));
exit:
OT_UNUSED_VARIABLE(aMessageInfo);
SendPetitionResponse(aHeader, aMessageInfo, state);
}
示例7: SetChannelPage
void ChannelTlv::SetChannel(uint16_t aChannel)
{
uint8_t channelPage = OT_RADIO_CHANNEL_PAGE_0;
#if OPENTHREAD_CONFIG_RADIO_2P4GHZ_OQPSK_SUPPORT
if ((OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MIN <= aChannel) && (aChannel <= OT_RADIO_2P4GHZ_OQPSK_CHANNEL_MAX))
{
channelPage = OT_RADIO_CHANNEL_PAGE_0;
}
#endif
#if OPENTHREAD_CONFIG_RADIO_915MHZ_OQPSK_SUPPORT
if ((OT_RADIO_915MHZ_OQPSK_CHANNEL_MIN <= aChannel) && (aChannel <= OT_RADIO_915MHZ_OQPSK_CHANNEL_MAX))
{
channelPage = OT_RADIO_CHANNEL_PAGE_2;
}
#endif
SetChannelPage(channelPage);
mChannel = HostSwap16(aChannel);
}
示例8: GetNetif
otError Joiner::TryNextJoin()
{
ThreadNetif & netif = GetNetif();
otError error = OT_ERROR_NOT_FOUND;
JoinerRouter *joinerRouter = &mJoinerRouters[0];
for (size_t i = 1; i < OPENTHREAD_CONFIG_MAX_JOINER_ROUTER_ENTRIES; i++)
{
if (mJoinerRouters[i].mPriority > joinerRouter->mPriority)
{
joinerRouter = &mJoinerRouters[i];
}
}
if (joinerRouter->mPriority > 0)
{
Ip6::SockAddr sockaddr;
joinerRouter->mPriority = 0;
netif.GetMac().SetPanId(joinerRouter->mPanId);
netif.GetMac().SetPanChannel(joinerRouter->mChannel);
netif.GetIp6Filter().AddUnsecurePort(OPENTHREAD_CONFIG_JOINER_UDP_PORT);
sockaddr.GetAddress().mFields.m16[0] = HostSwap16(0xfe80);
sockaddr.GetAddress().SetIid(joinerRouter->mExtAddr);
sockaddr.mPort = joinerRouter->mJoinerUdpPort;
sockaddr.mScopeId = OT_NETIF_INTERFACE_ID_THREAD;
netif.GetCoapSecure().Connect(sockaddr, Joiner::HandleSecureCoapClientConnect, this);
mState = OT_JOINER_STATE_CONNECT;
error = OT_ERROR_NONE;
}
else
{
otLogDebgMeshCoP("No joinable networks remaining to try");
}
return error;
}
示例9: while
otError Tlv::GetOffset(const Message &aMessage, uint8_t aType, uint16_t &aOffset)
{
otError error = OT_ERROR_NOT_FOUND;
uint16_t offset = aMessage.GetOffset();
uint16_t end = aMessage.GetLength();
Tlv tlv;
while (offset + sizeof(tlv) <= end)
{
uint32_t length = sizeof(tlv);
aMessage.Read(offset, sizeof(tlv), &tlv);
if (tlv.GetLength() != kExtendedLength)
{
length += tlv.GetLength();
}
else
{
uint16_t extLength;
VerifyOrExit(sizeof(extLength) == aMessage.Read(offset + sizeof(tlv), sizeof(extLength), &extLength));
length += sizeof(extLength) + HostSwap16(extLength);
}
VerifyOrExit(offset + length <= end);
if (tlv.GetType() == aType)
{
aOffset = offset;
ExitNow(error = OT_ERROR_NONE);
}
offset += static_cast<uint16_t>(length);
}
exit:
return error;
}
示例10: VerifyOrExit
otError Mpl::ProcessOption(Message &aMessage, const Address &aAddress, bool aIsOutbound)
{
otError error;
OptionMpl option;
VerifyOrExit(aMessage.Read(aMessage.GetOffset(), sizeof(option), &option) >= OptionMpl::kMinLength &&
(option.GetSeedIdLength() == OptionMpl::kSeedIdLength0 ||
option.GetSeedIdLength() == OptionMpl::kSeedIdLength2),
error = OT_ERROR_DROP);
if (option.GetSeedIdLength() == OptionMpl::kSeedIdLength0)
{
// Retrieve MPL Seed Id from the IPv6 Source Address.
option.SetSeedId(HostSwap16(aAddress.mFields.m16[7]));
}
// Check MPL Data Messages in the MPL Buffered Set against sequence number.
UpdateBufferedSet(option.GetSeedId(), option.GetSequence());
// Check if the MPL Data Message is new.
error = UpdateSeedSet(option.GetSeedId(), option.GetSequence());
if (error == OT_ERROR_NONE)
{
AddBufferedMessage(aMessage, option.GetSeedId(), option.GetSequence(), aIsOutbound);
}
else if (aIsOutbound)
{
// In case MPL Data Message is generated locally, ignore potential error of the MPL Seed Set
// to allow subsequent retransmissions with the same sequence number.
ExitNow(error = OT_ERROR_NONE);
}
exit:
return error;
}
示例11: GetFlags
/**
* This method returns the TCP Flags.
*
* @returns The TCP Flags.
*
*/
uint16_t GetFlags(void) const { return HostSwap16(mFlags); }
示例12: SetSeedId
/**
* This method sets the MPL Seed Id value.
*
* @param[in] aSeedId The MPL Seed Id value.
*
*/
void SetSeedId(uint16_t aSeedId) { mSeedId = HostSwap16(aSeedId); }
示例13: GetSeedId
/**
* This method returns the MPL Seed Id value.
*
* @returns The MPL Seed Id value.
*
*/
uint16_t GetSeedId(void) const { return HostSwap16(mSeedId); }
示例14: SetSequence
/**
* This method sets the ICMPv6 message sequence for Echo Requests and Replies.
*
* @param[in] aSequence The ICMPv6 message sequence.
*
*/
void SetSequence(uint16_t aSequence) { mData.m16[1] = HostSwap16(aSequence); }
示例15: GetSequence
/**
* This method returns the ICMPv6 message sequence for Echo Requests and Replies.
*
* @returns The ICMPv6 message sequence.
*
*/
uint16_t GetSequence(void) const { return HostSwap16(mData.m16[1]); }