From b9096d3df8b11f983d502f6157235729dc6e93a1 Mon Sep 17 00:00:00 2001
From: Alex Crichton <alex@alexcrichton.com>
Date: Tue, 3 Nov 2015 10:08:44 -0800
Subject: [PATCH] Add getaddrinfo functions

---
 src/unix/bsd/mod.rs                  |  7 +++++++
 src/unix/mod.rs                      |  8 +++++++-
 src/unix/notbsd/android/mod.rs       |  7 +++++++
 src/unix/notbsd/linux/mips.rs        | 10 ++++++++++
 src/unix/notbsd/linux/notmips/mod.rs | 10 ++++++++++
 5 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs
index ca738062..03fe18c2 100644
--- a/src/unix/bsd/mod.rs
+++ b/src/unix/bsd/mod.rs
@@ -135,6 +135,13 @@ extern {
     pub fn setgroups(ngroups: ::c_int,
                      ptr: *const ::gid_t) -> ::c_int;
     pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
+    pub fn getnameinfo(sa: *const ::sockaddr,
+                       salen: ::socklen_t,
+                       host: *mut ::c_char,
+                       hostlen: ::socklen_t,
+                       serv: *mut ::c_char,
+                       sevlen: ::socklen_t,
+                       flags: ::c_int) -> ::c_int;
 }
 
 cfg_if! {
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index 5085028a..fb028971 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -432,7 +432,6 @@ extern {
 
     pub fn utimes(filename: *const ::c_char,
                   times: *const ::timeval) -> ::c_int;
-    pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
     pub fn dlopen(filename: *const ::c_char,
                   flag: ::c_int) -> *mut ::c_void;
     pub fn dlerror() -> *mut ::c_char;
@@ -440,6 +439,13 @@ extern {
                  symbol: *const ::c_char) -> *mut ::c_void;
     pub fn dlclose(handle: *mut ::c_void) -> ::c_int;
     pub fn dladdr(addr: *const ::c_void, info: *mut Dl_info) -> ::c_int;
+
+    pub fn getaddrinfo(node: *const c_char,
+                       service: *const c_char,
+                       hints: *const addrinfo,
+                       res: *mut *mut addrinfo) -> ::c_int;
+    pub fn freeaddrinfo(res: *mut addrinfo);
+    pub fn gai_strerror(errcode: ::c_int) -> *const ::c_char;
 }
 
 // TODO: get rid of this #[cfg(not(...))]
diff --git a/src/unix/notbsd/android/mod.rs b/src/unix/notbsd/android/mod.rs
index 86db969a..37678f4e 100644
--- a/src/unix/notbsd/android/mod.rs
+++ b/src/unix/notbsd/android/mod.rs
@@ -218,6 +218,13 @@ extern {
                 flags: ::c_uint) -> ::ssize_t;
     pub fn recv(socket: ::c_int, buf: *mut ::c_void, len: ::size_t,
                 flags: ::c_uint) -> ::ssize_t;
+    pub fn getnameinfo(sa: *const ::sockaddr,
+                       salen: ::socklen_t,
+                       host: *mut ::c_char,
+                       hostlen: ::size_t,
+                       serv: *mut ::c_char,
+                       sevlen: ::size_t,
+                       flags: ::c_int) -> ::c_int;
 }
 
 cfg_if! {
diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs
index 16cdcc82..e51fd67b 100644
--- a/src/unix/notbsd/linux/mips.rs
+++ b/src/unix/notbsd/linux/mips.rs
@@ -235,3 +235,13 @@ pub const SIGCHLD: ::c_int = 18;
 pub const SIGBUS: ::c_int = 10;
 
 pub const SIG_SETMASK: ::c_int = 3;
+
+extern {
+    pub fn getnameinfo(sa: *const ::sockaddr,
+                       salen: ::socklen_t,
+                       host: *mut ::c_char,
+                       hostlen: ::socklen_t,
+                       serv: *mut ::c_char,
+                       sevlen: ::socklen_t,
+                       flags: ::c_uint) -> ::c_int;
+}
diff --git a/src/unix/notbsd/linux/notmips/mod.rs b/src/unix/notbsd/linux/notmips/mod.rs
index 5deb068d..f974a563 100644
--- a/src/unix/notbsd/linux/notmips/mod.rs
+++ b/src/unix/notbsd/linux/notmips/mod.rs
@@ -179,6 +179,16 @@ pub const SIGCHLD: ::c_int = 17;
 pub const SIGBUS: ::c_int = 7;
 pub const SIG_SETMASK: ::c_int = 2;
 
+extern {
+    pub fn getnameinfo(sa: *const ::sockaddr,
+                       salen: ::socklen_t,
+                       host: *mut ::c_char,
+                       hostlen: ::socklen_t,
+                       serv: *mut ::c_char,
+                       sevlen: ::socklen_t,
+                       flags: ::c_int) -> ::c_int;
+}
+
 cfg_if! {
     if #[cfg(any(target_arch = "x86", target_arch = "arm"))] {
         mod b32;
-- 
GitLab