diff --git a/Misc/NEWS.d/next/Library/2026-09-14-15-20-29.gh-issue-157497.xnwAxk.rst b/Misc/NEWS.d/next/Library/2026-09-14-15-20-29.gh-issue-157497.xnwAxk.rst new file mode 100644 index 00000000000000..6d2fd28d747653 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-09-14-15-20-29.gh-issue-157497.xnwAxk.rst @@ -0,0 +1 @@ +:func:`socket.gethostbyaddr` now works with IPv6 addresses on Solaris. diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 61505c2603f22c..0b7ee151d9c1b4 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -6404,6 +6404,20 @@ _socket_gethostbyaddr(PyObject *module, PyObject *hobj) PyErr_SetString(PyExc_OSError, "unsupported address family"); goto finally; } +#if defined(__sun) && defined(ENABLE_IPV6) + /* Solaris gethostbyaddr supports AF_INET only; use platform + specific and AF_INET6 capable getipnodebyaddr instead. */ + if (af == AF_INET6) { + Py_BEGIN_ALLOW_THREADS + h = getipnodebyaddr(ap, al, af, &h_error); + Py_END_ALLOW_THREADS + ret = gethost_common(state, h, SAS2SA(&addr), sizeof(addr), af, h_error); + if (h != NULL) { + freehostent(h); + } + goto finally; + } +#endif Py_BEGIN_ALLOW_THREADS #ifdef HAVE_GETHOSTBYNAME_R #if defined(HAVE_GETHOSTBYNAME_R_6_ARG)