ReactOS 0.4.15-dev-8235-gcd88a97
hostent.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS DNS Shared Library
4 * FILE: lib/dnslib/hostent.c
5 * PURPOSE: Functions for dealing with Host Entry structures
6 */
7
8/* INCLUDES ******************************************************************/
9#include "precomp.h"
10
11/* DATA **********************************************************************/
12
13/* FUNCTIONS *****************************************************************/
14
19 IN ULONG AddressSize,
20 IN ULONG AddressCount,
21 IN ULONG AliasCount)
22{
23 PHOSTENT Hostent;
24 ULONG_PTR BufferPosition = (ULONG_PTR)*Buffer;
25
26 /* Align the hostent on the buffer's 4 byte boundary */
27 BufferPosition += 3 & ~3;
28
29 /* Set up the basic data */
30 Hostent = (PHOSTENT)BufferPosition;
31 Hostent->h_length = (WORD)AddressSize;
32 Hostent->h_addrtype = AddressFamily;
33
34 /* Put aliases after Hostent */
35 Hostent->h_aliases = (PCHAR*)((ULONG_PTR)(Hostent + 1) & ~3);
36
37 /* Zero it out */
38 RtlZeroMemory(Hostent->h_aliases, AliasCount * sizeof(PCHAR));
39
40 /* Put addresses after aliases */
41 Hostent->h_addr_list = (PCHAR*)
42 ((ULONG_PTR)Hostent->h_aliases +
43 (AliasCount * sizeof(PCHAR)) + sizeof(PCHAR));
44
45 /* Update the location */
46 BufferPosition = (ULONG_PTR)Hostent->h_addr_list +
47 ((AddressCount * sizeof(PCHAR)) + sizeof(PCHAR));
48
49 /* Send it back */
50 *Buffer = (PVOID)BufferPosition;
51
52 /* Return the hostent */
53 return Hostent;
54}
55
56VOID
60{
61 /* Loop every pointer in the list */
62 do
63 {
64 /* Update the pointer */
65 *List = (PCHAR)((ULONG_PTR)*List - Base);
66 } while(*List++);
67}
68
69VOID
72{
73 /* Do we have a name? */
74 if (Hostent->h_name)
75 {
76 /* Update it */
77 Hostent->h_name -= (ULONG_PTR)Hostent;
78 }
79
80 /* Do we have aliases? */
81 if (Hostent->h_aliases)
82 {
83 /* Update the pointer */
84 Hostent->h_aliases -= (ULONG_PTR)Hostent;
85
86 /* Fix them up */
87 Dns_PtrArrayToOffsetArray(Hostent->h_aliases, (ULONG_PTR)Hostent);
88 }
89
90 /* Do we have addresses? */
91 if (Hostent->h_addr_list)
92 {
93 /* Fix them up */
94 Dns_PtrArrayToOffsetArray(Hostent->h_addr_list, (ULONG_PTR)Hostent);
95 }
96}
97
Definition: bufpool.h:45
#define ULONG_PTR
Definition: config.h:101
unsigned short WORD
Definition: ntddk_ex.h:93
VOID WINAPI Dns_PtrArrayToOffsetArray(PCHAR *List, ULONG_PTR Base)
Definition: hostent.c:58
PHOSTENT WINAPI Hostent_Init(IN PVOID *Buffer, IN WORD AddressFamily, IN ULONG AddressSize, IN ULONG AddressCount, IN ULONG AliasCount)
Definition: hostent.c:17
VOID WINAPI Hostent_ConvertToOffsets(IN PHOSTENT Hostent)
Definition: hostent.c:71
#define PCHAR
Definition: match.c:90
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2439
short h_length
Definition: winsock.h:137
char ** h_aliases
Definition: winsock.h:135
short h_addrtype
Definition: winsock.h:136
char ** h_addr_list
Definition: winsock.h:138
void * PVOID
Definition: typedefs.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
#define WINAPI
Definition: msvc.h:6
struct hostent * PHOSTENT
Definition: winsock.h:497