-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathSendOutOfBandData_TCPClient.c
52 lines (44 loc) · 1.19 KB
/
SendOutOfBandData_TCPClient.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
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string.h>
#include <errno.h>
#include "../../tool/TimeTool.h"
int main(int argc, char *argv[])
{
if (argc != 3) {
printf("usage : %s <ip> <port>\n", argv[0]);
exit(0);
}
int fd = -1;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
perror("socket fd create fail!");
exit(1);
}
struct sockaddr_in svraddr;
bzero(&svraddr, sizeof(svraddr));
svraddr.sin_family = AF_INET;
svraddr.sin_port = htons(atoi(argv[2]));
svraddr.sin_addr.s_addr = inet_addr(argv[1]);
if (connect(fd, (struct sockaddr *)&svraddr, sizeof(svraddr)) < 0) {
perror("connect error!");
exit(1);
}
write(fd, "123", 3);
logx("wrote 3 bytes of normal data");
sleep(1);
send(fd, "4", 1, MSG_OOB);
logx("wrote 1 bytes of OOB data");
sleep(1);
write(fd, "56", 2);
logx("wrote 2 bytes of normal data");
sleep(1);
send(fd, "7", 1, MSG_OOB);
logx("wrote 1 bytes of OOB data");
sleep(1);
write(fd, "89", 2);
logx("wrote 1 bytes of normal data");
sleep(1);
}