void recv_file(int sk) { char incmsg[CMSG_SPACE(sizeof(_sctp_cmsg_data_t))]; struct iovec iov; struct msghdr inmessage; struct cmsghdr *cmsg; _sctp_cmsg_data_t *sinfo; int error; static char buffer[1024]; int buffer_size=1024; int check_listen; /* Mark sk as being able to accept new associations */ check_listen = listen(sk, 5); if (check_listen != 0) { printf("\n\n\t\tlisten Failure: %s.\n\n\n", strerror(errno)); exit(1); } /* Initialize inmessage with enough space for DATA... */ memset(&inmessage, 0, sizeof(inmessage)); if ((iov.iov_base = malloc(5000)) == NULL) { printf(" Can't allocate memory.\n"); exit(1); } iov.iov_base = buffer; iov.iov_len = 5000; inmessage.msg_iov = &iov; inmessage.msg_iovlen = 1; /* or a control message. */ inmessage.msg_control = incmsg; inmessage.msg_controllen = sizeof(incmsg); int writebyte=0; int fd[10]; int check_file=0; for(check_file=0;check_file=0) { if( !(inmessage.msg_flags & MSG_NOTIFICATION )){ cmsg = CMSG_FIRSTHDR(&inmessage); if(cmsg==NULL)continue; sinfo = (struct sctp_sndrcvinfo*)CMSG_DATA(cmsg); writebyte=fwrite(buffer,error,1,fd[sinfo->sinfo_stream]); if(time_clock==0) { time_clock=1; start=time(NULL); start_c=clock(); } } else { union sctp_notification *sn; sn = (union sctp_notification *)iov.iov_base; if ((sn->sn_header.sn_type == SCTP_ASSOC_CHANGE) && (sn->sn_assoc_change.sac_state == SCTP_SHUTDOWN_COMP)) break; } } finish=time(NULL); finish_c=clock(); temp=finish_c-start_c; duration_c=(double)temp/CLOCKS_PER_SEC; duration=finish-start; printf("the file has been transferred in %d secs and %2.3f secs.\n",duration,duration_c); close(fd); close(sk); } /* command_listen() */