summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-08-17 16:19:27 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-08-17 16:19:27 +0200
commit2135b66f45d7d92e32413bec426e9907d04f0fc1 (patch)
treea67d85fd504c84583739c2594109de6854e728cd
parent44b44d3691882d1a09b388ee7405467d17c14492 (diff)
Changed getsockname to allow handling of pipe fd
-rw-r--r--expected/wasm32-wasi/predefined-macros.txt1
-rw-r--r--expected/wasm64-wasi/predefined-macros.txt1
-rw-r--r--libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockname.c6
-rw-r--r--libc-bottom-half/headers/public/__header_sys_socket.h1
4 files changed, 9 insertions, 0 deletions
diff --git a/expected/wasm32-wasi/predefined-macros.txt b/expected/wasm32-wasi/predefined-macros.txt
index d6642ac..effb2d0 100644
--- a/expected/wasm32-wasi/predefined-macros.txt
+++ b/expected/wasm32-wasi/predefined-macros.txt
@@ -35,6 +35,7 @@
#define ADJ_TIMECONST 0x0020
#define AF_INET __WASI_ADDRESS_FAMILY_INET4
#define AF_INET6 __WASI_ADDRESS_FAMILY_INET6
+#define AF_LOCAL AF_UNIX
#define AF_UNIX __WASI_ADDRESS_FAMILY_UNIX
#define AF_UNSPEC __WASI_ADDRESS_FAMILY_UNSPEC
#define AI_ADDRCONFIG 0x20
diff --git a/expected/wasm64-wasi/predefined-macros.txt b/expected/wasm64-wasi/predefined-macros.txt
index 70b8f07..d1db3c9 100644
--- a/expected/wasm64-wasi/predefined-macros.txt
+++ b/expected/wasm64-wasi/predefined-macros.txt
@@ -35,6 +35,7 @@
#define ADJ_TIMECONST 0x0020
#define AF_INET __WASI_ADDRESS_FAMILY_INET4
#define AF_INET6 __WASI_ADDRESS_FAMILY_INET6
+#define AF_LOCAL AF_UNIX
#define AF_UNIX __WASI_ADDRESS_FAMILY_UNIX
#define AF_UNSPEC __WASI_ADDRESS_FAMILY_UNSPEC
#define AI_ADDRCONFIG 0x20
diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockname.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockname.c
index 29b3d96..fbe3429 100644
--- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockname.c
+++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockname.c
@@ -10,6 +10,12 @@
int getsockname(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) {
__wasi_addr_port_t local_addr;
__wasi_errno_t error = __wasi_sock_addr_peer(socket, &local_addr);
+ if (error == ENOTSOCK) {
+ // in that case, return a AF_LOCAL type constant
+ *addrlen = sizeof(addr->sa_family);
+ addr->sa_family = AF_LOCAL;
+ return 0;
+ }
if (error != 0) {
errno = error;
return -1;
diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h
index 92c7dc3..f145197 100644
--- a/libc-bottom-half/headers/public/__header_sys_socket.h
+++ b/libc-bottom-half/headers/public/__header_sys_socket.h
@@ -119,6 +119,7 @@
#define AF_INET __WASI_ADDRESS_FAMILY_INET4
#define AF_INET6 __WASI_ADDRESS_FAMILY_INET6
#define AF_UNIX __WASI_ADDRESS_FAMILY_UNIX
+#define AF_LOCAL AF_UNIX
#define PF_UNSPEC AF_UNSPEC
#define PF_INET AF_INET