2

I've just installed pysctp from http://www.epx.com.br/pysctp/, and I'm having trouble getting the basic example working. What could I be doing wrong?

I'm on Red Hat Linux.

Python 2.7.2 (default, Oct 25 2011, 10:11:43)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> import sctp
>>> sk = sctp.sctpsocket_tcp(socket.AF_INET)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python2.7/lib/python2.7/site-packages/sctp.py", line 1644, in __init__
    sctpsocket.__init__(self, family, TCP_STYLE, sk)
  File "/usr/local/python2.7/lib/python2.7/site-packages/sctp.py", line 1016, in __init__
    self.events = event_subscribe(self)
  File "/usr/local/python2.7/lib/python2.7/site-packages/sctp.py", line 623, in __init__
    self.__dict__.update(self.container._get_events())
  File "/usr/local/python2.7/lib/python2.7/site-packages/sctp.py", line 1356, in _get_events
    return _sctp.get_events(self._sk.fileno())
IOError: [Errno 22] Invalid argument
thomson_matt
  • 7,473
  • 3
  • 39
  • 47

3 Answers3

2

Someone broke the ABI (added a few more fields to struct sctp_event_subscribe and the kernel wants userspace to want the new amount). Here's a kludge, proper fix would be for the kernel to accept old apps that have been compiled against headers with a smaller struct_event_subscribe and just not give them the new fields...). Or even updating to the new-style header in lksctp-devel and recompiling everything.

--- _sctp.c~    2011-12-20 16:48:45.000000000 +0200
+++ _sctp.c 2011-12-20 16:49:23.498912252 +0200
@@ -832,8 +832,9 @@
 {
    PyObject* ret = 0;
    int fd;
+   char padding[4]; // Happily overflowing here...
    struct sctp_event_subscribe v;
-   socklen_t lv = sizeof(v);
+   socklen_t lv = 10; // Come to think of it, it could have been 9 at some point

    if (PyArg_ParseTuple(args, "i", &fd)) {
        if (getsockopt(fd, SOL_SCTP, SCTP_EVENTS, &v, &lv)) {
1

Looks like a bug internal to pysctp. get_events calls getsockopt.

getsockopt(2) says:

   EINVAL    optlen invalid in setsockopt().
Brian Cain
  • 14,403
  • 3
  • 50
  • 88
1

Brian's right - there's some sort of issue calling getsockopt for SCTP_EVENTS. I've not been able to solve that, but I've commented out this line in sctp.py:

self.__dict__.update(self.container._get_events())

The SCTP sockets then seem to work fine. I've not yet needed to get the SCTP_EVENTS, so this is fine for now.

thomson_matt
  • 7,473
  • 3
  • 39
  • 47