-
Notifications
You must be signed in to change notification settings - Fork 0
/
rst_client.c
88 lines (85 loc) · 2.37 KB
/
rst_client.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#define PORT 5001
#define ADDR "212.201.121.85"
#define NUMBER_OF_STREAMS 65535
int
main(int argc, char *argv[])
{
int fd;
char c;
struct sctp_initmsg init;
#if 1
struct sctp_reset_streams srs;
#else
sctp_assoc_t assoc_id;
#endif
struct sctp_udpencaps udpencaps;
struct sockaddr_in addr;
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP)) < 0) {
perror("socket");
}
memset(&init, 0, sizeof(struct sctp_initmsg));
init.sinit_num_ostreams = NUMBER_OF_STREAMS;
if (setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, (const void *)&init, (socklen_t)sizeof(struct sctp_initmsg)) < 0) {
perror("setsockopt(SCTP_INITMSG)");
}
memset(&udpencaps, 0, sizeof(struct sctp_udpencaps));
udpencaps.sue_address.ss_family=AF_INET;
udpencaps.sue_port = htons(9899);
if (setsockopt(fd, IPPROTO_SCTP, SCTP_REMOTE_UDP_ENCAPS_PORT, (void *)&udpencaps, sizeof(struct sctp_udpencaps)) < 0) {
perror("setsockopt");
}
memset(&addr, 0, sizeof(struct sockaddr_in));
addr.sin_family = AF_INET;
addr.sin_len = sizeof(struct sockaddr_in);
addr.sin_addr.s_addr = inet_addr(ADDR);
addr.sin_port = htons(PORT);
if (connect(fd, (const struct sockaddr *) &addr, sizeof(struct sockaddr_in)) != 0) {
perror("connect");
}
c = 'A';
if (send(fd, (const void *)&c, 1, 0) < 0) {
perror("send 1");
}
c = 'B';
if (send(fd, (const void *)&c, 1, 0) < 0) {
perror("send 2");
}
#if 1
memset(&srs, 0, sizeof(struct sctp_reset_streams));
srs.srs_flags = SCTP_STREAM_RESET_OUTGOING;
srs.srs_number_streams = 0;
if (setsockopt(fd, IPPROTO_SCTP, SCTP_RESET_STREAMS, &srs, (socklen_t)sizeof(struct sctp_reset_streams)) < 0) {
perror("setsockopt SCTP_RESET_STREAMS");
}
#else
if (setsockopt(fd, IPPROTO_SCTP, SCTP_RESET_ASSOC, &assoc_id, (socklen_t)sizeof(sctp_assoc_t)) < 0) {
perror("setsockopt SCTP_RESET_ASSOC");
}
#endif
sleep(1);
c = 'C';
if (send(fd, (const void *)&c, 1, 0) < 0) {
perror("send 3");
}
c = 'D';
if (send(fd, (const void *)&c, 1, 0) < 0) {
perror("send 3");
}
printf("now sleeping for the finale\n");
sleep(10);
printf("We are not awake and ready to go home\n");
if (close(fd) < 0) {
perror("close");
}
return (0);
}