use minimal winsock2 headers

This commit is contained in:
UnknownShadow200 2024-08-20 16:00:02 +10:00
parent f1cac3962c
commit c603018d48
4 changed files with 161 additions and 39 deletions

View file

@ -0,0 +1,4 @@
#define SHELLAPI DECLSPEC_IMPORT
SHELLAPI HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR operation, LPCWSTR file, LPCWSTR parameters, LPCWSTR directory, INT showCmd);
SHELLAPI HINSTANCE WINAPI ShellExecuteA(HWND hwnd, LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory, INT showCmd);

View file

@ -0,0 +1,7 @@
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE* pbData;
} DATA_BLOB;
static BOOL (WINAPI *_CryptProtectData )(DATA_BLOB* dataIn, PCWSTR dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);

139
misc/windows/min-winsock2.h Normal file
View file

@ -0,0 +1,139 @@
/* IP addresses */
typedef struct sockaddr {
USHORT sa_family;
char sa_data[14];
} SOCKADDR;
typedef struct in_addr {
union in_data {
struct { UCHAR s_b1,s_b2,s_b3,s_b4; } S_un_b;
struct { USHORT s_w1,s_w2; } S_un_w;
ULONG S_addr;
} S_un;
} IN_ADDR;
typedef struct sockaddr_in {
SHORT sin_family;
USHORT sin_port;
struct in_addr sin_addr;
char sin_zero[8];
} SOCKADDR_IN;
typedef struct in6_addr {
union in6_data {
UCHAR Byte[16];
USHORT Word[8];
} u;
} IN6_ADDR;
typedef struct sockaddr_in6 {
USHORT sin6_family;
USHORT sin6_port;
ULONG sin6_flowinfo;
IN6_ADDR sin6_addr;
ULONG sin6_scope_id;
} SOCKADDR_IN6;
typedef struct sockaddr_storage {
short ss_family;
CHAR ss_pad[126];
} SOCKADDR_STORAGE;
/* Type declarations */
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef UINT_PTR SOCKET;
/* Constants */
#define AF_INET 2
#define AF_INET6 23
#define SOCK_STREAM 1
#define IPPROTO_TCP 6
#define SOL_SOCKET 0xffff
#define SO_ERROR 0x1007
#define SD_BOTH 0x02
#define IOC_IN 0x80000000
/* has input parameters | input size| func group | command */
#define FIONBIO (IOC_IN | (4 << 16) | ('f' << 8) | 126)
/* Struct declarations */
#define FD_SETSIZE 64
typedef struct fd_set {
u_int fd_count;
SOCKET fd_array[FD_SETSIZE];
} fd_set;
struct timeval {
long tv_sec;
long tv_usec;
};
struct hostent {
char* h_name;
char** h_aliases;
short h_addrtype;
short h_length;
char** h_addr_list;
};
typedef struct addrinfo {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
char * ai_canonname;
struct sockaddr * ai_addr;
struct addrinfo * ai_next;
} ADDRINFOA;
#define WSADESCRIPTION_LEN 256
#define WSASYS_STATUS_LEN 128
typedef struct WSAData {
WORD wVersion;
WORD wHighVersion;
#ifdef _WIN64
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char* lpVendorInfo;
char szDescription[WSADESCRIPTION_LEN + 1];
char szSystemStatus[WSASYS_STATUS_LEN + 1];
#else
char szDescription[WSADESCRIPTION_LEN + 1];
char szSystemStatus[WSASYS_STATUS_LEN + 1];
unsigned short iMaxSockets;
unsigned short iMaxUdpDg;
char* lpVendorInfo;
#endif
} WSADATA;
/* Function declarations */
static int (WINAPI *_WSAStartup)(WORD versionRequested, WSADATA* wsaData);
static int (WINAPI *_WSACleanup)(void);
static int (WINAPI *_WSAGetLastError)(void);
static int (WINAPI *_WSAStringToAddressW)(LPWSTR addressString, INT addressFamily, LPVOID protocolInfo, LPVOID address, LPINT addressLength);
static int (WINAPI *_socket)(int af, int type, int protocol);
static int (WINAPI *_closesocket)(SOCKET s);
static int (WINAPI *_connect)(SOCKET s, const struct sockaddr* name, int namelen);
static int (WINAPI *_shutdown)(SOCKET s, int how);
static int (WINAPI *_ioctlsocket)(SOCKET s, long cmd, u_long* argp);
static int (WINAPI *_getsockopt)(SOCKET s, int level, int optname, char* optval, int* optlen);
static int (WINAPI *_recv)(SOCKET s, char* buf, int len, int flags);
static int (WINAPI *_send)(SOCKET s, const char FAR * buf, int len, int flags);
static int (WINAPI *_select)(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
static struct hostent* (WINAPI *_gethostbyname)(const char* name);
static unsigned short (WINAPI *_htons)(u_short hostshort);
static int (WINAPI *_getaddrinfo )(PCSTR nodeName, PCSTR serviceName, const ADDRINFOA* hints, ADDRINFOA** result);
static void (WINAPI* _freeaddrinfo)(ADDRINFOA* addrInfo);

View file

@ -16,23 +16,17 @@
#define UNICODE
#define _UNICODE
#endif
#include <winsock2.h> /* auto includes windows.h */
#include <windows.h>
/*
#include <winsock2.h>
#include <ws2tcpip.h>
/* === BEGIN shellapi.h === */
#define SHELLAPI DECLSPEC_IMPORT
SHELLAPI HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR operation, LPCWSTR file, LPCWSTR parameters, LPCWSTR directory, INT showCmd);
SHELLAPI HINSTANCE WINAPI ShellExecuteA(HWND hwnd, LPCSTR operation, LPCSTR file, LPCSTR parameters, LPCSTR directory, INT showCmd);
/* === END shellapi.h === */
/* === BEGIN wincrypt.h === */
typedef struct _CRYPTOAPI_BLOB {
DWORD cbData;
BYTE* pbData;
} DATA_BLOB;
static BOOL (WINAPI *_CryptProtectData )(DATA_BLOB* dataIn, PCWSTR dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
static BOOL (WINAPI *_CryptUnprotectData)(DATA_BLOB* dataIn, PWSTR* dataDescr, PVOID entropy, PVOID reserved, PVOID promptStruct, DWORD flags, DATA_BLOB* dataOut);
/* === END wincrypt.h === */
#include <shellapi.h>
#include <wincrypt.h>
*/
/* Compatibility versions so compiling works on older Windows SDKs */
#include "../misc/windows/min-winsock2.h"
#include "../misc/windows/min-shellapi.h"
#include "../misc/windows/min-wincrypt.h"
static HANDLE heap;
const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
@ -448,28 +442,6 @@ void Platform_LoadSysFonts(void) {
/* Sanity check to ensure cc_sockaddr struct is large enough to contain all socket addresses supported by this platform */
static char sockaddr_size_check[sizeof(SOCKADDR_STORAGE) < CC_SOCKETADDR_MAXSIZE ? 1 : -1];
static int (WINAPI *_WSAStartup)(WORD versionRequested, LPWSADATA wsaData);
static int (WINAPI *_WSACleanup)(void);
static int (WINAPI *_WSAGetLastError)(void);
static int (WINAPI *_WSAStringToAddressW)(LPWSTR addressString, INT addressFamily, LPVOID protocolInfo, LPVOID address, LPINT addressLength);
static int (WINAPI *_socket)(int af, int type, int protocol);
static int (WINAPI *_closesocket)(SOCKET s);
static int (WINAPI *_connect)(SOCKET s, const struct sockaddr* name, int namelen);
static int (WINAPI *_shutdown)(SOCKET s, int how);
static int (WINAPI *_ioctlsocket)(SOCKET s, long cmd, u_long* argp);
static int (WINAPI *_getsockopt)(SOCKET s, int level, int optname, char* optval, int* optlen);
static int (WINAPI *_recv)(SOCKET s, char* buf, int len, int flags);
static int (WINAPI *_send)(SOCKET s, const char FAR * buf, int len, int flags);
static int (WINAPI *_select)(int nfds, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timeval* timeout);
static struct hostent* (WINAPI *_gethostbyname)(const char* name);
static unsigned short (WINAPI *_htons)(u_short hostshort);
static int (WINAPI *_getaddrinfo )(PCSTR nodeName, PCSTR serviceName, const ADDRINFOA* hints, PADDRINFOA* result);
static void (WINAPI* _freeaddrinfo)(PADDRINFOA addrInfo);
static INT WINAPI FallbackParseAddress(LPWSTR addressString, INT addressFamily, LPVOID protocolInfo, LPVOID address, LPINT addressLength) {
SOCKADDR_IN* addr4 = (SOCKADDR_IN*)address;
@ -565,7 +537,7 @@ static cc_result ParseHostNew(char* host, int port, cc_sockaddr* addrs, int* num
portRaw[portStr.length] = '\0';
res = _getaddrinfo(host, portRaw, &hints, &result);
if (res == EAI_NONAME) return SOCK_ERR_UNKNOWN_HOST;
if (res == WSAHOST_NOT_FOUND) return SOCK_ERR_UNKNOWN_HOST;
if (res) return res;
/* Prefer IPv4 addresses first */