-
Notifications
You must be signed in to change notification settings - Fork 0
/
zbuff_sctp_client.c
68 lines (59 loc) · 1.57 KB
/
zbuff_sctp_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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#define BUFFER 1048576 //1MB sized buffer, eventually make this CLI option
#define PORT 5000 //static port number, eventually make this CLI option
int main (int argc, char* argv[])
{
int connSock;
int in;
int i;
int ret;
int flags;
struct sockaddr_in servaddr;
struct sctp_status status;
char buffer[BUFFER+1];
int datalen = 0;
//ask user for data to be sent
fprintf(stdout, "Enter data to be sent\n");
fgets(buffer, BUFFER, stdin);
//clear new line, and/or carriage return from input
buffer[strcspn(buffer, "\r\n")] = 0;
datalen = strlen(buffer);
connSock = socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP);
if (connSock == -1)
{
fprintf(stderr, "Function socket() failed!\n");
exit(1);
}
//initialize servaddr struct and fill it with 0's
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PORT);
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ret = connect(connSock, (struct sockaddr *) &servaddr, sizeof(servaddr));
if (ret == -1)
{
fprintf(stderr, "Function connect() failed!\n");
close(connSock);
exit(1);
}
ret = sctp_sendmsg(connSock, (void *) buffer, (size_t) datalen, NULL, 0, 0, 0, 0, 0, 0);
if(ret == -1)
{
fprintf(stderr, "Function sctp_sendmsg() failed!\n");
exit(1);
}
else
{
printf("Successfully sent %d bytes of data to the server!\n", ret);
}
close(connSock);
return 0;
}