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. >=20 > 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. >=20 > 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 =3D 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 >=20 > /*Here are programs.*/ >=20 > #include <sys/errno.h> > #include <stdio.h> > #include <string.h> >=20 > #include <netinet/in.h> > #include <netinet/sctp.h> > #include <sys/types.h> > #include <sys/socket.h> > #define PORT 63000 > #define MTU 1500 >=20 > int main() > { > int _listenfd, _sctp_socket, _connfd; > struct sockaddr_in servaddr; > int ret, msg_flag; > char message[MTU]; > struct sctp_sndrcvinfo sndrcvinfo; > =09 > _sctp_socket =3D socket( AF_INET , SOCK_SEQPACKET , IPPROTO_SCTP = ); >=20 > bzero( (void *)&servaddr, sizeof(servaddr) ); > servaddr.sin_family =3D AF_INET; > servaddr.sin_addr.s_addr =3D htonl( INADDR_ANY ); > servaddr.sin_port =3D htons(PORT); >=20 > ret =3D bind(_sctp_socket, (struct sockaddr *)&servaddr, = sizeof(servaddr)); > if( ret ) > { > printf("Server bind error" ); > } >=20 > _listenfd=3D listen(_sctp_socket, 10); > if(0 !=3D _listenfd) > { > printf("Server listen error" ); > } >=20 > ret =3D sctp_recvmsg(_sctp_socket, (void *)message , MTU, NULL, = 0 , > &sndrcvinfo , &msg_flag); > if(ret >=3D 0) > { > printf("Receive message:%s", message); > } > } > =09 >=20 > #include <sys/errno.h> > #include <stdio.h> > #include <string.h> >=20 > #include <netinet/in.h> > #include <netinet/sctp.h> > #include <sys/types.h> > #include <sys/socket.h> > #define PORT 63000 >=20 > int main() > { > int _sctp_socket, _sctp_associd, ret; > _sctp_socket =3D socket( AF_INET , SOCK_SEQPACKET , IPPROTO_SCTP = ); >=20 > struct sockaddr_in server_ipaddress; > server_ipaddress . sin_family =3D AF_INET; > server_ipaddress . sin_port =3D htons(PORT); > server_ipaddress . sin_addr.s_addr =3D inet_addr("127.0.0.1"); >=20 > ret =3D sctp_connectx(_sctp_socket , (struct sockaddr*) = &server_ipaddress , > 1, &_sctp_associd); > if( ret < 0) > { > printf("sctp_connectx error"); > } > } > =09 > =09 >=20 > =09 >=20 >=20 > -- > 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" >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?C6A45788-E86B-4825-A4A6-2859B74D110B>