diff --git a/Libraries/LibCore/System.h b/Libraries/LibCore/System.h index ed195985ba1..2de5b798c35 100644 --- a/Libraries/LibCore/System.h +++ b/Libraries/LibCore/System.h @@ -141,6 +141,7 @@ struct WaitPidResult { ErrorOr waitpid(pid_t waitee, int options = 0); ErrorOr fchown(int fd, uid_t, gid_t); ErrorOr uname(); +#endif class AddressInfoVector { AK_MAKE_NONCOPYABLE(AddressInfoVector); @@ -173,7 +174,6 @@ private: }; ErrorOr getaddrinfo(char const* nodename, char const* servname, struct addrinfo const& hints); -#endif unsigned hardware_concurrency(); u64 physical_memory_bytes(); diff --git a/Libraries/LibCore/SystemWindows.cpp b/Libraries/LibCore/SystemWindows.cpp index 991f1d31743..2de80381c9a 100644 --- a/Libraries/LibCore/SystemWindows.cpp +++ b/Libraries/LibCore/SystemWindows.cpp @@ -292,4 +292,35 @@ ErrorOr isatty(int handle) return GetFileType(to_handle(handle)) == FILE_TYPE_CHAR; } +ErrorOr socket(int domain, int type, int protocol) +{ + auto socket = ::socket(domain, type, protocol); + if (socket == INVALID_SOCKET) + return Error::from_windows_error(); + return socket; +} + +ErrorOr getaddrinfo(char const* nodename, char const* servname, struct addrinfo const& hints) +{ + struct addrinfo* results = nullptr; + + int rc = ::getaddrinfo(nodename, servname, &hints, &results); + if (rc != 0) + return Error::from_windows_error(rc); + + Vector addresses; + + for (auto* result = results; result != nullptr; result = result->ai_next) + TRY(addresses.try_append(*result)); + + return AddressInfoVector { move(addresses), results }; +} + +ErrorOr connect(int socket, struct sockaddr const* address, socklen_t address_length) +{ + if (::connect(socket, address, address_length) == SOCKET_ERROR) + return Error::from_windows_error(); + return {}; +} + }