SCTP Programmer's Guide
A SCTP Sample Programs
This appendix lists the sample programs for a client and server, in both one-to-one and
one-to-many associations.
Sample Server Programs
This section lists the sample server programs in one-to-one and one-to-many
associations.
This section addresses the following topics:
• “One-to-One Server Program”
• “One-to-Many Server Program” (page 77)
One-to-One Server Program
The following sample program is an implementation of an echo server 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>
#define BUFLEN 100
int debug=0;
static void
handle_event(void *buf)
{
struct sctp_assoc_change *sac;
struct sctp_send_failed *ssf;
struct sctp_paddr_change *spc;
struct sctp_remote_error *sre;
union sctp_notification *snp;
char addrbuf[INET6_ADDRSTRLEN];
const char *ap;
struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
snp = buf;
switch (snp->sn_header.sn_type) {
case SCTP_ASSOC_CHANGE:
sac = &snp->sn_assoc_change;
printf("^^^ assoc_change: state=%hu, error=%hu, instr=%hu "
"outstr=%hu\n", sac->sac_state, sac->sac_error,
sac->sac_inbound_streams, sac->sac_outbound_streams);
break;
case SCTP_SEND_FAILED:
ssf = &snp->sn_send_failed;
Sample Server Programs 75