if((lfd = ext_socket(checkIPv6() ? AF_INET6 : AF_INET,
SOCK_STREAM, IPPROTO_SCTP)) == -1) {
perror("socket");
exit(1);
}
init.sinit_num_ostreams = MAX_OUTGOING;
init.sinit_max_instreams = MAX_INCOMING;
init.sinit_max_attempts = 3;
init.sinit_max_init_timeo = 30;
if(ext_setsockopt(lfd, IPPROTO_SCTP, SCTP_INITMSG, (void*)&init, sizeof(init)) < 0) {
perror("setsockopt");
exit(1);
}
sin->sin_family = AF_INET;
sin->sin_port = htons(7);
sin->sin_addr.s_addr = INADDR_ANY;
if(ext_bind(lfd, (struct sockaddr *)sin, sizeof (*sin)) == -1) {
perror("bind");
exit(1);
}
/* Enable ancillary data and notifications */
memset((char*)&events,1,sizeof(events));
if (ext_setsockopt(lfd, IPPROTO_SCTP, SCTP_EVENTS, &events, sizeof(events)) < 0) {
perror("setsockopt SCTP_EVENTS");
exit(1);
}
if(ext_listen(lfd, 1) == -1) {
perror("listen");
exit(1);
}
/* Wait for new associations */
for (;;) {
if((cfd = ext_accept(lfd, NULL, 0)) == -1) {
perror("accept");
exit(1);
}
/* add start----------------------------*/
ext_close(cfd);//error appear:(ERROR:ext_close(1022)--still in use!)
/* add end------------------------------*/
/* Enable ancillary data and notifications */
memset((char*)&events,1,sizeof(events));
if(ext_setsockopt(cfd, IPPROTO_SCTP, SCTP_EVENTS, &events, sizeof(events)) < 0) {
perror("setsockopt SCTP_EVENTS");
exit(1);
}
/* Echo back any and all data */
echo(cfd,0);
}
}
Archive powered by MHonArc 2.6.19+.