-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommon.cpp
More file actions
47 lines (35 loc) · 1013 Bytes
/
Common.cpp
File metadata and controls
47 lines (35 loc) · 1013 Bytes
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
#include "Common.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <unistd.h>
#include <arpa/inet.h>
void bindCore(uint16_t core) {
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(core, &cpuset);
int rc = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &cpuset);
if (rc != 0) {
Debug::notifyError("can't bind core!");
}
}
char *getIP() {
struct ifreq ifr;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, "ib0", IFNAMSIZ - 1);
ioctl(fd, SIOCGIFADDR, &ifr);
close(fd);
return inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr);
}
char *getMac() {
static struct ifreq ifr;
int fd = socket(AF_INET, SOCK_DGRAM, 0);
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, "ens2", IFNAMSIZ - 1);
ioctl(fd, SIOCGIFHWADDR, &ifr);
close(fd);
return (char *)ifr.ifr_hwaddr.sa_data;
}