Commit f9f9566c authored by Erich Hoover's avatar Erich Hoover Committed by Alexandre Julliard

ws2_32: Separate out hostent creation from duplication.

parent 49d40d80
...@@ -282,6 +282,7 @@ static INT num_startup; /* reference counter */ ...@@ -282,6 +282,7 @@ static INT num_startup; /* reference counter */
static FARPROC blocking_hook = (FARPROC)WSA_DefaultBlockingHook; static FARPROC blocking_hook = (FARPROC)WSA_DefaultBlockingHook;
/* function prototypes */ /* function prototypes */
static struct WS_hostent *WS_create_he(char *name, int aliases, int addresses);
static struct WS_hostent *WS_dup_he(const struct hostent* p_he); static struct WS_hostent *WS_dup_he(const struct hostent* p_he);
static struct WS_protoent *WS_dup_pe(const struct protoent* p_pe); static struct WS_protoent *WS_dup_pe(const struct protoent* p_pe);
static struct WS_servent *WS_dup_se(const struct servent* p_se); static struct WS_servent *WS_dup_se(const struct servent* p_se);
...@@ -4459,33 +4460,60 @@ static int list_dup(char** l_src, char** l_to, int item_size) ...@@ -4459,33 +4460,60 @@ static int list_dup(char** l_src, char** l_to, int item_size)
/* ----- hostent */ /* ----- hostent */
/* duplicate hostent entry /* create a hostent entry
* and handle all Win16/Win32 dependent things (struct size, ...) *correctly*. *
* Ditto for protoent and servent. * Creates the entry with enough memory for the name, aliases
* addresses, and the address pointers. Also copies the name
* and sets up all the pointers.
*/ */
static struct WS_hostent *WS_dup_he(const struct hostent* p_he) static struct WS_hostent *WS_create_he(char *name, int aliases, int addresses)
{ {
char *p;
struct WS_hostent *p_to; struct WS_hostent *p_to;
char *p;
int size = (sizeof(*p_he) + int size = (sizeof(struct WS_hostent) +
strlen(p_he->h_name) + 1 + strlen(name) + 1 +
list_size(p_he->h_aliases, 0) + sizeof(char *)*aliases +
list_size(p_he->h_addr_list, p_he->h_length)); sizeof(char *)*addresses);
if (!(p_to = check_buffer_he(size))) return NULL; if (!(p_to = check_buffer_he(size))) return NULL;
p_to->h_addrtype = p_he->h_addrtype; memset(p_to, 0, size);
p_to->h_length = p_he->h_length;
p = (char *)(p_to + 1); p = (char *)(p_to + 1);
p_to->h_name = p; p_to->h_name = p;
strcpy(p, p_he->h_name); strcpy(p, name);
p += strlen(p) + 1; p += strlen(p) + 1;
p_to->h_aliases = (char **)p; if (aliases != 0)
p += list_dup(p_he->h_aliases, p_to->h_aliases, 0); {
p_to->h_aliases = (char **)p;
p += sizeof(char *)*aliases;
}
if (addresses != 0)
{
p_to->h_addr_list = (char **)p;
p += sizeof(char *)*addresses;
}
return p_to;
}
/* duplicate hostent entry
* and handle all Win16/Win32 dependent things (struct size, ...) *correctly*.
* Ditto for protoent and servent.
*/
static struct WS_hostent *WS_dup_he(const struct hostent* p_he)
{
int addresses = list_size(p_he->h_addr_list, p_he->h_length);
int aliases = list_size(p_he->h_aliases, 0);
struct WS_hostent *p_to;
p_to = WS_create_he(p_he->h_name, aliases, addresses);
if (!p_to) return NULL;
p_to->h_addrtype = p_he->h_addrtype;
p_to->h_length = p_he->h_length;
p_to->h_addr_list = (char **)p; list_dup(p_he->h_aliases, p_to->h_aliases, 0);
list_dup(p_he->h_addr_list, p_to->h_addr_list, p_he->h_length); list_dup(p_he->h_addr_list, p_to->h_addr_list, p_he->h_length);
return p_to; return p_to;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment