gethostbyname_r update.
* gethostbyname_r is now the 6 arg version. * Make enet use the right code path (this should be upstreamed). * Add a compat header to make these declarations visible to all without extra compilation flags.
This commit is contained in:
Родитель
2a60fa0c6f
Коммит
b9c8b95795
|
@ -7480,12 +7480,13 @@ LibraryManager.library = {
|
|||
},
|
||||
|
||||
gethostbyname_r__deps: ['gethostbyname'],
|
||||
gethostbyname_r: function(name, ret, buf, buflen, err) {
|
||||
gethostbyname_r: function(name, ret, buf, buflen, out, err) {
|
||||
var data = _gethostbyname(name);
|
||||
_memcpy(ret, data, ___hostent_struct_layout.__size__);
|
||||
_free(data);
|
||||
{{{ makeSetValue('err', '0', '0', 'i32') }}};
|
||||
return ret;
|
||||
{{{ makeSetValue('out', '0', 'ret', '*') }}};
|
||||
return 0;
|
||||
},
|
||||
|
||||
getaddrinfo__deps: ['$Sockets', '$DNS', '_addrinfo_layout', '_inet_pton4_raw', '_inet_ntop4_raw', '_inet_pton6_raw', '_inet_ntop6_raw', '_write_sockaddr', 'htonl'],
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
#ifndef _COMPAT_NETDB_H_
|
||||
#define _COMPAT_NETDB_H_
|
||||
|
||||
#include_next <netdb.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The musl includes only define these things for old sources or
|
||||
when certain flags are activated. We want these available
|
||||
all of the time for now. */
|
||||
struct hostent *gethostbyname (const char *);
|
||||
struct hostent *gethostbyaddr (const void *, socklen_t, int);
|
||||
|
||||
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _COMPAT_NETDB_H_ */
|
|
@ -80,7 +80,7 @@ enet_address_set_host (ENetAddress * address, const char * name)
|
|||
char buffer [2048];
|
||||
int errnum;
|
||||
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
||||
#if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__EMSCRIPTEN__)
|
||||
gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum);
|
||||
#else
|
||||
hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum);
|
||||
|
|
|
@ -13,12 +13,17 @@
|
|||
|
||||
int main() {
|
||||
char str[INET_ADDRSTRLEN];
|
||||
struct hostent *host = NULL;
|
||||
struct hostent hostData;
|
||||
struct in_addr addr;
|
||||
const char *res;
|
||||
char buffer[2048];
|
||||
int err;
|
||||
|
||||
// resolve the hostname ot an actual address
|
||||
struct hostent *host = gethostbyname("slashdot.org");
|
||||
// gethostbyname_r calls the same stuff as gethostbyname, so we'll test the
|
||||
// more complicated one.
|
||||
// resolve the hostname to an actual address
|
||||
gethostbyname_r("slashdot.org", &hostData, buffer, sizeof(buffer), &host, &err);
|
||||
assert(host->h_addrtype == AF_INET);
|
||||
assert(host->h_length == sizeof(uint32_t));
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче