drop non portable SOL_TCP / fix MacOS v2 (#680)

* Revert "Fix compilation on MacOS"

in order to another solution

* src: use IPPROTO_TCP in place of SOL_TCP

* use the more specific IPPROTO_TCP type for setsockopt
* fixes build on MacOS

src/edge_utils.c:891:31: error: use of undeclared identifier 'SOL_TCP'; did you mean 'FPP_TCP'?
        setsockopt(eee->sock, SOL_TCP, TCP_NODELAY, &value, sizeof(value));

src/edge_utils.c:894:31: error: use of undeclared identifier 'SOL_TCP'
        setsockopt(eee->sock, SOL_TCP, TCP_CORK, &value, sizeof(value));
                              ^
src/edge_utils.c:894:40: error: use of undeclared identifier 'TCP_CORK'
        setsockopt(eee->sock, SOL_TCP, TCP_CORK, &value, sizeof(value));

* include/n2n.h: drop redefiniton of SOL_TCP for WIN32, as we don't use it anywhere now

* src: only use TCP_CORK on LINUX

* it's LINUX only and fails on Win32 and MacOS (man 7 tcp)
This commit is contained in:
Sven Roederer 2021-04-05 19:30:53 +02:00 committed by GitHub
parent 90c2364b6d
commit 23c18e349f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 21 deletions

View File

@ -137,7 +137,6 @@
#ifdef WIN32
#include <winsock2.h> /* for tcp */
#define SHUT_RDWR SD_BOTH /* for tcp */
#define SOL_TCP IPPROTO_TCP /* for tcp */
#include "win32/wintap.h"
#include <sys/stat.h>
#else
@ -155,17 +154,11 @@
#include "sn_selection.h"
#include "network_traffic_filter.h"
/* ************************************** */
#include "header_encryption.h"
#include "tf.h"
/* ************************************** */
#if !defined(SOL_TCP) && defined(IPPROTO_TCP)
#define SOL_TCP IPPROTO_TCP
#endif
/* ************************************** */
#ifndef TRACE_ERROR
#define TRACE_ERROR 0, __FILE__, __LINE__
#define TRACE_WARNING 1, __FILE__, __LINE__

View File

@ -888,10 +888,10 @@ static ssize_t sendto_sock (n2n_edge_t *eee, const void * buf,
// if the connection is tcp, i.e. not the regular sock...
if(eee->conf.connect_tcp) {
setsockopt(eee->sock, SOL_TCP, TCP_NODELAY, &value, sizeof(value));
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
value = 1;
#if !defined(WIN32) && !defined(__APPLE__)
setsockopt(eee->sock, SOL_TCP, TCP_CORK, &value, sizeof(value));
#ifdef LINUX
setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
#endif
// prepend packet length...
@ -907,10 +907,10 @@ static ssize_t sendto_sock (n2n_edge_t *eee, const void * buf,
// if the connection is tcp, i.e. not the regular sock...
if(eee->conf.connect_tcp) {
value = 1; /* value should still be set to 1 */
setsockopt(eee->sock, SOL_TCP, TCP_NODELAY, &value, sizeof(value));
#if !defined(WIN32) && !defined(__APPLE__)
setsockopt(eee->sock, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
#ifdef LINUX
value = 0;
setsockopt(eee->sock, SOL_TCP, TCP_CORK, &value, sizeof(value));
setsockopt(eee->sock, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
#endif
}

View File

@ -149,10 +149,10 @@ static ssize_t sendto_sock(n2n_sn_t *sss,
// if the connection is tcp, i.e. not the regular sock...
if((socket_fd >= 0) && (socket_fd != sss->sock)) {
setsockopt(socket_fd, SOL_TCP, TCP_NODELAY, &value, sizeof(value));
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
value = 1;
#if !defined(WIN32) && !defined(__APPLE__)
setsockopt(socket_fd, SOL_TCP, TCP_CORK, &value, sizeof(value));
#ifdef LINUX
setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
#endif
// prepend packet length...
@ -169,10 +169,10 @@ static ssize_t sendto_sock(n2n_sn_t *sss,
// if the connection is tcp, i.e. not the regular sock...
if((socket_fd >= 0) && (socket_fd != sss->sock)) {
value = 1; /* value should still be set to 1 */
setsockopt(socket_fd, SOL_TCP, TCP_NODELAY, &value, sizeof(value));
#if !defined(WIN32) && !defined(__APPLE__)
setsockopt(socket_fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value));
#ifdef LINUX
value = 0;
setsockopt(socket_fd, SOL_TCP, TCP_CORK, &value, sizeof(value));
setsockopt(socket_fd, IPPROTO_TCP, TCP_CORK, &value, sizeof(value));
#endif
}