forked from unpbook/unpv13e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sctp_strcli1.c
41 lines (39 loc) · 1.1 KB
/
sctp_strcli1.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "unp.h"
void
sctpstr_cli(FILE *fp, int sock_fd, struct sockaddr *to, socklen_t tolen)
{
struct sockaddr_in peeraddr;
struct sctp_sndrcvinfo sri;
char sendline[MAXLINE], recvline[MAXLINE];
socklen_t len;
int out_sz,rd_sz;
int msg_flags;
bzero(&sri,sizeof(sri));
while (fgets(sendline, MAXLINE, fp) != NULL) {
if(sendline[0] != '[') {
printf("Error, line must be of the form '[streamnum]text'\n");
continue;
}
sri.sinfo_stream = strtol(&sendline[1],NULL,0);
out_sz = strlen(sendline);
Sctp_sendmsg(sock_fd, sendline, out_sz,
to, tolen,
0, 0,
sri.sinfo_stream,
0, 0);
/* include mod_strcli1 */
do {
len = sizeof(peeraddr);
rd_sz = Sctp_recvmsg(sock_fd, recvline, sizeof(recvline),
(SA *)&peeraddr, &len,
&sri,&msg_flags);
if(msg_flags & MSG_NOTIFICATION)
check_notification(sock_fd,recvline,rd_sz);
} while (msg_flags & MSG_NOTIFICATION);
printf("From str:%d seq:%d (assoc:0x%x):",
sri.sinfo_stream,sri.sinfo_ssn,
(u_int)sri.sinfo_assoc_id);
printf("%.*s",rd_sz,recvline);
/* end mod_strcli1 */
}
}