#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
+#include <errno.h>
#include <stdio.h>
#include <ctype.h>
#include <rpc/types.h>
gai_family_type_check(int32_t f)
{
int32_t i;
-
+
for (i = 0; i < supported_family_count; i++)
{
if (f == supported_family[i]) return 0;
gai_socket_type_check(int32_t s)
{
int32_t i;
-
+
for (i = 0; i < supported_socket_count; i++)
{
if (s == supported_socket[i]) return 0;
gai_protocol_type_check(int32_t p)
{
int32_t i;
-
+
for (i = 0; i < supported_protocol_count; i++)
{
if (p == supported_protocol[i]) return 0;
gai_socket_protocol_type_check(int32_t s, int32_t p)
{
int32_t i, j, ss, sp;
-
+
for (i = 0, j = 0; i < supported_socket_protocol_pair_count; i++, j+=2)
{
ss = supported_socket_protocol_pair[j];
if (!xdr_int(&outxdr, (int32_t *)&na))
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
if (encode_kv(&outxdr, "name", nodename) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "service", servname) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "protocol", str) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (socktype != SOCK_UNSPEC)
{
snprintf(str, 64, "%u", socktype);
if (encode_kv(&outxdr, "socktype", str) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (family != PF_UNSPEC)
{
snprintf(str, 64, "%u", family);
if (encode_kv(&outxdr, "family", str) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (canonname != 0)
{
if (encode_kv(&outxdr, "canonname", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (passive != 0)
{
if (encode_kv(&outxdr, "passive", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (parallel != 0)
{
if (encode_kv(&outxdr, "parallel", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
-
+
if (numerichost != 0)
{
if (encode_kv(&outxdr, "numerichost", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
*len = xdr_getpos(&outxdr);
xdr_destroy(&outxdr);
-
+
return 0;
}
if (gai_proc < 0)
{
status = _lookup_link(server_port, "getaddrinfo", &gai_proc);
- if (status != KERN_SUCCESS) return EAI_SYSTEM;
+ if (status != KERN_SUCCESS)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
}
qlen = LU_QBUF_SIZE;
+
+ /* gai_make_query sets errno if it fails */
i = gai_make_query(nodename, servname, hints, qbuf, &qlen);
if (i != 0) return EAI_SYSTEM;
if (!xdr_int(&inxdr, (int32_t *)&n))
{
xdr_destroy(&inxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
servnull = 0;
if ((servname == NULL) || (servname[0] == '\0')) servnull = 1;
-
+
if ((nodenull == 1) && (servnull == 1)) return EAI_NONAME;
status = gai_checkhints(hints);
if (status != 0) return status;
server_port = MACH_PORT_NULL;
if (_lu_running()) server_port = _lookupd_port(0);
- if (server_port == MACH_PORT_NULL) return EAI_SYSTEM;
+ if (server_port == MACH_PORT_NULL)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
if (gai_proc < 0)
{
status = _lookup_link(server_port, "getaddrinfo", &gai_proc);
- if (status != KERN_SUCCESS) return EAI_SYSTEM;
+ if (status != KERN_SUCCESS)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
}
qlen = LU_QBUF_SIZE;
+
+ /* gai_make_query sets errno if it fails */
i = gai_make_query(nodename, servname, hints, qbuf, &qlen);
if (i != 0) return EAI_SYSTEM;
qlen /= BYTES_PER_XDR_UNIT;
- return lu_async_start(p, gai_proc, qbuf, qlen, (void *)callback, context);
+ status = lu_async_start(p, gai_proc, qbuf, qlen, (void *)callback, context);
+ if (status != 0)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
+
+ return 0;
}
int32_t
if (!xdr_int(&xdr, (int32_t *)&n))
{
xdr_destroy(&xdr);
+ errno = EIO;
return EAI_SYSTEM;
}
int32_t i, j, nkeys, nvals, status;
char *key, **vals;
- if ((host == NULL) || (serv == NULL)) return EAI_SYSTEM;
+ if ((host == NULL) || (serv == NULL))
+ {
+ errno = EINVAL;
+ return EAI_SYSTEM;
+ }
- if (!xdr_int(inxdr, &nkeys)) return EAI_SYSTEM;
+ if (!xdr_int(inxdr, &nkeys))
+ {
+ errno = EIO;
+ return EAI_SYSTEM;
+ }
*host = NULL;
*serv = NULL;
key = NULL;
vals = NULL;
nvals = 0;
-
+
status = _lu_xdr_attribute(inxdr, &key, &vals, (uint32_t *)&nvals);
- if (status < 0) return EAI_SYSTEM;
+ if (status < 0)
+ {
+ errno = EIO;
+ return EAI_SYSTEM;
+ }
if (nvals == 0)
{
ifnum = s6->sin6_addr.__u6_addr.__u6_addr16[1];
if (ifnum == 0) ifnum = s6->sin6_scope_id;
else if ((s6->sin6_scope_id != 0) && (ifnum != s6->sin6_scope_id)) return EAI_FAIL;
-
+
s6->sin6_addr.__u6_addr.__u6_addr16[1] = 0;
s6->sin6_scope_id = ifnum;
if ((ifnum != 0) && (flags & NI_NUMERICHOST)) flags |= NI_WITHSCOPEID;
if (!xdr_int(&outxdr, (int32_t *)&na))
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
if (encode_kv(&outxdr, key, str) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "port", str) != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "protocol", "udp") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "fqdn", "0") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "numerichost", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "numericserv", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
if (encode_kv(&outxdr, "name_required", "1") != 0)
{
xdr_destroy(&outxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
}
*len = xdr_getpos(&outxdr);
xdr_destroy(&outxdr);
-
+
return 0;
}
return i;
}
}
-
+
wanth = 0;
if ((host != NULL) && (hostlen != 0)) wanth = 1;
*/
server_port = MACH_PORT_NULL;
if (_lu_running()) server_port = _lookupd_port(0);
- if (server_port == MACH_PORT_NULL) return EAI_SYSTEM;
+ if (server_port == MACH_PORT_NULL)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
if (gni_proc < 0)
{
status = _lookup_link(server_port, "getnameinfo", &gni_proc);
- if (status != KERN_SUCCESS) return EAI_SYSTEM;
+ if (status != KERN_SUCCESS)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
}
qlen = LU_QBUF_SIZE;
if (!xdr_int(&inxdr, (int32_t *)&n))
{
xdr_destroy(&inxdr);
+ errno = EIO;
return EAI_SYSTEM;
}
server_port = MACH_PORT_NULL;
if (_lu_running()) server_port = _lookupd_port(0);
- if (server_port == MACH_PORT_NULL) return EAI_SYSTEM;
+ if (server_port == MACH_PORT_NULL)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
if (gni_proc < 0)
{
status = _lookup_link(server_port, "getnameinfo", &gni_proc);
- if (status != KERN_SUCCESS) return EAI_SYSTEM;
+ if (status != KERN_SUCCESS)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
}
qlen = LU_QBUF_SIZE;
qlen /= BYTES_PER_XDR_UNIT;
- return lu_async_start(p, gni_proc, qbuf, qlen, (void *)callback, context);
+ status = lu_async_start(p, gni_proc, qbuf, qlen, (void *)callback, context);
+ if (status != 0)
+ {
+ errno = ECONNREFUSED;
+ return EAI_SYSTEM;
+ }
+
+ return 0;
}
int32_t
if (!xdr_int(&xdr, (int32_t *)&n))
{
xdr_destroy(&xdr);
+ errno = EIO;
return EAI_SYSTEM;
}