ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

PHOSTENT WINAPI SaBlob_CreateHostent ( IN OUT PULONG_PTR  BufferPosition,
IN OUT PSIZE_T  FreeBufferSpace,
IN OUT PSIZE_T  HostEntrySize,
IN PDNS_BLOB  Blob,
IN DWORD  StringType,
IN BOOLEAN  Relative,
IN BOOLEAN  BufferAllocated 
)

Definition at line 131 of file sablob.c.

{
    PDNS_ARRAY DnsAddrArray = Blob->DnsAddrArray;
    ULONG AliasCount = Blob->AliasCount;
    WORD AddressFamily = AF_UNSPEC;
    ULONG AddressCount = 0, AddressSize = 0, TotalSize, NamePointerSize;
    ULONG AliasPointerSize;
    PDNS_FAMILY_INFO FamilyInfo = NULL;
    ULONG StringLength = 0;
    ULONG i;
    ULONG HostentSize = 0;
    PHOSTENT Hostent = NULL;
    ULONG_PTR HostentPtr;
    PVOID CurrentAddress;

    /* Check if we actually have any addresses */
    if (DnsAddrArray)
    {
        /* Get the address family */
        AddressFamily = DnsAddrArray->Addresses[0].AddressFamily;

        /* Get family information */
        FamilyInfo = FamilyInfo_GetForFamily(AddressFamily);

        /* Save the current address count and their size */
        AddressCount = DnsAddrArray->UsedAddresses;
        AddressSize = FamilyInfo->AddressSize;
    }

    /* Calculate total size for all the addresses, and their pointers */
    TotalSize = AddressSize * AddressCount;
    NamePointerSize = AddressCount * sizeof(PVOID) + sizeof(PVOID);

    /* Check if we have a name */
    if (Blob->Name)
    {
        /* Find out the size we'll need for a copy */
        StringLength = (Dns_GetBufferLengthForStringCopy(Blob->Name,
                                                         0,
                                                         UnicodeString,
                                                         StringType) + 1) & ~1;
    }

    /*  Now do the same for the aliases */
    for (i = AliasCount; i; i--)
    {
        /* Find out the size we'll need for a copy */
        HostentSize += (Dns_GetBufferLengthForStringCopy(Blob->Aliases[i],
                                                         0,
                                                         UnicodeString,
                                                         StringType) + 1) & ~1;
    }

    /* Find out how much the pointers will take */
    AliasPointerSize = AliasCount * sizeof(PVOID) + sizeof(PVOID);

    /* Calculate Hostent Size */
    HostentSize += TotalSize +
                   NamePointerSize +
                   AliasPointerSize +
                   StringLength +
                   sizeof(HOSTENT);

    /* Check if we already have a buffer */
    if (!BufferAllocated)
    {
        /* We don't, allocate space ourselves */
        HostentPtr = (ULONG_PTR)Dns_AllocZero(HostentSize);
    }
    else
    {
        /* We do, so allocate space in the buffer */
        HostentPtr = (ULONG_PTR)FlatBuf_Arg_ReserveAlignPointer(BufferPosition,
                                                                FreeBufferSpace,
                                                                HostentSize);
    }

    /* Make sure we got space */
    if (HostentPtr)
    {
        /* Initialize it */
        Hostent = Hostent_Init((PVOID)&HostentPtr,
                               AddressFamily,
                               AddressSize,
                               AddressCount,
                               AliasCount);
    }

    /* Loop the addresses */
    for (i = 0; i < AddressCount; i++)
    {
        /* Get the pointer of the current address */
        CurrentAddress = (PVOID)((ULONG_PTR)&DnsAddrArray->Addresses[i] +
                                             FamilyInfo->AddressOffset);

        /* Write the pointer */
        Hostent->h_addr_list[i] = (PCHAR)HostentPtr;

        /* Copy the address */
        RtlCopyMemory((PVOID)HostentPtr, CurrentAddress, AddressSize);

        /* Advance the buffer */
        HostentPtr += AddressSize;
    }

    /* Check if we have a name */
    if (Blob->Name)
    {
        /* Align our current position */
        HostentPtr += 1 & ~1;

        /* Save our name here */
        Hostent->h_name = (LPSTR)HostentPtr;

        /* Now copy it in the blob */
        HostentPtr += Dns_StringCopy((PVOID)HostentPtr,
                                     NULL,
                                     Blob->Name,
                                     0,
                                     UnicodeString,
                                     StringType);
    }

    /* Loop the Aliases */
    for (i = AliasCount; i; i--)
    {
        /* Align our current position */
        HostentPtr += 1 & ~1;

        /* Save our alias here */
        Hostent->h_aliases[i] = (LPSTR)HostentPtr;

        /* Now copy it in the blob */
        HostentPtr += Dns_StringCopy((PVOID)HostentPtr,
                                     NULL,
                                     Blob->Aliases[i],
                                     0,
                                     UnicodeString,
                                     StringType);
    }

    /* Check if the caller didn't have a buffer */
    if (!BufferAllocated)
    {
        /* Return the size; not needed if we had a blob, since it's internal */
        *HostEntrySize = *BufferPosition - (ULONG_PTR)HostentPtr;
    }

    /* Convert to Offsets if requested */
    if(Relative) Hostent_ConvertToOffsets(Hostent);

    /* Return the full, complete, hostent */
    return Hostent;
}

Generated on Sun May 27 2012 06:03:29 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.