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
8 /* INCLUDES ******************************************************************/
11 /* DATA **********************************************************************/
13 /* FUNCTIONS *****************************************************************/
17 Hostent_Init(IN PVOID
*Buffer
,
18 IN WORD AddressFamily
,
20 IN ULONG AddressCount
,
24 ULONG_PTR BufferPosition
= (ULONG_PTR
)*Buffer
;
26 /* Align the hostent on the buffer's 4 byte boundary */
27 BufferPosition
+= 3 & ~3;
29 /* Set up the basic data */
30 Hostent
= (PHOSTENT
)BufferPosition
;
31 Hostent
->h_length
= (WORD
)AddressSize
;
32 Hostent
->h_addrtype
= AddressFamily
;
34 /* Put aliases after Hostent */
35 Hostent
->h_aliases
= (PCHAR
*)((ULONG_PTR
)(Hostent
+ 1) & ~3);
38 RtlZeroMemory(Hostent
->h_aliases
, AliasCount
* sizeof(PCHAR
));
40 /* Put addresses after aliases */
41 Hostent
->h_addr_list
= (PCHAR
*)
42 ((ULONG_PTR
)Hostent
->h_aliases
+
43 (AliasCount
* sizeof(PCHAR
)) + sizeof(PCHAR
));
45 /* Update the location */
46 BufferPosition
= (ULONG_PTR
)Hostent
->h_addr_list
+
47 ((AddressCount
* sizeof(PCHAR
)) + sizeof(PCHAR
));
50 *Buffer
= (PVOID
)BufferPosition
;
52 /* Return the hostent */
58 Dns_PtrArrayToOffsetArray(PCHAR
*List
,
61 /* Loop every pointer in the list */
64 /* Update the pointer */
65 *List
= (PCHAR
)((ULONG_PTR
)*List
- Base
);
71 Hostent_ConvertToOffsets(IN PHOSTENT Hostent
)
73 /* Do we have a name? */
77 Hostent
->h_name
-= (ULONG_PTR
)Hostent
;
80 /* Do we have aliases? */
81 if (Hostent
->h_aliases
)
83 /* Update the pointer */
84 Hostent
->h_aliases
-= (ULONG_PTR
)Hostent
;
87 Dns_PtrArrayToOffsetArray(Hostent
->h_aliases
, (ULONG_PTR
)Hostent
);
90 /* Do we have addresses? */
91 if (Hostent
->h_addr_list
)
94 Dns_PtrArrayToOffsetArray(Hostent
->h_addr_list
, (ULONG_PTR
)Hostent
);