aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--android/console.c2
-rw-r--r--sockets.c25
-rw-r--r--sockets.h14
3 files changed, 36 insertions, 5 deletions
diff --git a/android/console.c b/android/console.c
index 3a769c1..a8560f4 100644
--- a/android/console.c
+++ b/android/console.c
@@ -912,7 +912,7 @@ do_redir_add( ControlClient client, char* args )
return -1;
}
- if (!inet_strtoip("10.0.2.15", &guest_ip)) {
+ if (inet_strtoip("10.0.2.15", &guest_ip) < 0) {
control_write( client, "KO: unexpected internal failure when resolving 10.0.2.15\r\n" );
return -1;
}
diff --git a/sockets.c b/sockets.c
index 62c1ee3..fa1f39d 100644
--- a/sockets.c
+++ b/sockets.c
@@ -624,8 +624,29 @@ sock_address_init_resolve( SockAddress* a, const char* hostname, uint16_t por
memset(hints, 0, sizeof(hints));
hints->ai_family = preferIn6 ? AF_INET6 : AF_UNSPEC;
- if (getaddrinfo(hostname, NULL, hints, &res) < 0) {
- return _fix_errno();
+ ret = getaddrinfo(hostname, NULL, hints, &res);
+ if (ret != 0) {
+ int err;
+
+ switch (ret) {
+ case EAI_AGAIN: /* server is down */
+ case EAI_FAIL: /* server is sick */
+ err = EHOSTDOWN;
+ break;
+
+ case EAI_NODATA:
+ case EAI_NONAME:
+ err = ENOENT;
+ break;
+
+ case EAI_MEMORY:
+ err = ENOMEM;
+ break;
+
+ default:
+ err = EINVAL;
+ }
+ return _set_errno(err);
}
ret = sock_address_from_bsd( a, res->ai_addr, res->ai_addrlen );
diff --git a/sockets.h b/sockets.h
index 274cf32..0dd06e2 100644
--- a/sockets.h
+++ b/sockets.h
@@ -228,8 +228,18 @@ int sock_address_get_ip( const SockAddress* a );
char* bufprint_sock_address( char* p, char* end, const SockAddress* a );
/* resolve a hostname or decimal IPv4/IPv6 address into a socket address.
- * returns 0 on success, or -1 on failure */
-int sock_address_init_resolve( SockAddress* a, const char* hostname, uint16_t port, int preferIn6 );
+ * returns 0 on success, or -1 on failure. Note that the values or errno
+ * set by this function are the following:
+ *
+ * EINVAL : invalid argument
+ * EHOSTDOWN : could not reach DNS server
+ * ENOENT : no host with this name, or host doesn't have any IP address
+ * ENOMEM : not enough memory to perform request
+ */
+int sock_address_init_resolve( SockAddress* a,
+ const char* hostname,
+ uint16_t port,
+ int preferIn6 );
/* create a new socket, return the socket number of -1 on failure */
int socket_create( SocketFamily family, SocketType type );