Browse Source

python: Patch in a working getprotobyname()

See #2387.
android-5
Fredrik Fornwall 7 years ago
parent
commit
c78b7f43af
  1. 78
      packages/python/Modules-socketmodule.c.patch
  2. 2
      packages/python/build.sh

78
packages/python/Modules-socketmodule.c.patch

@ -0,0 +1,78 @@
diff -u -r ../Python-3.6.5/Modules/socketmodule.c ./Modules/socketmodule.c
--- ../Python-3.6.5/Modules/socketmodule.c 2018-03-28 11:19:31.000000000 +0200
+++ ./Modules/socketmodule.c 2018-06-08 03:28:51.003730525 +0200
@@ -5373,17 +5373,74 @@
This only returns the protocol number, since the other info is
already known or not useful (like the list of aliases). */
+#ifdef __ANDROID__
+struct protocol_name_and_number {
+ char* name;
+ int number;
+};
+#endif
+
/*ARGSUSED*/
static PyObject *
socket_getprotobyname(PyObject *self, PyObject *args)
{
+#ifdef __ANDROID__
+ /* http://git.musl-libc.org/cgit/musl/tree/src/network/proto.c */
+ static const struct protocol_name_and_number protocols[] = {
+ {"ip", 0},
+ {"icmp", 1},
+ {"igmp", 2},
+ {"ggp", 3},
+ {"ipencap", 4},
+ {"st", 5},
+ {"tcp", 6},
+ {"egp", 8},
+ {"pup", 12},
+ {"udp", 17},
+ {"hmp", 20},
+ {"xns-idp", 22},
+ {"iso-tp4", 29},
+ {"xtp", 36},
+ {"ddp", 37},
+ {"idpr-cmtp", 38},
+ {"ipv6", 41},
+ {"ipv6-route", 43},
+ {"ipv6-frag", 44},
+ {"idrp", 45},
+ {"rsvp", 46},
+ {"gre", 47},
+ {"esp", 50},
+ {"ah", 51},
+ {"skip", 57},
+ {"ipv6-icmp", 58},
+ {"ipv6-nonxt", 59},
+ {"ipv6-opts", 60},
+ {"rspf", 73},
+ {"vmtp", 81},
+ {"ospf", 89},
+ {"ipip", 94},
+ {"encap", 98},
+ {"pim", 103},
+ {"raw", 255}
+ };
+ int i;
+#endif
const char *name;
struct protoent *sp;
if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
return NULL;
+#ifdef __ANDROID__
+ for (i = 0; i < sizeof(protocols) / sizeof(protocols[0]); i++) {
+ if (strcmp(protocols[i].name, name) == 0) {
+ return PyLong_FromLong((long) protocols[i].number);
+ }
+ }
+ sp = NULL;
+#else
Py_BEGIN_ALLOW_THREADS
sp = getprotobyname(name);
Py_END_ALLOW_THREADS
+#endif
if (sp == NULL) {
PyErr_SetString(PyExc_OSError, "protocol not found");
return NULL;

2
packages/python/build.sh

@ -3,7 +3,7 @@ TERMUX_PKG_DESCRIPTION="Python 3 programming language intended to enable clear p
TERMUX_PKG_DEPENDS="libandroid-support, ncurses, readline, libffi, openssl, libutil, libbz2, libsqlite, gdbm, ncurses-ui-libs, libcrypt, liblzma"
_MAJOR_VERSION=3.6
TERMUX_PKG_VERSION=${_MAJOR_VERSION}.5
TERMUX_PKG_REVISION=2
TERMUX_PKG_REVISION=3
TERMUX_PKG_SHA256=f434053ba1b5c8a5cc597e966ead3c5143012af827fd3f0697d21450bb8d87a6
TERMUX_PKG_SRCURL=https://www.python.org/ftp/python/${TERMUX_PKG_VERSION}/Python-${TERMUX_PKG_VERSION}.tar.xz

Loading…
Cancel
Save