Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 3 Dec 2011 08:29:37 +0100
From:      =?iso-8859-1?Q?Michael_T=FCxen?= <Michael.Tuexen@lurchi.franken.de>
To:        jyl_2006 <yilinjing2006@gmail.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: the return value of sctp_connectx do not match any error
Message-ID:  <C6A45788-E86B-4825-A4A6-2859B74D110B@lurchi.franken.de>
In-Reply-To: <1322888085250-5043901.post@n5.nabble.com>
References:  <1322834879026-5041952.post@n5.nabble.com> <0D6FA7F2-1462-44EF-98F4-3B6AFC856757@lurchi.franken.de> <1322888085250-5043901.post@n5.nabble.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Dec 3, 2011, at 5:54 AM, jyl_2006 wrote:

> First, I use the return value of sctp_connectx, and I do not use errno, so
> the return value does not match the errors gived in manual. Now,I know it is
> my mistake.
> 
> However, I write a simple program to test sctp_connectx, it still show
> error.The errno is "EINVAL", I am sure that the paraments are set properly.
> 
> One more thing, I also test these programs in other platform, the result is
> OK, but under FreeBSD, it does not work.
In BSD you need to set the sin_len field of the sockaddr_in structure.
So if you add
	server_ipaddress . sin_len = sizeof(struct sockaddr_in);
the client works (at least it does for me).
You should do the same for the server...

Please let me know if your problem persists.

Best regards
Michael
> 
> /*Here are programs.*/
> 
> #include <sys/errno.h>
> #include <stdio.h>
> #include <string.h>
> 
> #include <netinet/in.h>
> #include <netinet/sctp.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #define PORT 63000
> #define MTU  1500
> 
> int main()
> {
> 	int _listenfd, _sctp_socket, _connfd;
> 	struct sockaddr_in servaddr;
> 	int ret, msg_flag;
> 	char message[MTU];
> 	struct sctp_sndrcvinfo sndrcvinfo;
> 	
> 	_sctp_socket = socket( AF_INET , SOCK_SEQPACKET , IPPROTO_SCTP );
> 
> 	bzero( (void *)&servaddr, sizeof(servaddr) );
> 	servaddr.sin_family = AF_INET;
> 	servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
> 	servaddr.sin_port = htons(PORT);
> 
> 	ret = bind(_sctp_socket, (struct sockaddr *)&servaddr, sizeof(servaddr));
> 	if( ret )
> 	{
> 		printf("Server bind error" );
> 	}
> 
> 	_listenfd= listen(_sctp_socket, 10);
> 	if(0 != _listenfd)
> 	{
> 		printf("Server listen error" );
> 	}
> 
> 	ret = sctp_recvmsg(_sctp_socket, (void *)message , MTU, NULL, 0 ,
> &sndrcvinfo , &msg_flag);
> 	if(ret >= 0)
> 	{
> 		printf("Receive message:%s", message);
> 	}
> }
> 	
> 
> #include <sys/errno.h>
> #include <stdio.h>
> #include <string.h>
> 
> #include <netinet/in.h>
> #include <netinet/sctp.h>
> #include <sys/types.h>
> #include <sys/socket.h>
> #define PORT 63000
> 
> int main()
> {
> 	int _sctp_socket, _sctp_associd, ret;
> 	_sctp_socket = socket( AF_INET , SOCK_SEQPACKET , IPPROTO_SCTP );
> 
> 	struct sockaddr_in server_ipaddress;
> 	server_ipaddress . sin_family = AF_INET;
> 	server_ipaddress . sin_port = htons(PORT);
> 	server_ipaddress . sin_addr.s_addr = inet_addr("127.0.0.1");
> 
> 	ret = sctp_connectx(_sctp_socket , (struct sockaddr*) &server_ipaddress ,
> 1, &_sctp_associd);
>        if( ret < 0)
>        {
> 		printf("sctp_connectx error");
>        }
> }
> 	
> 	
> 
> 	
> 
> 
> --
> View this message in context: http://freebsd.1045724.n5.nabble.com/the-return-value-of-sctp-connectx-do-not-match-any-error-tp5041952p5043901.html
> Sent from the freebsd-net mailing list archive at Nabble.com.
> _______________________________________________
> freebsd-net@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org"
> 




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C6A45788-E86B-4825-A4A6-2859B74D110B>