All of lore.kernel.org
 help / color / mirror / Atom feed
* Problem code multi-streaming
@ 2011-06-09  3:09 Nguyễn Phước Thành
  2011-06-09  4:27 ` Max Matveev
  2011-06-09  7:31 ` Wei Yongjun
  0 siblings, 2 replies; 3+ messages in thread
From: Nguyễn Phước Thành @ 2011-06-09  3:09 UTC (permalink / raw)
  To: linux-sctp

[-- Attachment #1: Type: text/plain, Size: 613 bytes --]

I have some code demo using multi-streaming, but it is not run right.I 
attach my code send file in this mail. I using this code from sctp_test, 
but i don't know why it error.
I use sinfo->sinfo_stream = 1; and when send one chunk I change stream :

  if(stream==1) stream=2;
  if(stream==2)  stream=1;

But capture packet with Wireshark I see SID is always 1, I send packet 
is order, using multi-homing.
All different functions run ok.I don't know why SID don't change.I read 
this darft of socket API SCTP in folder doc of LKSCTP, but I don't 
understand why I write code like sctp_test but sctp_test run ok.

[-- Attachment #2: codesend_file.c --]
[-- Type: text/plain, Size: 4307 bytes --]

void send_file(int sk)\r{\r    struct msghdr outmsg;\r    char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];\r    struct cmsghdr *cmsg;\r    struct sctp_sndrcvinfo *sinfo;\r    struct iovec iov;\r    char message[1500];\r    struct hostent *hst;\r    struct sockaddr *addrs;\r    int msglen;\r    int error = 0;\r    int try_error=0;\r    int stream = 1;\r    //Kiem lai dia chi dich va gan cac thong tin phu hop\r        if (remote_host != NULL) {\r		hst = gethostbyname(remote_host);\r		if (hst == NULL || hst->h_length < 1) {\r			fprintf(stderr, "%s: bad hostname: \n",\r				remote_host);\r			exit(1);\r		}\r		ra_family = hst->h_addrtype;\r                ra_len = sizeof(remote_addr);\r                ra_raw = &remote_addr.sin_addr;\r		remote_addr.sin_port = htons(8000);\r		remote_addr.sin_family = AF_INET;\r		memcpy(ra_raw, hst->h_addr_list[0], hst->h_length);\r        }\r        else\r        {\r            //Hostname khong ton tai thoat chuong trinh...\r            printf("Not found remote host!!!\n");\r            printf("Shutdown program.\n");\r            exit(1);\r        }\r        printf("Host name is %s.\n",remote_host);\r        // KIem tra su ton tai cua ket noi toi remote addrs\r        if ((SOCK_SEQPACKET == socket_type) && associd &&\r            (0 != test_sk_for_assoc(sk, associd))) {\r		associd = test_recv_assoc_change(sk);\r		printf("Old association gone, Starting a new one!\n");\r		new_connection = 1;\r	}\r        int fd;\r        if ( localfile == NULL ) fd = 0;\r	fd = open(localfile,O_RDONLY);\r        if(fd==-1)\r        {\r            printf("Read file error.\n");\r            exit(1);\r        }\r	fprintf(stderr," ready to send...\n");\r        printf("Ready to send file....\n");\r        msglen=read(fd,message,1024);\r        do {\r            /* Initialize the message struct we use to pass\r		 * messages to the remote socket.\r             */\r            try_error++;\r            if(try_error==100)\r            {\r                printf("Can't connect remote address,program shutdown.\n");\r                exit(1);\r            }\r            iov.iov_base = message;\r            iov.iov_len = msglen;\r            outmsg.msg_iov = &iov;\r            outmsg.msg_iovlen = 1;\r            outmsg.msg_control = outcmsg;;\r            outmsg.msg_controllen = sizeof(outcmsg);\r            outmsg.msg_name = &remote_addr;\r            outmsg.msg_namelen = ra_len;\r            cmsg = CMSG_FIRSTHDR(&outmsg);\r            cmsg->cmsg_level = IPPROTO_SCTP;\r            cmsg->cmsg_type = SCTP_SNDRCV;\r            cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo));\r            outmsg.msg_controllen = cmsg->cmsg_len;\r            sinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg);\r            memset(sinfo, 0, sizeof(struct sctp_sndrcvinfo));\r            sinfo->sinfo_flags = 0;\r            sinfo->sinfo_stream = 1;\r            sinfo->sinfo_ppid=rand();\r            error = sendmsg(sk, &outmsg, MSG_WAITALL);\r            if (error != msglen) \r		printf(stderr, ": error: %s.\n", strerror(errno));\r	} while (error != msglen);\r\r    /* If this is the first message sent over a UDP-style socket,\r     * get the associd from the SCTP_ASSOC_CHANGE notification.\r     */\r	if ((SOCK_SEQPACKET == socket_type) && (0 == associd))\r			associd = test_recv_assoc_change(sk);\r\r	/* Verify there is no association.  */\r	if (0 != test_sk_for_assoc(sk, associd)) {\r		printf("No association is present now!!\n");\r		new_connection = 1;\r		}\r        else {\r		if (new_connection) {\r		int rc = sctp_getpaddrs(sk, associd, &addrs);\r		if (0 >= rc) {\r                    if (rc == 0) {\r			fprintf(stderr, "sctp_getpaddrs failed, no peers.\n");\r                    } else {\r			fprintf(stderr, "sctp_getpaddrs failed %s(%d).\n", strerror(errno), errno);\r			}\r                         exit(1);\r		}\r		printf("New connection, peer addresses\n");\r		//print_addr_buf(addrs, rc);\r		sctp_freepaddrs(addrs);\r		new_connection = 0;\r		}\r        }\r        iov.iov_base = buffer;\r	iov.iov_len = 1;\r	outmsg.msg_iov = &iov;\r	outmsg.msg_iovlen = 1;\r        /* open the file */\r	\r	while ( (msglen = read(fd,buffer,1024)) > 0 ) {\r		/* Send to our neighbor.  */\r            if(stream==1) stream=2;\r            if(stream==2)  stream=1;\r            sinfo->sinfo_stream = stream;\r			iov.iov_len = msglen;\r		 sendmsg(sk, &outmsg, MSG_WAITALL);\r	}\r\r	close(fd);\r	close(sk);\r}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-09  7:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-09  3:09 Problem code multi-streaming Nguyễn Phước Thành
2011-06-09  4:27 ` Max Matveev
2011-06-09  7:31 ` Wei Yongjun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.