如何开始使用 Python SCTP 堆栈 (pysctp)?

发布于 2024-12-21 12:51:35 字数 1126 浏览 1 评论 0原文

我刚刚从 http://www.epx.com.br/pysctp/,并且我无法使基本示例正常工作。我可能做错了什么?

我使用的是红帽 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ぃ弥猫深巷。 2024-12-28 12:51:35

有人破坏了 ABI(向 struct sctp_event_subscribe 添加了更多字段,并且内核希望用户空间想要新的数量)。这是一个拼凑,正确的修复方法是让内核接受已针对具有较小 struct_event_subscribe 的标头进行编译的旧应用程序,而不是向它们提供新字段...)。或者甚至更新到 lksctp-devel 中的新样式标头并重新编译所有内容。

--- _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)) {

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)) {
×纯※雪 2024-12-28 12:51:35

看起来像是 pysctp 内部的错误。 get_events 调用 getsockopt

getsockopt(2) 说:

 EINVAL optlen 在setsockopt() 中无效。

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

getsockopt(2) says:

   EINVAL    optlen invalid in setsockopt().
岁月打碎记忆 2024-12-28 12:51:35

Brian 是对的 - 为 SCTP_EVENTS 调用 getsockopt 时出现了某种问题。我无法解决这个问题,但我在 sctp.py 中注释掉了这一行:

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

然后 SCTP 套接字似乎工作正常。我还不需要获取 SCTP_EVENTS,所以现在就可以了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文