ReactOS  0.4.15-dev-1201-gb2cf5a4
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 
16 WINAPI
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 
56 VOID
57 WINAPI
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 
69 VOID
70 WINAPI
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 
signed char * PCHAR
Definition: retypes.h:7
#define IN
Definition: typedefs.h:39
char ** h_addr_list
Definition: winsock.h:138
VOID WINAPI Hostent_ConvertToOffsets(IN PHOSTENT Hostent)
Definition: hostent.c:71
IN PCO_ADDRESS_FAMILY AddressFamily
Definition: ndis.h:1906
_In_opt_ ULONG Base
Definition: rtlfuncs.h:2373
char ** h_aliases
Definition: winsock.h:135
VOID WINAPI Dns_PtrArrayToOffsetArray(PCHAR *List, ULONG_PTR Base)
Definition: hostent.c:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
PHOSTENT WINAPI Hostent_Init(IN PVOID *Buffer, IN WORD AddressFamily, IN ULONG AddressSize, IN ULONG AddressCount, IN ULONG AliasCount)
Definition: hostent.c:17
short h_length
Definition: winsock.h:137
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
#define PCHAR
Definition: match.c:90
LIST_ENTRY List
Definition: psmgr.c:57
#define WINAPI
Definition: msvc.h:6
unsigned short WORD
Definition: ntddk_ex.h:93
short h_addrtype
Definition: winsock.h:136
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define ULONG_PTR
Definition: config.h:101
struct hostent * PHOSTENT
Definition: winsock.h:497