Enhance sock_addr_local syscall (#1320)

Slightly change the __wasi_sock_addr_local interface - since we already have
a `__wasi_addr_t` structure which is an union, there's no need for passing the
length around - the address buffer will always have the right length (i.e. max
of all address families).
This commit is contained in:
Marcin Kolny
2022-08-01 09:15:33 +02:00
committed by GitHub
parent 08fd714551
commit 3e77b053c3
11 changed files with 195 additions and 40 deletions

View File

@ -19,7 +19,10 @@ main(int argc, char *argv[])
{
int socket_fd, ret, total_size = 0;
char buffer[1024] = { 0 };
char ip_string[16] = { 0 };
struct sockaddr_in server_address = { 0 };
struct sockaddr_in local_address = { 0 };
socklen_t len;
printf("[Client] Create socket\n");
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
@ -42,6 +45,20 @@ main(int argc, char *argv[])
return EXIT_FAILURE;
}
len = sizeof(local_address);
ret = getsockname(socket_fd, (struct sockaddr *)&local_address, &len);
if (ret == -1) {
perror("Failed to retrieve socket address");
close(socket_fd);
return EXIT_FAILURE;
}
inet_ntop(AF_INET, &local_address.sin_addr, ip_string,
sizeof(ip_string) / sizeof(ip_string[0]));
printf("[Client] Local address is: %s:%d\n", ip_string,
ntohs(local_address.sin_port));
printf("[Client] Client receive\n");
while (1) {
ret = recv(socket_fd, buffer + total_size, sizeof(buffer) - total_size,