diff options
Diffstat (limited to 'src/libc/net')
-rw-r--r-- | src/libc/net/socket.c | 21 |
1 files changed, 17 insertions, 4 deletions
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 <netdb.h> #include <netinet/in.h> #include <stdio.h> +#include <string.h> #include <sys/socket.h> 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; } |