diff -r 3a57eafd8401 Modules/socketmodule.c --- a/Modules/socketmodule.c Tue May 24 09:15:14 2016 +0300 +++ b/Modules/socketmodule.c Wed May 25 10:59:49 2016 +0200 @@ -366,6 +366,34 @@ #endif +#if defined(__ANDROID__) && __ANDROID_API__ < 23 +#define GETSERVBYNAME(sp, name, proto) \ + do { \ + if ((sp=getservbyname((name), (proto))) == NULL && \ + (proto) == NULL) { \ + if ((sp=getservbyname((name), "tcp")) == NULL) \ + sp = getservbyname((name), "udp"); \ + } \ + } while (0) +#else +#define GETSERVBYNAME(sp, name, proto) sp = getservbyname((name), (proto)) +#endif + +#ifdef __ANDROID__ +#define GETSERVBYPORT(sp, port, proto) \ + do { \ + int nport = htons((short)(port)); \ + if ((sp=getservbyport(nport, (proto))) == NULL && \ + (proto) == NULL) { \ + if ((sp=getservbyport(nport, "tcp")) == NULL) \ + sp = getservbyport(nport, "udp"); \ + } \ + } while (0) +#else +#define GETSERVBYPORT(sp, port, proto) \ + sp = getservbyport(htons((short)(port)), (proto)) +#endif + /* I know this is a bad practice, but it is the easiest... */ #if !defined(HAVE_GETADDRINFO) /* avoid clashes with the C library definition of the symbol. */ @@ -4912,7 +4940,7 @@ if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto)) return NULL; Py_BEGIN_ALLOW_THREADS - sp = getservbyname(name, proto); + GETSERVBYNAME(sp, name, proto); Py_END_ALLOW_THREADS if (sp == NULL) { PyErr_SetString(PyExc_OSError, "service/proto not found"); @@ -4949,7 +4977,7 @@ return NULL; } Py_BEGIN_ALLOW_THREADS - sp = getservbyport(htons((short)port), proto); + GETSERVBYPORT(sp, port, proto); Py_END_ALLOW_THREADS if (sp == NULL) { PyErr_SetString(PyExc_OSError, "port/proto not found");