+ *++q = 0; /* null terminate the pointer list */
+ h->h_addr_list = h_addr_list; /* copy pointer to pointers */
+
+ /* ensure word alignment of pointers */
+ misalign = sizeof(char *) - pos%sizeof(char *);
+ if(misalign < sizeof(char *))
+ pos += misalign;
+
+ /* leave space for pointer list */
+ p = h->h_aliases;
+ char **h_aliases = (char **)(buffer + pos);
+ while(*(p++) != 0)
+ pos += sizeof(char *);
+
+ /* copy aliases and fill new pointer list */
+ for (p = h->h_aliases, q = h_aliases; *p != 0; p++, q++)
+ {
+ len = strlen(*p);
+ if (size <= pos + len)
+ {
+ *err = ENOMEM;
+ return NULL;
+ }
+ memcpy(buffer + pos, *p, len); /* copy content */
+ buffer[pos + len] = '\0';
+ *q = buffer + pos; /* set copied pointer to copied content */
+ pos += len + 1;
+ }
+ *++q = 0; /* null terminate the pointer list */
+ h->h_aliases = h_aliases; /* copy pointer to pointers */
+
+ return h;
+}
+#endif // HAVE_GETHOSTBYNAME
+
+hostent *wxGethostbyname_r(const char *hostname,
+ hostent *h,
+ wxGethostBuf buffer,
+ int size,
+ int *err)
+{
+ hostent *he;
+#if defined(HAVE_FUNC_GETHOSTBYNAME_R_6)
+ gethostbyname_r(hostname, h, buffer, size, &he, err);
+#elif defined(HAVE_FUNC_GETHOSTBYNAME_R_5)
+ he = gethostbyname_r(hostname, h, buffer, size, err);
+#elif defined(HAVE_FUNC_GETHOSTBYNAME_R_3)
+ he = gethostbyname_r(hostname, h, &buffer);
+ *err = h_errno;
+#elif defined(HAVE_GETHOSTBYNAME)
+ wxLOCK_GETBY_MUTEX(name);
+
+ he = gethostbyname(hostname);
+ *err = h_errno;
+
+ if ( he )
+ he = deepCopyHostent(h, he, buffer, size, err);
+#else
+ #error "No gethostbyname[_r]()"
+#endif
+
+ return he;
+}
+
+hostent *wxGethostbyaddr_r(const char *addr_buf,
+ int buf_size,
+ int proto,
+ hostent *h,
+ wxGethostBuf buffer,
+ int size,
+ int *err)
+{
+ hostent *he;
+#if defined(HAVE_FUNC_GETHOSTBYADDR_R_6)
+ gethostbyaddr_r(addr_buf, buf_size, proto, h, buffer, size, &he, err);
+#elif defined(HAVE_FUNC_GETHOSTBYADDR_R_5)
+ he = gethostbyaddr_r(addr_buf, buf_size, proto, h, buffer, size, err);
+#elif defined(HAVE_FUNC_GETHOSTBYADDR_R_3)
+ he = gethostbyaddr_r(addr_buf, buf_size, proto, h, buffer);
+ *err = h_errno;
+#elif defined(HAVE_GETHOSTBYADDR)
+ wxLOCK_GETBY_MUTEX(addr);
+
+ he = gethostbyaddr(addr_buf, buf_size, proto);
+ *err = h_errno;
+
+ if ( he )
+ he = deepCopyHostent(h, he, buffer, size, err);
+#else
+ #error "No gethostbyaddr[_r]()"
+#endif
+
+ return he;