Exemplo n.º 1
0
void* Allocator::_Realloc(void* ptr, size_t size, const char* file_name, unsigned int line_num)
{
	//LOG("%s:%d  realloc(%p, %d)\n", file_name, line_num, ptr, size);

	byte* pBlock = (byte*)ptr - sizeof(Header);
	Header* pHeader = reinterpret_cast<Header*>(pBlock);
	Footer* pFooter = reinterpret_cast<Footer*>((byte*)ptr+size);

	ASSERT(pHeader->m_pBlockNode != NULL);
	BlockNode* pNode = pHeader->m_pBlockNode;

	size_t total = size + sizeof(Header) + sizeof(Footer);
	pBlock = (byte*)realloc(pBlock, total);
	ptr = pBlock + sizeof(Header);

	pHeader = reinterpret_cast<Header*>(pBlock);
	pFooter = reinterpret_cast<Footer*>((byte*)ptr+size);

	pHeader->Init(size, file_name, line_num);
	pFooter->Init(size, file_name, line_num);

	pNode->pBlock = pBlock;
	pHeader->m_pBlockNode = pNode;
	
	return ptr;
}
Exemplo n.º 2
0
void Client::SendEmptyMessage(const Ip6::Address &aAddress, uint16_t aPort, uint16_t aMessageId, Header::Type aType)
{
    Header header;
    Ip6::MessageInfo messageInfo;
    Message *message;
    ThreadError error = kThreadError_None;

    header.Init(aType, kCoapCodeEmpty);
    header.SetMessageId(aMessageId);

    VerifyOrExit((message = NewMessage(header)) != NULL, ;);
Exemplo n.º 3
0
void* Allocator::_Malloc(size_t size, const char* file_name, unsigned int line_num)
{
	//LOG("%s:%d  malloc(%d)\n", file_name, line_num, size);

	size_t total = size + sizeof(Header) + sizeof(Footer);
	byte* pBlock = (byte*)malloc(total);
	byte* ptr = pBlock + sizeof(Header);

	Header* pHeader = reinterpret_cast<Header*>(pBlock);
	Footer* pFooter = reinterpret_cast<Footer*>(ptr+size);

	pHeader->Init(size, file_name, line_num);
	pFooter->Init(size, file_name, line_num);

	AddBlock(pBlock);

	return ptr;
}
Exemplo n.º 4
0
ThreadError Ip6::SendDatagram(Message &message, MessageInfo &messageInfo, IpProto ipproto)
{
    ThreadError error = kThreadError_None;
    Header header;
    uint16_t payloadLength = message.GetLength();
    uint16_t checksum;
    const NetifUnicastAddress *source;

    header.Init();
    header.SetPayloadLength(payloadLength);
    header.SetNextHeader(ipproto);
    header.SetHopLimit(messageInfo.mHopLimit ? messageInfo.mHopLimit : kDefaultHopLimit);

    if (messageInfo.GetSockAddr().IsUnspecified())
    {
        VerifyOrExit((source = Netif::SelectSourceAddress(messageInfo)) != NULL, error = kThreadError_Error);
        header.SetSource(source->GetAddress());
    }
    else
    {
        header.SetSource(messageInfo.GetSockAddr());
    }

    header.SetDestination(messageInfo.GetPeerAddr());

    if (header.GetDestination().IsLinkLocal() || header.GetDestination().IsLinkLocalMulticast())
    {
        VerifyOrExit(messageInfo.mInterfaceId != 0, error = kThreadError_Drop);
    }

    if (messageInfo.GetPeerAddr().IsRealmLocalMulticast())
    {
        SuccessOrExit(error = AddMplOption(message, header, ipproto, payloadLength));
    }

    SuccessOrExit(error = message.Prepend(&header, sizeof(header)));

    // compute checksum
    checksum = ComputePseudoheaderChecksum(header.GetSource(), header.GetDestination(),
                                           payloadLength, ipproto);

    switch (ipproto)
    {
    case kProtoUdp:
        SuccessOrExit(error = Udp::UpdateChecksum(message, checksum));
        break;

    case kProtoIcmp6:
        SuccessOrExit(error = Icmp::UpdateChecksum(message, checksum));
        break;

    default:
        break;
    }

exit:

    if (error == kThreadError_None)
    {
        error = HandleDatagram(message, NULL, messageInfo.mInterfaceId, NULL, false);
    }

    return error;
}