MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / TrySetUpIPV6Socket

Function TrySetUpIPV6Socket

test/host/socket/wasi_socket.cpp:34–72  ·  view source on GitHub ↗

XXX: Set up a socket with address ::1 to test if IPv6 is available. It prevents system calls like sysctl net.ipv6.conf.all.disable_ipv6. However, the port used in TEST cannot be the same as TrySetUpIPV6Socket because it does not set up SO_REUSEADDR=1 and may cause the test to fail.

Source from the content-addressed store, hash-verified

32// TrySetUpIPV6Socket because it does not set up SO_REUSEADDR=1 and may
33// cause the test to fail.
34bool TrySetUpIPV6Socket() {
35 bool State = false;
36
37#if WASMEDGE_OS_WINDOWS
38 WSADATA_ WSAData;
39 WSAStartup(0x0202, &WSAData);
40 const SOCKET_ ErrFd = INVALID_SOCKET_;
41 SOCKET_ Fd;
42#else
43 const int ErrFd = -1;
44 int Fd;
45#endif
46
47 do {
48 Fd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_IP);
49 if (Fd == ErrFd)
50 break;
51
52 struct sockaddr_in6 Sock6;
53 std::memset(&Sock6, 0, sizeof(Sock6));
54 Sock6.sin6_family = AF_INET6;
55 Sock6.sin6_port = htons(10000);
56 Sock6.sin6_addr = in6addr_loopback;
57
58 if (bind(Fd, reinterpret_cast<sockaddr *>(&Sock6), sizeof(Sock6)) < 0)
59 break;
60
61 State = true;
62 } while (false);
63
64#if WASMEDGE_OS_WINDOWS
65 closesocket(Fd);
66 WSACleanup();
67#else
68 close(Fd);
69#endif
70
71 return State;
72}
73
74bool TestIPv6Enabled() {
75 static bool Resolved = false;

Callers 1

TestIPv6EnabledFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIPv6EnabledFunction · 0.68