sctp_sndrcvinfo结构体
sctp_event_subscribe结构体
更多的关于SCTP的结构体http://aisxyz.iteye.com/blog/2408978
SCTP套接字编程相关函数
client.c
/************************************************************************* > File Name: client.c > Author: Chen > Mail: 971859774@qq.com > Created Time: 2018年11月14日 星期三 17时06分56秒 ************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <arpa/inet.h> #include <netinet/sctp.h> #include <sys/socket.h> #include <sys/types.h> #include <strings.h> #include <string.h> #include <ctype.h> #include "my_err.h" #define SERV_PORT 9877 #define SCTP_MAXLINE 800 #define SERV_MAX_SCTP_STRM 10 void sctp_cli(int sockfd,struct sockaddr * to,socklen_t tolen) { struct sctp_sndrcvinfo sri; bzero(&sri,sizeof(sri)); char rdbuf[MAXLINE],rvbuf[MAXLINE]; struct sockaddr_in peeraddr; int flag; while(fgets(rdbuf,MAXLINE,stdin)!=NULL) { if(rdbuf[0]!='[') { fprintf(stderr,"Error,line must be of the form '[strnum]text' "); continue; } if(isdigit(rdbuf[1])) { sri.sinfo_stream=strtol(&rdbuf[1],NULL,10); int out_sz=strlen(rdbuf); sctp_sendmsg(sockfd,rdbuf,out_sz,to,tolen,0,0,sri.sinfo_stream,0,0); socklen_t len=sizeof(peeraddr); int rd_sz=sctp_recvmsg(sockfd,rvbuf,sizeof(rvbuf),(struct sockaddr *)&peeraddr,&len,&sri,&flag); printf("From str:%d seq:%d (assoc:0x%x):",sri.sinfo_stream,sri.sinfo_ssn,(u_int)sri.sinfo_assoc_id); printf("%.*s",rd_sz,rvbuf); } } return; } //是否有头端阻塞 void sctp_cli_all(int sockfd,struct sockaddr *to,socklen_t tolen) { struct sctp_sndrcvinfo sri; bzero(&sri,sizeof(sri)); char rdbuf[MAXLINE],rvbuf[MAXLINE]; bzero(&rdbuf,sizeof(rdbuf)); bzero(&rvbuf,sizeof(rvbuf)); while(fgets(rdbuf,SCTP_MAXLINE-9,stdin)!=NULL) { int rd_sz=strlen(rdbuf); if(rdbuf[rd_sz-1]==' ') { rdbuf[rd_sz-1]='