-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnetlink.cc
120 lines (101 loc) · 3.21 KB
/
netlink.cc
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <cstring>
#include <dlfcn.h>
#include <ifaddrs.h>
#include <iostream>
#include <map>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/types.h>
#define QWE(name) \
static decltype(&name) orig_##name; \
if (!orig_##name && !(orig_##name = (decltype(&name))dlsym(RTLD_NEXT, #name))) { \
abort(); \
}
extern "C" {
/// g++ -std=c++2a -pthread -fpic -fpermissive -shared netlink.cc -o netlink.so -ldl -D_GNU_SOURCE
// std::string card = "wlp0s20f3";
// int getifaddrs(struct ifaddrs** ifap) {
// *ifap = NULL;
// return 0;
// QWE(getifaddrs);
// return orig_getifaddrs(ifap);
// auto ret = orig_getifaddrs(ifap);
// if (ret == -1)
// return -1;
// int family, s;
// char host[NI_MAXHOST];
// // ifaddrs* card = NULL;
// using namespace std::literals;
// for (ifaddrs* ifa = *ifap; ifa != NULL; ifa = ifa->ifa_next) {
// if (card != ifa->ifa_name) {
// ifa->ifa_addr = NULL;
// // continue;
// }
// // card = ifa;
// // card->ifa_next = NULL;
// // ifaddr_map.emplace(card, *ifap);
// // *ifap = card;
// }
// return ret;
// }
int prlimit64(pid_t pid, enum __rlimit_resource resource, const struct rlimit64* new_limit,
struct rlimit64* old_limit) {
if (resource == RLIMIT_CORE)
return 0;
QWE(prlimit64);
return orig_prlimit64(pid, resource, new_limit, old_limit);
}
char* setlocale(int category, const char* /* locale */) {
QWE(setlocale);
return orig_setlocale(category, "");
}
locale_t uselocale(locale_t /* newloc */) {
QWE(uselocale);
return orig_uselocale(LC_GLOBAL_LOCALE);
}
struct tm* gmtime(const time_t* timep) {
QWE(gmtime);
uselocale(LC_GLOBAL_LOCALE);
return orig_gmtime(timep);
}
struct tm* gmtime_r(const time_t* timep, struct tm* result) {
QWE(gmtime_r);
uselocale(LC_GLOBAL_LOCALE);
return orig_gmtime_r(timep, result);
}
struct tm* localtime(const time_t* timep) {
QWE(localtime);
uselocale(LC_GLOBAL_LOCALE);
return orig_localtime(timep);
}
struct tm* localtime_r(const time_t* timep, struct tm* result) {
QWE(localtime_r);
uselocale(LC_GLOBAL_LOCALE);
return orig_localtime_r(timep, result);
}
// int socket(int family, int type, int protocol) {
// QWE(socket);
// struct ifreq interface;
// int fd = orig_socket(family, type, protocol);
// int errorCode;
// strcpy(interface.ifr_name, card.c_str());
// errorCode = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &interface, sizeof(interface));
// if (errorCode < 0) {
// perror("setsockopt");
// errno = EINVAL;
// return -1;
// };
// return fd;
// }
// void freeifaddrs(struct ifaddrs* ifa) {
// QWE(freeifaddrs);
// auto it = ifaddr_map.find(ifa);
// if (it != ifaddr_map.end())
// orig_freeifaddrs(it->second);
// else
// orig_freeifaddrs(ifa);
// }
}