Skip to content

Instantly share code, notes, and snippets.

@drygdryg
Created April 9, 2021 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drygdryg/06c94e1d6262103dddb0472bc326799a to your computer and use it in GitHub Desktop.
Save drygdryg/06c94e1d6262103dddb0472bc326799a to your computer and use it in GitHub Desktop.
Patch to cross-compile Masscan under MinGW
diff --git a/Makefile b/Makefile
index 8265d5e..00eebe0 100644
--- a/Makefile
+++ b/Makefile
@@ -49,8 +49,8 @@ endif
# intended environment, so it make break in the future.
ifneq (, $(findstring mingw, $(SYS)))
INCLUDES = -Ivs10/include
-LIBS = -L vs10/lib -lIPHLPAPI -lWs2_32
-FLAGS2 = -march=i686
+LIBS = -L vs10/lib -liphlpapi -lws2_32
+#FLAGS2 = -march=i686
endif
# Cygwin
diff --git a/src/main.c b/src/main.c
index 31cfc6a..13b84ff 100644
--- a/src/main.c
+++ b/src/main.c
@@ -76,7 +76,7 @@
#include <stdint.h>
#if defined(WIN32)
-#include <WinSock.h>
+#include <winsock.h>
#if defined(_MSC_VER)
#pragma comment(lib, "Ws2_32.lib")
#endif
diff --git a/src/out-tcp-services.c b/src/out-tcp-services.c
index 8a4f49a..d7ee66e 100644
--- a/src/out-tcp-services.c
+++ b/src/out-tcp-services.c
@@ -5,7 +5,7 @@
#ifndef WIN32
#include <netdb.h>
#else
-#include <WinSock2.h>
+#include <winsock2.h>
#endif
#include <ctype.h>
diff --git a/src/pixie-backtrace.c b/src/pixie-backtrace.c
index 9251bcf..54fd123 100644
--- a/src/pixie-backtrace.c
+++ b/src/pixie-backtrace.c
@@ -96,7 +96,7 @@ pixie_backtrace_init(const char *self)
}
#elif defined(WIN32)
-#include <Windows.h>
+#include <windows.h>
typedef struct _SYMBOL_INFO {
ULONG SizeOfStruct;
diff --git a/src/pixie-file.c b/src/pixie-file.c
index f999a12..a0aeb58 100644
--- a/src/pixie-file.c
+++ b/src/pixie-file.c
@@ -1,7 +1,7 @@
#include "pixie-file.h"
#if defined(WIN32)
-#include <Windows.h>
+#include <windows.h>
#include <io.h>
#include <fcntl.h>
#define access _access
diff --git a/src/pixie-sockets.h b/src/pixie-sockets.h
index 97f8a1e..c589b8d 100644
--- a/src/pixie-sockets.h
+++ b/src/pixie-sockets.h
@@ -2,7 +2,7 @@
#define PIXIE_SOCKETS_H
#include <stddef.h>
#if defined(WIN32)
-#include <WinSock2.h>
+#include <winsock2.h>
#else
#include <sys/socket.h>
#include <sys/select.h>
diff --git a/src/pixie-threads.c b/src/pixie-threads.c
index 48283a1..9e9539f 100644
--- a/src/pixie-threads.c
+++ b/src/pixie-threads.c
@@ -2,7 +2,7 @@
#include "pixie-threads.h"
#if defined(WIN32)
-#include <Windows.h>
+#include <windows.h>
#include <process.h>
#endif
#if defined(__GNUC__)
diff --git a/src/pixie-timer.c b/src/pixie-timer.c
index e84eca0..6802cc7 100644
--- a/src/pixie-timer.c
+++ b/src/pixie-timer.c
@@ -31,7 +31,7 @@
#if defined(WIN32)
-#include <Windows.h>
+#include <windows.h>
LARGE_INTEGER
getFILETIMEoffset(void)
@@ -54,48 +54,6 @@ getFILETIMEoffset(void)
return (t);
}
-int
-clock_gettime(int X, struct timeval *tv)
-{
- LARGE_INTEGER t;
- FILETIME f;
- double microseconds;
- static LARGE_INTEGER offset;
- static double frequencyToMicroseconds;
- static int initialized = 0;
- static BOOL usePerformanceCounter = 0;
-
- UNUSEDPARM(X);
-
- if (!initialized) {
- LARGE_INTEGER performanceFrequency;
- initialized = 1;
- usePerformanceCounter = QueryPerformanceFrequency(&performanceFrequency);
- if (usePerformanceCounter) {
- QueryPerformanceCounter(&offset);
- frequencyToMicroseconds = (double)performanceFrequency.QuadPart / 1000000.;
- } else {
- offset = getFILETIMEoffset();
- frequencyToMicroseconds = 10.;
- }
- }
- if (usePerformanceCounter) QueryPerformanceCounter(&t);
- else {
- GetSystemTimeAsFileTime(&f);
- t.QuadPart = f.dwHighDateTime;
- t.QuadPart <<= 32;
- t.QuadPart |= f.dwLowDateTime;
- }
-
- t.QuadPart -= offset.QuadPart;
- microseconds = (double)t.QuadPart / frequencyToMicroseconds;
- t.QuadPart = (LONGLONG)microseconds;
- tv->tv_sec = (long)(t.QuadPart / 1000000);
- tv->tv_usec = t.QuadPart % 1000000;
- return (0);
-}
-
-
uint64_t
pixie_gettime(void)
{
diff --git a/src/rawsock-getip6.c b/src/rawsock-getip6.c
index 94a36ba..097274d 100644
--- a/src/rawsock-getip6.c
+++ b/src/rawsock-getip6.c
@@ -83,12 +83,37 @@ rawsock_get_adapter_ipv6(const char *ifname)
#elif defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
-#include <WS2tcpip.h>
+#include <ws2tcpip.h>
#include <iphlpapi.h>
#ifdef _MSC_VER
#pragma comment(lib, "IPHLPAPI.lib")
#endif
+const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
+{
+ if (af == AF_INET)
+ {
+ struct sockaddr_in in;
+ memset(&in, 0, sizeof(in));
+ in.sin_family = AF_INET;
+ memcpy(&in.sin_addr, src, sizeof(struct in_addr));
+ getnameinfo((struct sockaddr *)&in, sizeof(struct
+sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST);
+ return dst;
+ }
+ else if (af == AF_INET6)
+ {
+ struct sockaddr_in6 in;
+ memset(&in, 0, sizeof(in));
+ in.sin6_family = AF_INET6;
+ memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
+ getnameinfo((struct sockaddr *)&in, sizeof(struct
+sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST);
+ return dst;
+ }
+ return NULL;
+}
+
ipv6address
rawsock_get_adapter_ipv6(const char *ifname)
{
diff --git a/src/string_s.c b/src/string_s.c
index 388bc15..3edb407 100644
--- a/src/string_s.c
+++ b/src/string_s.c
@@ -80,36 +80,6 @@ errno_t strcpy_s(char *dst, size_t sizeof_dst, const char *src)
}
#endif
-#ifdef __GNUC__
-
-errno_t localtime_s(struct tm* _tm, const time_t *time)
-{
- struct tm *x;
-
- x = localtime(time);
- if (x == NULL) {
- memset(_tm, 0, sizeof(*_tm));
- return -1;
- }
- memcpy(_tm, x, sizeof(*_tm));
-
- return 0;
-}
-errno_t gmtime_s(struct tm* _tm, const time_t *time)
-{
- struct tm *x;
-
- x = gmtime(time);
- if (x == NULL) {
- memset(_tm, 0, sizeof(*_tm));
- return -1;
- }
- memcpy(_tm, x, sizeof(*_tm));
-
- return 0;
-}
-#endif
-
/*
* I don't understand why Microsoft says this function is unsafe, so
diff --git a/src/stub-lua.c b/src/stub-lua.c
index 8059c88..89d288f 100644
--- a/src/stub-lua.c
+++ b/src/stub-lua.c
@@ -3,7 +3,7 @@
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
-#include <Windows.h>
+#include <windows.h>
#pragma warning(disable: 4133 4113 4047)
#else
#include <dlfcn.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment