-#ifndef HAVE_DECL_AI_ADDRCONFIG
-#define AI_ADDRCONFIG 0
-#endif
-
-#define ALIGNMENT sizeof (char *)
-
-static int
-align (int len, int al)
-{
- int i;
- i = len % al;
- if (i)
- len += al - i;
- return len;
-}
-
-struct hostent *
-get_hostent (const char *addr, int len, int type)
-{
- struct hostent *cp;
- int len_ent;
- const char *name;
- int len_name;
- int num_aliases = 1;
- int len_aliases = sizeof (char *);
- int num_addr_list = 1;
- int len_addr_list = sizeof (char *);
- int pos;
- struct in_addr *ipv4;
-
- switch (type)
- {
- case AF_INET:
- ipv4 = (struct in_addr *) addr;
- name = inet_ntoa (*ipv4);
- break;
-
- default:
- return NULL;
- }
-
- len_ent = align (sizeof (*cp), ALIGNMENT);
- len_name = align (strlen (name) + 1, ALIGNMENT);
-
- num_addr_list++;
- len_addr_list += align (len, ALIGNMENT) + sizeof (char *);
-
- cp = (struct hostent *) xmalloc (len_ent + len_name + len_aliases
- + len_addr_list);
-
- cp->h_addrtype = type;
- cp->h_length = len;
- pos = len_ent;
- cp->h_name = (char *) &(((char *) cp) [pos]);
- strcpy (cp->h_name, name);
-
- pos += len_name;
- cp->h_aliases = (char **) &(((char *) cp) [pos]);
- pos += num_aliases * sizeof (char *);
- cp->h_aliases [0] = NULL;
-
- pos = len_ent + len_name + len_aliases;
- cp->h_addr_list = (char **) &(((char *) cp) [pos]);
- pos += num_addr_list * sizeof (char *);
- cp->h_addr_list [0] = (char *) &(((char *) cp) [pos]);
- memcpy (cp->h_addr_list [0], addr, cp->h_length);
- pos += align (cp->h_length, ALIGNMENT);
- cp->h_addr_list [1] = NULL;
-
- return cp;
-}
-
-struct hostent *
-hostent_dup (struct hostent *hp)
-{
- int len_ent = align (sizeof (*hp), ALIGNMENT);
- int len_name = align (strlen (hp->h_name) + 1, ALIGNMENT);
- int num_aliases = 1;
- int len_aliases = sizeof (char *);
- int num_addr_list = 1;
- int len_addr_list = sizeof (char *);
- int pos, i;
- char **sp;
- struct hostent *cp;
-
- for (sp = hp->h_aliases; sp && *sp; sp++)
- {
- num_aliases++;
- len_aliases += align (strlen (*sp) + 1, ALIGNMENT)
- + sizeof (char *);
- }
-
- for (sp = hp->h_addr_list; *sp; sp++)
- {
- num_addr_list++;
- len_addr_list += align (hp->h_length, ALIGNMENT)
- + sizeof (char *);
- }
-
- cp = (struct hostent *) xmalloc (len_ent + len_name + len_aliases
- + len_addr_list);
-
- *cp = *hp;
- pos = len_ent;
- cp->h_name = (char *) &(((char *) cp) [pos]);
- strcpy (cp->h_name, hp->h_name);
-
- pos += len_name;
- cp->h_aliases = (char **) &(((char *) cp) [pos]);
- pos += num_aliases * sizeof (char *);
- for (sp = hp->h_aliases, i = 0; i < num_aliases; i++, sp++)
- if (sp && *sp)
- {
- cp->h_aliases [i] = (char *) &(((char *) cp) [pos]);
- strcpy (cp->h_aliases [i], *sp);
- pos += align (strlen (*sp) + 1, ALIGNMENT);
- }
- else
- cp->h_aliases [i] = NULL;
-
- pos = len_ent + len_name + len_aliases;
- cp->h_addr_list = (char **) &(((char *) cp) [pos]);
- pos += num_addr_list * sizeof (char *);
- for (sp = hp->h_addr_list, i = 0; i < num_addr_list; i++, sp++)
- if (*sp)
- {
- cp->h_addr_list [i] = (char *) &(((char *) cp) [pos]);
- memcpy (cp->h_addr_list [i], *sp, hp->h_length);
- pos += align (hp->h_length, ALIGNMENT);
- }
- else
- cp->h_addr_list [i] = *sp;
-
- return cp;
-}
-
-#ifdef HAVE_GETNAMEINFO
-static socklen_t
-sockaddr_size(const struct sockaddr *sap)
-{
- if (sap->sa_family != AF_INET)
- return 0;
- return (socklen_t)sizeof(struct sockaddr_in);
-}
-#endif /* HAVE_GETNAMEINFO */
-