forked from csmith-project/csmith
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mac.patch
79 lines (78 loc) · 2.12 KB
/
mac.patch
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
diff --git a/src/platform.cpp b/src/platform.cpp
index d1ef1f9..c85e613 100644
--- a/src/platform.cpp
+++ b/src/platform.cpp
@@ -47,6 +47,10 @@
#include "platform.h"
#include <stdlib.h>
#include <sys/time.h>
+#include <net/if.h>
+#include <stdio.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
#if HAVE_BSD_STDLIB_H
# include <bsd/stdlib.h>
#endif
@@ -110,12 +114,62 @@ unsigned long platform_gen_seed()
return seed;
}
#else
+unsigned long getMacValue(void) {
+ int fd;
+ int interfaceNum = 0;
+ struct ifreq buf[16];
+ struct ifconf ifc;
+ struct ifreq ifrcopy;
+
+ if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
+ perror("socket");
+ close(fd);
+ return (unsigned long)1;
+ }
+
+ ifc.ifc_len = sizeof(buf);
+ ifc.ifc_buf = (caddr_t)buf;
+ if (!ioctl(fd, SIOCGIFCONF, (char *)&ifc)) {
+ interfaceNum = ifc.ifc_len / sizeof(struct ifreq);
+ while (interfaceNum-- > 0) {
+ // ignore the interface that not up or not runing
+ ifrcopy = buf[interfaceNum];
+ if (ioctl(fd, SIOCGIFFLAGS, &ifrcopy)) {
+ continue;
+ }
+
+ // get the mac of this interface
+ if (!ioctl(fd, SIOCGIFHWADDR, (char *)(&buf[interfaceNum]))) {
+ unsigned long value = 0;
+ int j=0;
+ for(int i=5; i>=0; i--) {
+ value += ((unsigned long)(buf[interfaceNum].ifr_hwaddr.sa_data[i]) << (j*8));
+ j++;
+ }
+ if( value == 0 ) {
+ continue;
+ } else {
+ return value;
+ }
+ } else {
+ close(fd);
+ return (unsigned long)2;
+ }
+ }
+ } else {
+ close(fd);
+ return (unsigned long)3;
+ }
+ close(fd);
+ return (unsigned long)0;
+}
+
unsigned long platform_gen_seed()
{
//return (long) read_time();
struct timeval tp;
gettimeofday(&tp, nullptr);
- return tp.tv_sec * 1000000 + tp.tv_usec;
+ return getMacValue() + (unsigned long)(tp.tv_sec * 1000000 + tp.tv_usec);
}
#endif