当前位置: 首页>>代码示例>>C++>>正文


C++ HostSwap16函数代码示例

本文整理汇总了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;
}
开发者ID:HarryMorris,项目名称:openthread,代码行数:34,代码来源:tlvs.cpp

示例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();
    }
}
开发者ID:turon,项目名称:openthread,代码行数:59,代码来源:joiner_router.cpp

示例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;
}
开发者ID:lanyuwen,项目名称:openthread,代码行数:13,代码来源:udp6.cpp

示例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;
}
开发者ID:BJangeofan,项目名称:openthread,代码行数:16,代码来源:ip6.cpp

示例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);
}
开发者ID:pvanhorn,项目名称:openthread,代码行数:18,代码来源:cli_udp_example.cpp

示例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);
}
开发者ID:xiaom-GitHub,项目名称:openthread,代码行数:41,代码来源:leader.cpp

示例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);
}
开发者ID:abtink,项目名称:openthread,代码行数:21,代码来源:meshcop_tlvs.cpp

示例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;
}
开发者ID:turon,项目名称:openthread,代码行数:40,代码来源:joiner.cpp

示例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;
}
开发者ID:mtornblad,项目名称:openthread,代码行数:39,代码来源:tlvs.cpp

示例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;
}
开发者ID:lanyuwen,项目名称:openthread,代码行数:36,代码来源:ip6_mpl.cpp

示例11: GetFlags

 /**
  * This method returns the TCP Flags.
  *
  * @returns The TCP Flags.
  *
  */
 uint16_t GetFlags(void) const { return HostSwap16(mFlags); }
开发者ID:lanyuwen,项目名称:openthread,代码行数:7,代码来源:tcp.hpp

示例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); }
开发者ID:lanyuwen,项目名称:openthread,代码行数:7,代码来源:ip6_mpl.hpp

示例13: GetSeedId

 /**
  * This method returns the MPL Seed Id value.
  *
  * @returns The MPL Seed Id value.
  *
  */
 uint16_t GetSeedId(void) const { return HostSwap16(mSeedId); }
开发者ID:lanyuwen,项目名称:openthread,代码行数:7,代码来源:ip6_mpl.hpp

示例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); }
开发者ID:itavero,项目名称:openthread,代码行数:7,代码来源:icmp6.hpp

示例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]); }
开发者ID:itavero,项目名称:openthread,代码行数:7,代码来源:icmp6.hpp


注:本文中的HostSwap16函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。