aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Mitchener <bruce.mitchener@gmail.com>2013-09-05 09:26:42 +0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-13 10:07:03 -0700
commitb9c8b95795849264c58be7d1496da3c4078df96c (patch)
treed4e5ec70082f4c03347b7cccdbfde691ae385186
parent2a60fa0c6f107959b754824a525a3d69294b9696 (diff)
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.
-rw-r--r--src/library.js5
-rw-r--r--system/include/compat/netdb.h22
-rw-r--r--tests/enet/unix.c2
-rw-r--r--tests/sockets/test_gethostbyname.c9
4 files changed, 33 insertions, 5 deletions
diff --git a/src/library.js b/src/library.js
index 466dc519..af0e8c97 100644
--- a/src/library.js
+++ b/src/library.js
@@ -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'],
diff --git a/system/include/compat/netdb.h b/system/include/compat/netdb.h
new file mode 100644
index 00000000..2aa1e950
--- /dev/null
+++ b/system/include/compat/netdb.h
@@ -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_ */
diff --git a/tests/enet/unix.c b/tests/enet/unix.c
index a225b57d..67d4a8b8 100644
--- a/tests/enet/unix.c
+++ b/tests/enet/unix.c
@@ -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);
diff --git a/tests/sockets/test_gethostbyname.c b/tests/sockets/test_gethostbyname.c
index de7da706..459c6b98 100644
--- a/tests/sockets/test_gethostbyname.c
+++ b/tests/sockets/test_gethostbyname.c
@@ -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));