diff -r 54087e63280a Modules/socketmodule.c --- a/Modules/socketmodule.c Sat Nov 05 02:49:20 2016 +0000 +++ b/Modules/socketmodule.c Sat Nov 05 12:25:27 2016 +0100 @@ -5726,6 +5726,9 @@ { Py_buffer packed_ip; struct in_addr packed_addr; +#ifdef HAVE_INET_PTON + char result[INET_ADDRSTRLEN]; +#endif if (!PyArg_ParseTuple(args, "y*:inet_ntoa", &packed_ip)) { return NULL; @@ -5741,7 +5744,12 @@ memcpy(&packed_addr, packed_ip.buf, packed_ip.len); PyBuffer_Release(&packed_ip); +#ifdef HAVE_INET_PTON + inet_ntop(AF_INET, &packed_addr, result, sizeof(result)); + return PyUnicode_FromString(result); +#else return PyUnicode_FromString(inet_ntoa(packed_addr)); +#endif } #if defined(HAVE_INET_PTON) || defined(MS_WINDOWS)