aboutsummaryrefslogtreecommitdiff
path: root/src/deps/libuwsockets.cpp
diff options
context:
space:
mode:
authorGravatar dave caruso <me@paperdave.net> 2023-09-29 16:17:54 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-29 16:17:54 -0700
commiteddb0078b5c9ff49bf67c0f1b1c2c623f0480b77 (patch)
treeaa7954964d5a79e6d4efe9a149def0e1cfc30f19 /src/deps/libuwsockets.cpp
parentfa7d7bd1e4a701d1f5d3ec89f287f30a2dd0babb (diff)
downloadbun-eddb0078b5c9ff49bf67c0f1b1c2c623f0480b77.tar.gz
bun-eddb0078b5c9ff49bf67c0f1b1c2c623f0480b77.tar.zst
bun-eddb0078b5c9ff49bf67c0f1b1c2c623f0480b77.zip
fix(runtime): followup for `server.requestIP` (#6185)
* fix(runtime): followup for `server.requestIP` * oops * yeah * sure * Update src/deps/libuwsockets.cpp * Update Dockerfile * lol --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com> Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'src/deps/libuwsockets.cpp')
-rw-r--r--src/deps/libuwsockets.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/deps/libuwsockets.cpp b/src/deps/libuwsockets.cpp
index 79dd68b42..bb89b33a8 100644
--- a/src/deps/libuwsockets.cpp
+++ b/src/deps/libuwsockets.cpp
@@ -5,6 +5,8 @@
#include <bun-usockets/src/internal/internal.h>
#include <string_view>
+extern "C" const char* ares_inet_ntop(int af, const char *src, char *dst, size_t size);
+
extern "C"
{
@@ -1577,28 +1579,29 @@ extern "C"
us_poll_change(&s->p, s->context->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
}
+ // Gets the remote address and port
+ // Returns 0 if failure / unix socket
uint64_t uws_res_get_remote_address_info(uws_res_t *res, const char **dest, int *port, bool *is_ipv6)
{
// This function is manual inlining + modification of
// us_socket_remote_address
// AsyncSocket::getRemoteAddress
- // To get { ip, port, is_ipv6 } for Bun.serve().requestIP()
// AsyncSocket::addressAsText
+ // To get { ip, port, is_ipv6 } for Bun.serve().requestIP()
static thread_local char b[64];
auto length = us_get_remote_address_info(b, (us_socket_t *)res, dest, port, (int*)is_ipv6);
+ if (length == 0) return 0;
if (length == 4) {
- length = sprintf(b, "%u.%u.%u.%u", b[0], b[1], b[2], b[3]);
- *is_ipv6 = false;
+ length = snprintf(b, 64, "%u.%u.%u.%u", b[0], b[1], b[2], b[3]);
+ *dest = b;
+ *is_ipv6 = false;
+ return length;
} else {
- length = sprintf(b, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
- b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11],
- b[12], b[13], b[14], b[15]);
- *is_ipv6 = true;
+ ares_inet_ntop(AF_INET6, b, &b[16], 64 - 16);
+ *dest = &b[16];
+ *is_ipv6 = true;
+ return strlen(*dest);
}
-
- *dest = b;
-
- return (unsigned int) length;
}
}