0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-11-21 22:06:17 +00:00
termux-packages/disabled-packages/python3.11/0004-impl-getprotobyname.patch

78 lines
1.9 KiB
Diff

--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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;