* See getaddrinfo.c and getnameinfo.c.
*/
-/* $Id: fake-gai-errnos.h,v 1.1.2.2 2003/07/12 17:41:45 guus Exp $ */
+/* $Id: fake-gai-errnos.h,v 1.1.2.3 2003/08/17 08:32:38 guus Exp $ */
/* for old netdb.h */
#ifndef EAI_NODATA
#define EAI_NODATA 1
#define EAI_MEMORY 2
+#define EAI_FAMILY 3
#endif
return "No address associated with hostname";
case EAI_MEMORY:
return "Memory allocation failure";
+ case EAI_FAMILY:
+ return "Address family not supported";
default:
return "Unknown error";
}
int i;
uint16_t port = 0;
+ if(hints && hints->ai_family != AF_INET && hints->ai_family != AF_UNSPEC)
+ return EAI_FAMILY;
+
if (servname)
port = htons(atoi(servname));
hp = gethostbyname(hostname);
- if(!hp || !hp->h_addr_list[0])
+ if(!hp || !hp->h_addr_list || !hp->h_addr_list[0])
return EAI_NODATA;
for (i = 0; hp->h_addr_list[i]; i++) {
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
struct hostent *hp;
+ int len;
- if(serv)
- snprintf(serv, sizeof(tmpserv), "%d", ntohs(sin->sin_port));
+ if(sa->sa_family != AF_INET)
+ return EAI_FAMILY;
- if(!host)
+ if(serv && servlen) {
+ len = snprintf(serv, servlen, "%d", ntohs(sin->sin_port));
+ if(len < 0 || len >= servlen)
+ return EAI_MEMORY;
+ }
+
+ if(!host || !hostlen)
return 0;
if(flags & NI_NUMERICHOST) {
- strncpy(host, inet_ntoa(sin->sin_addr), sizeof(host));
+ len = snprintf((host, hostlen, "%s", inet_ntoa(sin->sin_addr));
+ if(len < 0 || len >= hostlen)
+ return EAI_MEMORY;
return 0;
}
hp = gethostbyaddr((char *)&sin->sin_addr, sizeof(struct in_addr), AF_INET);
- if(!hp || !hp->h_name)
+ if(!hp || !hp->h_name || !hp->h_name[0])
return EAI_NODATA;
- if(strlen(hp->h_name) >= hostlen)
+ len = snprintf((host, hostlen, "%s", hp->h_name);
+ if(len < 0 || len >= hostlen)
return EAI_MEMORY;
- strncpy(host, hp->h_name, hostlen);
return 0;
}
#endif /* !HAVE_GETNAMEINFO */