From 7f6686177af7279fb9465df25b2c1295ce1aeaa2 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 20 Feb 2024 20:09:06 +0100 Subject: libc: better curl compat I can now actually curl an entire page :^) --- src/libc/net/socket.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/libc/net') diff --git a/src/libc/net/socket.c b/src/libc/net/socket.c index 9eacbe5..04d73f4 100644 --- a/src/libc/net/socket.c +++ b/src/libc/net/socket.c @@ -5,6 +5,7 @@ #include #include #include +#include #include int socket(int domain, int type, int protocol) { @@ -83,9 +84,21 @@ int setsockopt(int, int, int, const void *, socklen_t) { } int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen) { - // TODO /net/ should expose local address somehow - /* dummy output, just to satisfy curl */ - (void)sockfd; (void)addrlen; - addr->sa_family = AF_UNSPEC; + // TODO /net/ should expose the local address somehow + + /* Outputs a fake address, just to satisfy curl. + * Can't be AF_UNSPEC, as curl tries to print it with inet_ntop. */ + (void)sockfd; + struct sockaddr_in dummy = { + .sin_family = AF_INET, + .sin_port = 0, + .sin_addr = {0}, + }; + if ((int)sizeof(dummy) < *addrlen) { + *addrlen = sizeof(dummy); + } else if (*addrlen < 0) { + return errno = EINVAL, -1; + } + memcpy(addr, &dummy, *addrlen); return 0; } -- cgit v1.2.3