#include #include #include #include #include #include #include #include #include int main() { int sock, client, pkgsize, realpkgsize, i; uint8_t *pkg; struct addrinfo *res; static const struct addrinfo hints_ipv6 = { .ai_family = AF_INET, .ai_socktype = SOCK_SEQPACKET, .ai_flags = AI_PASSIVE }; static const struct sctp_initmsg initparams = { .sinit_max_instreams = 5, .sinit_num_ostreams = 5, }; static const struct sctp_event_subscribe subscribe = { .sctp_data_io_event = 1 }; static const int on = 1; if ( getaddrinfo(NULL, "2811", &hints_ipv6, &res) < 0 ) { perror("getaddrinfo"); return -1; } if ( (sock = socket(res->ai_family, SOCK_STREAM, IPPROTO_SCTP)) < 0 ) { perror("socket"); return -1; } if (setsockopt(sock, SOL_SCTP, SCTP_EVENTS, &subscribe, sizeof(subscribe)) < 0) { perror("setsockopt(SCTP_EVENTS)"); return -1; } if (setsockopt(sock, SOL_SCTP, SCTP_INITMSG, &initparams, sizeof(initparams)) < 0) { perror("setsockopt(SCTP_INITMSG)"); return -1; } if ( setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0 ) { perror("setsockopt(SO_REUSEADDR)"); return -1; } if ( bind(sock, res->ai_addr, res->ai_addrlen) < 0 ) { perror("bind"); return -1; } if ( listen(sock, 1) < 0 ) { perror("listen"); return -1; } if ( (client = accept(sock, NULL, NULL)) < 0 ) { perror("accept"); return -1; } sleep(10); if ( ioctl(client, SIOCINQ, &pkgsize) < 0 ) { perror("ioctl"); return -1; } fprintf(stderr, "Expecting packet of size %d\n", pkgsize); pkg = malloc(pkgsize*2); realpkgsize = sctp_recvmsg(client, pkg, pkgsize*2, NULL, 0, NULL, NULL); fprintf(stderr, "Received packet of size %d\n", realpkgsize); for(i = 0; i < realpkgsize; i++) fprintf(stderr, "%02x ", pkg[i]); fprintf(stderr, "\n"); close(client); close(sock); return 0; }