Sample SCTP code for Linux

In this post I will explain how to compile SCTP sample code on Linux with socket interface and with ACE.

First of all, make sure you have installed kernel module which adds support for SCTP:
I have been using

lksctp-tools-1.0.2

To install it, download it from online package repository and use rpm (rpm -i …).

Compiling the C test

You can use the following samples for SCTP client and SCTP server applications or read the wonderful article which includes similar code “Better networking with SCTP” from IBM.

Now, compile the sources with

g++ sctpclnt.cpp -L/usr/local/lib -lsctp -o sctp_client
g++ sctpserv.cpp -L/usr/local/lib -lsctp -o sctp_server

After running it you may get the error with errno 94 and description
Socket type not supported“.
This happens because sctp module is not enabled for linux kernel.
You can fix it by using the following shell command:

modprobe sctp

You do not need to recompile, just run the binaries and it should work fine.

Using ACE

ACE has SCTP performance test code which you can use as a starting point for your SCTP applications.

In order to run these tests you must make sure that ACE library is built with SCTP support.
One way to enable SCTP for ACE is described.

This way you can modify “platform_linux.GNU” which is under include/makeinclude/ of your ACE distribution directory. Unfortunately this never worked for me so I had to manually include
flags when buildilng ACE:

./configure CXXFLAGS="-DACE_HAS_LKSCTP" LDFLAGS="-L/usr/local/lib -lsctp"

This ensures that ACE_HAS_LKSCTP symbol is defined and linker knows where to get the SCTP library.

Now, when ACE library is built successfully, you get the “libACE.so”, place it into /usr/local/lib and run “ldconfig” to set run time bindings.

When building ACE SCTP performance test, you may notice it prints the following error message:

"SCTP was NOT installed when this binary was compiled."

The problem is that ACE test code is looking for ACE_HAS_SCTP symbol while ACE library is checking ACE_HAS_LKSCTP. For the ACE SCTP performance tests make sure ACE_HAS_SCTP is defined.

After rebuilding ACE code should work fine, given that sctp module is enabled as shown above.

Leave a Reply