mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-20 00:15:27 +00:00
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.
This commit is contained in:
@@ -70,7 +70,7 @@
|
|||||||
#ifdef MR_WIN32
|
#ifdef MR_WIN32
|
||||||
#include <winsock.h>
|
#include <winsock.h>
|
||||||
|
|
||||||
#define error() WSAGetLastError
|
#define error() WSAGetLastError()
|
||||||
|
|
||||||
#else /* !MR_WIN32 */
|
#else /* !MR_WIN32 */
|
||||||
|
|
||||||
@@ -184,7 +184,7 @@
|
|||||||
} else {
|
} else {
|
||||||
addr = MR_GC_NEW(struct sockaddr_in);
|
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_family = host->h_addrtype;
|
||||||
addr->sin_port = htons(Port);
|
addr->sin_port = htons(Port);
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@
|
|||||||
Success = MR_NO;
|
Success = MR_NO;
|
||||||
} else {
|
} else {
|
||||||
addr = MR_GC_NEW(struct sockaddr_in);
|
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_family = host->h_addrtype;
|
||||||
addr->sin_port = service->s_port;
|
addr->sin_port = service->s_port;
|
||||||
SA = (MR_Word) addr;
|
SA = (MR_Word) addr;
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ void ML_tcp_init(void)
|
|||||||
} else {
|
} else {
|
||||||
addr = MR_GC_NEW(struct sockaddr_in);
|
addr = MR_GC_NEW(struct sockaddr_in);
|
||||||
MR_memset(addr, 0, sizeof(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_family = host->h_addrtype;
|
||||||
addr->sin_port = htons(Port);
|
addr->sin_port = htons(Port);
|
||||||
/*
|
/*
|
||||||
@@ -334,7 +334,7 @@ socket_fd(Tcp) = socket_fd_c(Tcp ^ handle).
|
|||||||
} else {
|
} else {
|
||||||
addr = MR_GC_NEW(struct sockaddr_in);
|
addr = MR_GC_NEW(struct sockaddr_in);
|
||||||
MR_memset(addr, 0, sizeof(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_family = host->h_addrtype;
|
||||||
addr->sin_port = htons(Port);
|
addr->sin_port = htons(Port);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user