Skip to content

Commit c156360

Browse files
committed
chore: win fix
1 parent 56bc61b commit c156360

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/core/httpmorph.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
#ifdef _WIN32
2020
#define _CRT_SECURE_NO_WARNINGS
2121
#define strcasecmp _stricmp
22+
#define strncasecmp _strnicmp
2223
#define strdup _strdup
2324
#define close closesocket
2425
#define ssize_t SSIZE_T
2526
/* Helper for snprintf size parameter (Windows uses int, POSIX uses size_t) */
2627
#define SNPRINTF_SIZE(size) ((int)(size))
28+
/* Windows select() ignores first parameter (nfds) */
29+
#define SELECT_NFDS(sockfd) 0
2730
#else
2831
#define SNPRINTF_SIZE(size) (size)
32+
/* POSIX select() needs nfds = highest fd + 1 */
33+
#define SELECT_NFDS(sockfd) ((sockfd) + 1)
2934
#endif
3035

3136
#include "../include/httpmorph.h"
@@ -778,7 +783,7 @@ static int tcp_connect(const char *host, uint16_t port, uint32_t timeout_ms,
778783
tv.tv_sec = timeout_ms / 1000;
779784
tv.tv_usec = (timeout_ms % 1000) * 1000;
780785

781-
ret = select(sockfd + 1, NULL, &write_fds, NULL, &tv);
786+
ret = select(SELECT_NFDS(sockfd), NULL, &write_fds, NULL, &tv);
782787
if (ret > 0) {
783788
/* Check if connection succeeded */
784789
int error = 0;
@@ -1593,7 +1598,7 @@ static int http2_request(SSL *ssl, const httpmorph_request_t *request,
15931598
tv.tv_sec = 5; /* 5 second timeout */
15941599
tv.tv_usec = 0;
15951600

1596-
int select_rv = select(sockfd + 1, &readfds, &writefds, NULL, &tv);
1601+
int select_rv = select(SELECT_NFDS(sockfd), &readfds, &writefds, NULL, &tv);
15971602
if (select_rv < 0) {
15981603
/* Error */
15991604
rv = -1;

src/core/io_engine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ int io_socket_create_nonblocking(int domain, int type, int protocol) {
245245
int sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
246246
#else
247247
/* macOS and Windows don't support SOCK_NONBLOCK flag */
248-
int sockfd = socket(domain, type, protocol);
248+
int sockfd = (int)socket(domain, type, protocol);
249249
if (sockfd >= 0) {
250250
#ifdef _WIN32
251251
u_long mode = 1;

src/tls/browser_profiles.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
* browser_profiles.c - Browser TLS/HTTP fingerprint profiles implementation
33
*/
44

5-
#define _POSIX_C_SOURCE 200809L
5+
#ifndef _WIN32
6+
#define _POSIX_C_SOURCE 200809L
7+
#endif
68

79
#include "browser_profiles.h"
810
#include <stdlib.h>
@@ -232,7 +234,7 @@ const browser_profile_t* browser_profile_get(const char *name) {
232234
const browser_profile_t* browser_profile_random(void) {
233235
static bool seeded = false;
234236
if (!seeded) {
235-
srand(time(NULL));
237+
srand((unsigned int)time(NULL));
236238
seeded = true;
237239
}
238240

0 commit comments

Comments
 (0)