summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRuslan Mustakov <ruslan.mustakov@xored.com>2016-06-22 20:50:18 +0600
committerRuslan Mustakov <ruslan.mustakov@xored.com>2016-06-22 20:50:18 +0600
commit45f76738ee6643cf434eb1f7326ad8ad40c344f9 (patch)
tree20458a21a7da2cbd1e10670ddec8a65bdb4e0608
parent4b0ba5e3f1b78b3c45a3f1576ed3d60f9a8b6d80 (diff)
downloadNim-45f76738ee6643cf434eb1f7326ad8ad40c344f9.tar.gz
Added 'android4' define support that declares a different gethostbyaddr. Fixes #4376
-rw-r--r--lib/deprecated/pure/sockets.nim9
-rw-r--r--lib/posix/posix.nim8
-rw-r--r--lib/pure/nativesockets.nim9
3 files changed, 20 insertions, 6 deletions
diff --git a/lib/deprecated/pure/sockets.nim b/lib/deprecated/pure/sockets.nim
index 20e6d9364..34c2e7a7d 100644
--- a/lib/deprecated/pure/sockets.nim
+++ b/lib/deprecated/pure/sockets.nim
@@ -711,8 +711,13 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
                                   cint(sockets.AF_INET))
     if s == nil: raiseOSError(osLastError())
   else:
-    var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
-                                cint(posix.AF_INET))
+    var s =
+      when defined(android4):
+        posix.gethostbyaddr(cast[cstring](addr(myaddr)), sizeof(myaddr).cint,
+                            cint(posix.AF_INET))
+      else:
+        posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
+                            cint(posix.AF_INET))
     if s == nil:
       raiseOSError(osLastError(), $hstrerror(h_errno))
 
diff --git a/lib/posix/posix.nim b/lib/posix/posix.nim
index 6a13eec28..9718741a6 100644
--- a/lib/posix/posix.nim
+++ b/lib/posix/posix.nim
@@ -2616,8 +2616,12 @@ proc gai_strerror*(a1: cint): cstring {.importc:"(char *)$1", header: "<netdb.h>
 proc getaddrinfo*(a1, a2: cstring, a3: ptr AddrInfo,
                   a4: var ptr AddrInfo): cint {.importc, header: "<netdb.h>".}
 
-proc gethostbyaddr*(a1: pointer, a2: Socklen, a3: cint): ptr Hostent {.
-                    importc, header: "<netdb.h>".}
+when not defined(android4):
+  proc gethostbyaddr*(a1: pointer, a2: Socklen, a3: cint): ptr Hostent {.
+                      importc, header: "<netdb.h>".}
+else:
+  proc gethostbyaddr*(a1: cstring, a2: cint, a3: cint): ptr Hostent {.
+                      importc, header: "<netdb.h>".}
 proc gethostbyname*(a1: cstring): ptr Hostent {.importc, header: "<netdb.h>".}
 proc gethostent*(): ptr Hostent {.importc, header: "<netdb.h>".}
 
diff --git a/lib/pure/nativesockets.nim b/lib/pure/nativesockets.nim
index 15828ff35..4526afa49 100644
--- a/lib/pure/nativesockets.nim
+++ b/lib/pure/nativesockets.nim
@@ -326,8 +326,13 @@ proc getHostByAddr*(ip: string): Hostent {.tags: [ReadIOEffect].} =
                                   cint(AF_INET))
     if s == nil: raiseOSError(osLastError())
   else:
-    var s = posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
-                                cint(posix.AF_INET))
+    var s =
+      when defined(android4):
+        posix.gethostbyaddr(cast[cstring](addr(myaddr)), sizeof(myaddr).cint,
+                            cint(posix.AF_INET))
+      else:
+        posix.gethostbyaddr(addr(myaddr), sizeof(myaddr).Socklen,
+                            cint(posix.AF_INET))
     if s == nil:
       raiseOSError(osLastError(), $hstrerror(h_errno))