Stream-Control Transmission Protocol
by Ian Barile


Example 1:

int SCTPSock = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
//set sctp initial options
	sctp_initmsg tSCTPInitMsg;
	memset(&tSCTPInitMsg, 0, sizeof(tSCTPInitMsg));
	tSCTPInitMsg.sinit_num_ostreams = 10;
	tSCTPInitMsg.sinit_max_instreams = 20;
	int nRet = setsockopt(SCTPSock, SOL_SCTP, SCTP_INITMSG,
                             &tSCTPInitMsg, sizeof(tSCTPInitMsg));
//tell SCTP to provide information about the data messages 
//being sent across the SCTP association
sctp_event_subscribe tSCTPSubscribe;
	memset(&tSCTPSubscribe, 0, sizeof(tSCTPSubscribe));
	tSCTPSubscribe.sctp_data_io_event = 1;
	tSCTPSubscribe.sctp_send_failure_event = 1;
	nRet = setsockopt(SCTPSock, SOL_SCTP, SCTP_EVENTS,
			    &tSCTPSubscribe, sizeof(tSCTPSubscribe));

Example 2:

nRet = sctp_recvmsg(SCTPSock, szBuf, &buflen,
			 (sockaddr*)&msgname, &msgname_len,
			 &tSCTPSndRcvInfo, &msg_flags);
if( nRet == -1 ){
		perror(NULL);
		return -1;
}
switch(tSCTPSndRcvInfo.sinfo_stream){
 ...
}


Example 3: 

int SCTPSock = socket(PF_INET, SOCK_SEQ_PACKET, IPPROTO_SCTP);

void* pvSockAddrs;
int nAddrCount = 2;
pvSockAddrs = malloc( nAddrCount*sizeof(sockaddr_in));

//create addrs
struct sockaddr_in* sa;
sa = (sockaddr_in*)pvSockAddrs;
sa->sin_family = AF_INET;
 ...

sa = (sockaddr_in*)(pvSockAddrs + sizeof(sockaddr_in));
 ...
int nRet = sctp_bindx(SCTPSock, pvSockAddrs, nAddrCount, SCTP_BINDX_ADD_ADDR);




2


