SCTP Programmer's Guide

if (listen(fd, 1) < 0) {
perror("listen");
exit(1);
}
memset (&sri, 0, sizeof(sri));
printf ("{one-to-many}: Waiting for associations ...\n");
/* Wait for new associations */
while(1) {
/* Echo back any and all data */
memset (readbuf, 0, sizeof(readbuf));
len = sizeof (struct sockaddr_in);
sz = sctp_recvmsg (fd, readbuf, sizeof(readbuf),
&cli_addr, &len, &sri, &msg_flags);
if (debug)
printf ("sctp_recvmsg:[%d,e:%d,fl:%X]: ", sz, errno, msg_flags);
if (sz <= 0)
break;
if (msg_flags & MSG_NOTIFICATION) {
handle_event(readbuf);
continue;
}
printf ("<-- %s on str: %d\n", readbuf, sri.sinfo_stream);
sz = sctp_sendmsg (fd, readbuf, sz, &cli_addr, len,
sri.sinfo_ppid, sri.sinfo_flags,
sri.sinfo_stream, 0, 0);
if (debug)
printf ("sctp_sendmsg:[%d,e:%d]\n", sz, errno);
}
close(fd);
}
Sample Client Programs
This section lists the sample client programs for both one-to-one and one-to-many
associations.
This section addresses the following topics:
“One-to-One Client Program”
“One-to-Many Client Program” (page 82)
One-to-One Client Program
The following sample program is an implementation of an echo client over SCTP in a
one-to-one association:
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/sctp.h>
#include <sys/uio.h>
80 SCTP Sample Programs