Skip to content

Commit dac4e66

Browse files
committed
Fix setsockopt calls for Windows compatibility
On Windows, setsockopt expects 'const char *' for the option value parameter, not 'void *'. Add WIN32-specific casts for TCP_NODELAY setsockopt calls in edge_utils.c and sn_utils.c. Made-with: Cursor
1 parent fdf8dc6 commit dac4e66

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/edge_utils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,11 @@ static ssize_t sendto_sock (n2n_edge_t *eee, const void * buf,
10741074
// if the connection is tcp, i.e. not the regular sock...
10751075
if(eee->conf.connect_tcp) {
10761076

1077+
#ifdef WIN32
1078+
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(value));
1079+
#else
10771080
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
1081+
#endif
10781082
value = 1;
10791083
#ifdef LINUX
10801084
setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
@@ -1093,7 +1097,11 @@ static ssize_t sendto_sock (n2n_edge_t *eee, const void * buf,
10931097
// if the connection is tcp, i.e. not the regular sock...
10941098
if(eee->conf.connect_tcp) {
10951099
value = 1; /* value should still be set to 1 */
1100+
#ifdef WIN32
1101+
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(value));
1102+
#else
10961103
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
1104+
#endif
10971105
#ifdef LINUX
10981106
value = 0;
10991107
setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));

src/sn_utils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ static ssize_t sendto_sock(n2n_sn_t *sss,
517517
// if the connection is tcp, i.e. not the regular sock...
518518
if((socket_fd >= 0) && (socket_fd != sss->sock)) {
519519

520+
#ifdef WIN32
521+
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(value));
522+
#else
520523
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
524+
#endif
521525
value = 1;
522526
#ifdef LINUX
523527
setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
@@ -537,7 +541,11 @@ static ssize_t sendto_sock(n2n_sn_t *sss,
537541
// if the connection is tcp, i.e. not the regular sock...
538542
if((socket_fd >= 0) && (socket_fd != sss->sock)) {
539543
value = 1; /* value should still be set to 1 */
544+
#ifdef WIN32
545+
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, (const char *)&value, sizeof(value));
546+
#else
540547
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
548+
#endif
541549
#ifdef LINUX
542550
value = 0;
543551
setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));

0 commit comments

Comments
 (0)