#include #include #include #include #include #include /* Build: gcc -lrt -lsctp bindx.test.c -o bindxtest */ int main(int argc, char* argv[]) { int rc; int len; int out; int val = 32 * 1024; struct sockaddr_storage client_addr; struct sockaddr_in6 addrs[2]; struct sctp_paddrparams params; out = socket(AF_INET6, SOCK_SEQPACKET, IPPROTO_SCTP); if (out == -1) { printf("socket failed, out=%d, errno=%d, %s\n", out, errno, strerror(errno)); exit(-1); } printf("socket = %d\n",out); rc = setsockopt(out, SOL_SOCKET, SO_SNDBUF, &val, sizeof(val)); if (rc < 0) { printf("setsockopt SNDBUF failed rc=%d, %s\n", rc, strerror(errno)); exit(-1); } rc = setsockopt(out, SOL_SOCKET, SO_RCVBUF, &val, sizeof(val)); if (rc < 0) { printf("setsockopt RCVBUF failed rc=%d, %s\n", rc, strerror(errno)); exit(-1); } memset((void *)&addrs, 0, sizeof(addrs)); if (inet_pton(AF_INET6, "::ffff:192.168.1.168", &addrs[0].sin6_addr) < 0) printf("inet_pton(0) failed\n"); addrs[0].sin6_family = AF_INET6; addrs[0].sin6_port = htons(5060); if (inet_pton(AF_INET6, "::ffff:192.168.3.168", &addrs[1].sin6_addr) < 0) printf("inet_pton(1) failed\n"); addrs[1].sin6_family = AF_INET6; addrs[1].sin6_port = htons(5060); //printf("sctp_bindx(SCTP_BINDX_ADD_ADDR)\n"); rc = sctp_bindx(out, (struct sockaddr*)&addrs[0], 1, SCTP_BINDX_ADD_ADDR); if (rc < 0) { printf("sctp_bindx failed rc=%d, %s\n", rc, strerror(errno)); exit(-1); } rc = listen(out,2); if (rc < 0) { printf("listen failed rc=%d, %s\n", rc, strerror(errno)); exit(-1); } len = sizeof(client_addr); if (getsockname(out, (struct sockaddr *)&client_addr, &len) < 0) { printf("getsockname(%d) failed: %s\n", out, strerror(errno)); exit(-1); } system("cat /proc/net/sctp/eps"); //printf("sctp_bindx(SCTP_BINDX_ADD_ADDR)\n"); rc = sctp_bindx(out, (struct sockaddr *)&addrs[1], 1, SCTP_BINDX_ADD_ADDR); if (rc == -1) { printf("bind-1 failed, rc=%d, errno=%d, %s\n", rc, errno, strerror(errno)); exit(-1); } system("cat /proc/net/sctp/eps"); //printf("sctp_bindx(SCTP_BINDX_REM_ADDR)\n"); rc = sctp_bindx(out, (struct sockaddr *)&addrs[1], 1, SCTP_BINDX_REM_ADDR); if (rc == -1) { printf("bind-2 failed, rc=%d, errno=%d, %s\n", rc, errno, strerror(errno)); exit(-1); } system("cat /proc/net/sctp/eps"); exit(0); }