[m-rev.] diff: extras/net: Fixes for the net library

Paul Bone paul at bone.id.au
Thu Sep 4 12:38:48 AEST 2014


extras/net: Fixes for the net library

This change fixes two problems with the net library in extras/.

The h_addr field of the hostent structure (see gethostbyname(3)) is
deprecated.  gethostbyname can return multiple addresses in a list in the
field h_addr_list.  I've updated code to use the first item in this list.
Note that use of gethostbyname is also discouraged and getaddrinfo(3) is
recommended.  In a later change I intend to update this library to use
getaddrinfo.

The library used a macro error() to retrieve the error either from errno, or
on Windows from WSAGetLastError.  WSAGetLastError is a function however the
parentheses were missing from the macro causing it to be returned as a value
rather than called.

extras/net/sockets.m:
extras/net/tcp.m:
    As above.
---
 extras/net/sockets.m | 6 +++---
 extras/net/tcp.m     | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/extras/net/sockets.m b/extras/net/sockets.m
index a128842..9aab4c0 100644
--- a/extras/net/sockets.m
+++ b/extras/net/sockets.m
@@ -70,7 +70,7 @@
 #ifdef MR_WIN32
   #include <winsock.h>
 
-  #define  error()      WSAGetLastError
+  #define  error()      WSAGetLastError()
 
 #else /* !MR_WIN32 */
 
@@ -184,7 +184,7 @@
     } else {
         addr = MR_GC_NEW(struct sockaddr_in);
 
-        MR_memcpy(&(addr->sin_addr), host->h_addr, host->h_length);
+        MR_memcpy(&(addr->sin_addr), host->h_addr_list[0], host->h_length);
         addr->sin_family = host->h_addrtype;
         addr->sin_port = htons(Port);
 
@@ -215,7 +215,7 @@
             Success = MR_NO;
         } else {
             addr = MR_GC_NEW(struct sockaddr_in);
-            MR_memcpy(&(addr->sin_addr), host->h_addr, host->h_length);
+            MR_memcpy(&(addr->sin_addr), host->h_addr_list[0], host->h_length);
             addr->sin_family = host->h_addrtype;
             addr->sin_port = service->s_port;
             SA = (MR_Word) addr;
diff --git a/extras/net/tcp.m b/extras/net/tcp.m
index 87995bc..1a116bd 100644
--- a/extras/net/tcp.m
+++ b/extras/net/tcp.m
@@ -274,7 +274,7 @@ void ML_tcp_init(void)
         } else {
             addr = MR_GC_NEW(struct sockaddr_in);
             MR_memset(addr, 0, sizeof(struct sockaddr_in));
-            MR_memcpy(&(addr->sin_addr), host->h_addr, host->h_length);
+            MR_memcpy(&(addr->sin_addr), host->h_addr_list[0], host->h_length);
             addr->sin_family = host->h_addrtype;
             addr->sin_port = htons(Port);
             /*
@@ -334,7 +334,7 @@ socket_fd(Tcp) = socket_fd_c(Tcp ^ handle).
         } else {
             addr = MR_GC_NEW(struct sockaddr_in);
             MR_memset(addr, 0, sizeof(struct sockaddr_in));
-            MR_memcpy(&(addr->sin_addr), host->h_addr, host->h_length);
+            MR_memcpy(&(addr->sin_addr), host->h_addr_list[0], host->h_length);
             addr->sin_family = host->h_addrtype;
             addr->sin_port = htons(Port);
 
-- 
2.1.0.rc1




More information about the reviews mailing list