PySCTP - SCTP bindings for Python
Philippe Langlois P1 Security (http://www.p1sec.com) Phil __AT__ p1sec.com
PySCTP gives access to the SCTP transport protocol from Python language. It extends the traditional socket interface, allowing SCTP sockets to be used in most situations where a TCP or UDP socket would work, while preserving the unique characteristics of the protocol.
In a nutshell, PySCTP can be used as follows:
import socket import sctp
sk = sctpsocket_tcp(socket.AF_INET) sk.connect("10.0.1.1")
... most socket operations work for SCTP too ...
The autotest programs (test.py and test_server.py) are actually a good example of pysctp usage.
The BSD/Sockets SCTP extensions are defined by an IETF draft (draft-ietf-tsvwg-sctpsocket-10.txt) and PySCTP tries to map those extensions very closely. So, to really take the most advantage of SCTP and PySCTP, you must understand how the API works. You can find advice about it in the the draft itself (not incredibly easy to understand though), as well the 3rd edition of Unix Network Programming.
WARNING: the API of this module is not stable yet. We expect not to change it too much, but do not base any critical work on it yet :)
sudo python setup.py install
to see what this is going to install without actually doing it: python setup.py install --dry-run
to just build and not install: python setup.py build
- The "sctp" module
The "sctp" module is the Python side of the bindings. The docstrings of every class and method can give good advice of functions, but the highlights are:
sctpsocket is the root class for SCTP sockets, that ought not be used directly by the users. It does not inherit directly from Python standard socket; instead it contains a socket. That design was followed mostly because UDP-style sockets can be "peeled off" and return TCP-style sockets.
sctpsocket delegates unknown methods to the socket. This ensures that methods like close(), bind(), read(), select() etc. will work as expected. If the real socket is really needed, it can be obtained with sctpsocket.sock().
As said, "Normal" socket calls like open(), bind(), close() etc. can be used on SCTP sockets because they are delegated to the Python socket.
Users will normally use the sctpsocket_tcp (TCP style) and sctpsocket_udp (UDP style) classes. Some calls that are implemented in sctpsocket but do not make sense in a particular style are rendered invalid in each class (e.g. peeloff() in TCP-style sockets).
- The "_sctp" module
This is the C side of the bindings, that provides the "glue" between Python and the C API. The regular PySCTP user should not need to get into this, but power users and developers may be interested in it.
The interface between Python and C is designed to be as simple as possible. In particular, no object is created in C side, just simple types (strings, integers, lists, tuples and dictionaries).
The translation to/from complex objects is done entirely in Python. It avoids that _sctp depends on sctp.
NOTE: it all has been tested agains lksctp-utils 1.0.1 and kernel 2.6.10, that come with Ubuntu Hoary. Some newer calls like connectx() depend of testing on a newer environment to be implemented.
This module is licensed under the LGPL license.
Elvis Pfützenreuter <email@example.com> Casimiro Daniel NPRI <CasimiroD@npt.nuwc.navy.mil> - patch for new SCTP_* constants Philippe Langlois <Phil __AT__ p1sec.com> - patch for Mac OS X support, Python distutils packaging, GIT open repository