Skip to content

Commit d9c9ee7

Browse files
Update jellyfish.c
1 parent d67044b commit d9c9ee7

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

code/logic/jellyfish.c

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,17 @@ uint64_t get_time_microseconds(void) {
131131
#define DEFAULT_SALT 0xcbf29ce484222325ULL
132132

133133
#if defined(_WIN32) || defined(_WIN64)
134-
// ===================================================
135-
// Windows implementation using GetAdaptersAddresses()
136-
// ===================================================
137-
#include <winsock2.h>
134+
// =======================
135+
// Windows (MinGW-safe)
136+
// =======================
137+
#include <winsock2.h> // MUST come first
138138
#include <iphlpapi.h>
139+
#pragma comment(lib, "iphlpapi.lib")
139140

140141
static uint64_t get_device_salt(void) {
141142
uint64_t salt = DEFAULT_SALT;
142143
ULONG size = 15000;
144+
143145
IP_ADAPTER_ADDRESSES *adapters = (IP_ADAPTER_ADDRESSES *)malloc(size);
144146
if (!adapters) return salt;
145147

@@ -154,18 +156,19 @@ static uint64_t get_device_salt(void) {
154156
}
155157
}
156158
}
159+
157160
free(adapters);
158161
return salt;
159162
}
160163

161164
#elif defined(__APPLE__) && defined(__MACH__)
162-
// ========================
163-
// macOS / Darwin
164-
// ========================
165+
// =======================
166+
// macOS
167+
// =======================
165168
#include <ifaddrs.h>
166169
#include <net/if_dl.h>
167-
#include <net/if.h> // for IFNAMSIZ
168-
#include <sys/socket.h> // for struct sockaddr and AF_LINK
170+
#include <net/if.h>
171+
#include <sys/socket.h>
169172

170173
static uint64_t get_device_salt(void) {
171174
uint64_t salt = DEFAULT_SALT;
@@ -194,9 +197,9 @@ static uint64_t get_device_salt(void) {
194197
}
195198

196199
#else
197-
// ========================
198-
// Linux and Unix-like OS
199-
// ========================
200+
// =======================
201+
// Linux / BSD
202+
// =======================
200203
#include <unistd.h>
201204
#include <sys/ioctl.h>
202205
#include <net/if.h>
@@ -210,12 +213,12 @@ static uint64_t get_device_salt(void) {
210213

211214
struct ifreq ifr;
212215
const char *interfaces[] = { "eth0", "wlan0", "en0", "eno1" };
216+
213217
for (size_t i = 0; i < sizeof(interfaces)/sizeof(interfaces[0]); ++i) {
214218
memset(&ifr, 0, sizeof(ifr));
215-
strncpy(ifr.ifr_name, interfaces[i], IFNAMSIZ - 1);
219+
strncpy(ifr.ifr_name, interfaces[i], sizeof(ifr.ifr_name) - 1);
216220

217-
// 0x8927 = SIOCGIFHWADDR on Linux
218-
if (ioctl(sock, 0x8927, &ifr) == 0) {
221+
if (ioctl(sock, 0x8927, &ifr) == 0) { // SIOCGIFHWADDR
219222
unsigned char *mac = (unsigned char *)ifr.ifr_hwaddr.sa_data;
220223
for (int j = 0; j < 6; ++j) {
221224
salt ^= mac[j];

0 commit comments

Comments
 (0)