inet.cpp 395 B

12345678910111213141516171819
  1. #include <arpa/inet.h>
  2. #include <stdio.h>
  3. #include <errno.h>
  4. extern "C" {
  5. const char* inet_ntop(int af, const void* src, char* dst, socklen_t len)
  6. {
  7. if (af != AF_INET) {
  8. errno = EAFNOSUPPORT;
  9. return nullptr;
  10. }
  11. auto* bytes = (const unsigned char*)src;
  12. snprintf(dst, len, "%u.%u.%u.%u", bytes[3], bytes[2], bytes[1], bytes[0]);
  13. return (const char*)dst;
  14. }
  15. }