Skip to content

Commit f164658

Browse files
authored
wasip2: Some miscellaenous network-related changes (WebAssembly#678)
These were derived from getting Python's sockets-related test suite passing with wasi-libc. Some new functions are added here, some error codes are adjusted, and some aborts were changed since they're possible to trip.
1 parent 582fc24 commit f164658

File tree

8 files changed

+32
-13
lines changed

8 files changed

+32
-13
lines changed

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,16 @@ LIBC_TOP_HALF_MUSL_SOURCES = \
170170
errno/strerror.c \
171171
network/htonl.c \
172172
network/htons.c \
173-
network/ntohl.c \
174-
network/ntohs.c \
175-
network/inet_ntop.c \
176-
network/inet_pton.c \
177-
network/inet_aton.c \
178173
network/in6addr_any.c \
179174
network/in6addr_loopback.c \
175+
network/inet_addr.c \
176+
network/inet_aton.c \
177+
network/inet_legacy.c \
178+
network/inet_ntoa.c \
179+
network/inet_ntop.c \
180+
network/inet_pton.c \
181+
network/ntohl.c \
182+
network/ntohs.c \
180183
fenv/fenv.c \
181184
fenv/fesetround.c \
182185
fenv/feupdateenv.c \

expected/wasm32-wasip1-threads/defined-symbols.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,13 @@ imaxdiv
792792
in6addr_any
793793
in6addr_loopback
794794
index
795+
inet_addr
795796
inet_aton
797+
inet_lnaof
798+
inet_makeaddr
799+
inet_netof
800+
inet_network
801+
inet_ntoa
796802
inet_ntop
797803
inet_pton
798804
initstate

expected/wasm32-wasip1/defined-symbols.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,13 @@ imaxdiv
757757
in6addr_any
758758
in6addr_loopback
759759
index
760+
inet_addr
760761
inet_aton
762+
inet_lnaof
763+
inet_makeaddr
764+
inet_netof
765+
inet_network
766+
inet_ntoa
761767
inet_ntop
762768
inet_pton
763769
initstate

expected/wasm32-wasip2/defined-symbols.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,13 @@ imaxdiv
817817
in6addr_any
818818
in6addr_loopback
819819
index
820+
inet_addr
820821
inet_aton
822+
inet_lnaof
823+
inet_makeaddr
824+
inet_netof
825+
inet_network
826+
inet_ntoa
821827
inet_ntop
822828
inet_pton
823829
initstate

libc-bottom-half/sources/getsockpeername.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int getsockname(int socket, struct sockaddr *__restrict addr,
99
if (!entry)
1010
return -1;
1111
if (!entry->vtable->getsockname) {
12-
errno = EOPNOTSUPP;
12+
errno = ENOTSOCK;
1313
return -1;
1414
}
1515
return entry->vtable->getsockname(entry->data, addr, addrlen);
@@ -22,7 +22,7 @@ int getpeername(int socket, struct sockaddr *__restrict addr,
2222
if (!entry)
2323
return -1;
2424
if (!entry->vtable->getpeername) {
25-
errno = EOPNOTSUPP;
25+
errno = ENOTSOCK;
2626
return -1;
2727
}
2828
return entry->vtable->getpeername(entry->data, addr, addrlen);

libc-bottom-half/sources/netdb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
256256
socklen_t servlen, int flags)
257257
{
258258
// TODO wasi-sockets
259-
abort();
259+
errno = EOPNOTSUPP;
260+
return EAI_SYSTEM;
260261
}
261262

262263
struct hostent *gethostbyname(const char *name)

libc-bottom-half/sources/wasip2_tcp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ static int tcp_listen(void *data, int backlog) {
476476
}
477477

478478
if (!tcp_method_tcp_socket_set_listen_backlog_size(socket_borrow, backlog, &error)) {
479-
abort(); // Our own state checks should've prevented this from happening.
479+
errno = __wasi_sockets_utils__map_error(error);
480+
return -1;
480481
}
481482

482483
if (socket->state.tag == TCP_SOCKET_STATE_LISTENING) {

libc-top-half/musl/include/arpa/inet.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@ uint16_t htons(uint16_t);
1313
uint32_t ntohl(uint32_t);
1414
uint16_t ntohs(uint16_t);
1515

16-
#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */
1716
in_addr_t inet_addr (const char *);
1817
in_addr_t inet_network (const char *);
1918
char *inet_ntoa (struct in_addr);
20-
#endif
2119
int inet_pton (int, const char *__restrict, void *__restrict);
2220
const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t);
2321

2422
int inet_aton (const char *, struct in_addr *);
25-
#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */
2623
struct in_addr inet_makeaddr(in_addr_t, in_addr_t);
2724
in_addr_t inet_lnaof(struct in_addr);
2825
in_addr_t inet_netof(struct in_addr);
29-
#endif
3026

3127
#ifdef __cplusplus
3228
}

0 commit comments

Comments
 (0)