-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_wrap_socket.cpp
47 lines (38 loc) · 1.05 KB
/
common_wrap_socket.cpp
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
#ifdef wrapsocks
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
ssize_t __real_send(int sockfd, const void* buf, size_t len, int flags);
ssize_t __real_recv(int sockfd, void* buf, size_t len, int flags);
static size_t _random(size_t max) {
static bool is_random_initialized = false;
if (!is_random_initialized) {
srand(time(NULL));
is_random_initialized = true;
}
return 1 + (rand() % max);
}
// cppcheck-suppress unusedFunction
ssize_t __wrap_send(int sockfd, const void* buf, size_t len, int flags) {
size_t modified_len = len;
if (len != 0) {
modified_len = _random(len);
}
return __real_send(sockfd, buf, modified_len, flags);
}
// cppcheck-suppress unusedFunction
ssize_t __wrap_recv(int sockfd, void* buf, size_t len, int flags) {
size_t modified_len = len;
if (len != 0) {
modified_len = _random(len);
}
return __real_recv(sockfd, buf, modified_len, flags);
}
#ifdef __cplusplus
}
#endif
#endif // end ifdef