diff --git a/libc/arpa/inet.cpp b/libc/arpa/inet.cpp index e81ef38566..a7beed2592 100644 --- a/libc/arpa/inet.cpp +++ b/libc/arpa/inet.cpp @@ -50,3 +50,26 @@ char* inet_ntoa(struct in_addr in) ); return buffer; } + +const char* inet_ntop(int af, const void* __restrict src, char* __restrict dst, socklen_t size) +{ + if (af == AF_INET) + { + if (size < INET_ADDRSTRLEN) + { + errno = ENOSPC; + return nullptr; + } + uint32_t he = ntohl(reinterpret_cast(src)->s_addr); + sprintf(dst, "%u.%u.%u.%u", + (he >> 24) & 0xFF, + (he >> 16) & 0xFF, + (he >> 8) & 0xFF, + (he >> 0) & 0xFF + ); + return dst; + } + + errno = EAFNOSUPPORT; + return nullptr; +}