3 socket.setsockopt sometimes raise Invalid argument error, because of differences
4 between Linux and Solaris in socket layer. The reason is that the third argument
5 length is different for the following socket options:
10 An integer is expected on Linux, single byte on Solaris. While this should be
11 handled in the application code (with pack), we decided to patch this in runtime
12 rather than in our application code (because upstream is generally aware of this).
14 See the bug for more information.
16 --- Python-3.7.5/Modules/socketmodule.c
17 +++ Python-3.7.5/Modules/socketmodule.c
18 @@ -2776,6 +2776,7 @@ sock_setsockopt(PySocketSockObject *s, P
26 @@ -2798,8 +2799,15 @@ sock_setsockopt(PySocketSockObject *s, P
27 /* setsockopt(level, opt, flag) */
28 if (PyArg_ParseTuple(args, "iii:setsockopt",
29 &level, &optname, &flag)) {
31 + buflen = sizeof flag;
32 + /* Multi cast options take shorter arguments */
33 + if (optname == IP_MULTICAST_TTL
34 + || optname == IP_MULTICAST_LOOP)
35 + buflen = sizeof(u_char);
37 res = setsockopt(s->sock_fd, level, optname,
38 - (char*)&flag, sizeof flag);
39 + (char*)&flag, buflen);