- From: Tetu Ou <hu-outetu AT hiroshima-u.ac.jp>
- To: Michael Tuexen <Michael.Tuexen AT micmac.franken.de>
- Cc: sctp-discussion AT sctp.de
- Subject: Re: [SCTP-Discussion] question about SCTP programming
- Date: Tue, 03 Sep 2013 21:14:19 +0900
- List-archive: <http://lists.franken.de/pipermail/sctp-discussion>
- List-id: SCTP Discussions <sctp-discussion.sctp.de>
Dear Mr.Tuexen,
Thank you very much for your reply.
Compile was OK but when I running the client program(receive
message),the "Create socket error!"was printed out.
This is my fully source code of CreateSocket():
int CreateSocket()
{
int in, tempSock, ret, ret_1;
struct sockaddr_in servaddr, servaddr_1;
struct sctp_status status;
//struct sctp_sndrcvinfo sndrcvinfo;
struct sctp_event_subscribe events;
struct sctp_initmsg initmsg;
/* Create an SCTP TCP-Style Socket */
connSock = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
connSock_1 = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (tempSock < 0 || connSock_1 < 0) {
printf("Create socket error!\n");
exit (-1);
}
/* Specify that a maximum of 5 streams will be available per socket */
memset(&initmsg, 0, sizeof(initmsg));
initmsg.sinit_num_ostreams = conf.thread;
initmsg.sinit_max_instreams = conf.thread;
initmsg.sinit_max_attempts = 1;
ret = setsockopt(connSock, IPPROTO_SCTP, SCTP_INITMSG,
&initmsg, sizeof(initmsg));
ret_1 = setsockopt(connSock_1, IPPROTO_SCTP, SCTP_INITMSG,
&initmsg, sizeof(initmsg));
/* Specify the peer endpoint to which we'll connect */
bzero((void *)&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(MY_PORT_NUM);
servaddr.sin_addr.s_addr = inet_addr(conf.ip);
/* Specify the peer endpoint to which we'll connect */
bzero((void *)&servaddr_1, sizeof(servaddr_1));
servaddr_1.sin_family = AF_INET;
servaddr_1.sin_port = htons(MY_PORT_NUM+1);
servaddr_1.sin_addr.s_addr = inet_addr(conf.ip);
/* Connect to the server */
ret = connect(connSock, (struct sockaddr *)&servaddr, sizeof(servaddr));
ret_1 = connect(connSock_1, (struct sockaddr *)&servaddr_1,
sizeof(servaddr_1));
if (ret == -1 || ret_1 == -1) {
perror("Connection failure: ");
exit (-1);
}
/* Enable receipt of SCTP Snd/Rcv Data via sctp_recvmsg */
memset( (void *)&events, 0, sizeof(events) );
events.sctp_data_io_event = 1;
ret = setsockopt( connSock, SOL_SCTP, SCTP_EVENTS,
(const void *)&events, sizeof(events) );
/* Read and emit the status of the Socket (optional step) */
in = sizeof(status);
ret = getsockopt( connSock, SOL_SCTP, SCTP_STATUS,
(void *)&status, (socklen_t *)&in );
printf("assoc id = %d\n", status.sstat_assoc_id );
printf("state = %d\n", status.sstat_state );
printf("instrms = %d\n", status.sstat_instrms );
printf("outstrms = %d\n", status.sstat_outstrms );
return connSock;
}
Best regards
Zhe Wang
于 2013/09/03 3:58, Michael Tuexen 写道:
>
On Sep 2, 2013, at 4:42 PM, Tetu Ou
>
<hu-outetu AT hiroshima-u.ac.jp>
>
wrote:
>
>
> Hello,
>
>
>
> I am a new member of this mailing list,and i have a question about SCTP
>
> programming on FreeBSD.
>
> When I compiling my SCTP server/client(send/receive) program,I found an
>
> error like this:
>
> error:
>
> client.c: SOL_SCTP undeclared(first use in this function)...
>
>
>
> But on Linux,it was OK.
>
>
>
> The part of my source code( CreateSocket() ):
>
> /* Enable receipt of SCTP Snd/Rcv Data via sctp_recvmsg */
>
> memset( (void *)&events, 0, sizeof(events) );
>
> events.sctp_data_io_event = 1;
>
> ret = setsockopt( connSock, SOL_SCTP, SCTP_EVENTS,
>
> (const void *)&events, sizeof(events) );
>
>
>
> /* Read and emit the status of the Socket (optional step) */
>
> in = sizeof(status);
>
> ret = getsockopt( connSock, SOL_SCTP, SCTP_STATUS,
>
> (void *)&status, (socklen_t *)&in );
>
On FreeBSD you need to use IPPROTO_SCTP instead of SOL_SCTP.
>
>
Best regards
>
Michael
>
> I am sorry for my poor english,and I was wondering if it be possible to
>
> ask somebody who can help me.
>
>
>
> Thank you.
>
> Best Regards.
>
>
>
> --
>
> Zhe Wang
>
> Hiroshima University
>
>
>
> _______________________________________________
>
> sctp-discussion mailing list
>
> sctp-discussion AT sctp.de
>
> http://www.sctp.de/mailman/listinfo/sctp-discussion
>
>
>
-----
>
在此邮件中未发现病毒。
>
检查工具:AVG - www.avg.com
>
版本:2013.0.3392 / 病毒数据库:3222/6630 - 发布日期:09/02/13
--
Zhe Wang
Hiroshima University
Mail:
hu-outetu AT hiroshima-u.ac.jp
Archive powered by MHonArc 2.6.19+.