From 0669e41867f06b6eef8d17e596261e3c6b4edebe Mon Sep 17 00:00:00 2001 From: Packit Service Date: Dec 10 2020 02:37:29 +0000 Subject: Apply patch Socket-2.029-inet_aton-Use-getaddrinfo-if-possible.patch patch_name: Socket-2.029-inet_aton-Use-getaddrinfo-if-possible.patch present_in_specfile: true --- diff --git a/Socket.xs b/Socket.xs index b11ea75..cceead3 100644 --- a/Socket.xs +++ b/Socket.xs @@ -745,20 +745,34 @@ inet_aton(host) char * host CODE: { +#ifdef HAS_GETADDRINFO + struct addrinfo *res; + struct addrinfo hints = {0,}; + hints.ai_family = AF_INET; + if (!getaddrinfo(host, NULL, &hints, &res)) { + ST(0) = sv_2mortal(newSVpvn( + (char *)&(((struct sockaddr_in *)res->ai_addr)->sin_addr.s_addr), + 4 + )); + freeaddrinfo(res); + XSRETURN(1); + } +#else struct in_addr ip_address; struct hostent * phe; - if ((*host != '\0') && inet_aton(host, &ip_address)) { ST(0) = sv_2mortal(newSVpvn((char *)&ip_address, sizeof(ip_address))); XSRETURN(1); } #ifdef HAS_GETHOSTBYNAME + /* gethostbyname is not thread-safe */ phe = gethostbyname(host); if (phe && phe->h_addrtype == AF_INET && phe->h_length == 4) { ST(0) = sv_2mortal(newSVpvn((char *)phe->h_addr, phe->h_length)); XSRETURN(1); } #endif +#endif XSRETURN_UNDEF; }