summaryrefslogtreecommitdiff
path: root/src/libc/net
diff options
context:
space:
mode:
authordzwdz2024-02-20 20:09:06 +0100
committerdzwdz2024-02-20 20:09:06 +0100
commit7f6686177af7279fb9465df25b2c1295ce1aeaa2 (patch)
tree0d98eaa36de4997c937454649d907e450f837968 /src/libc/net
parent4be1fd62131f7e186e6f92f1bb5a356dc1ac1951 (diff)
libc: better curl compat
I can now actually curl an entire page :^)
Diffstat (limited to 'src/libc/net')
-rw-r--r--src/libc/net/socket.c21
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;
}