3
3
// Distributed under the MIT software license, see the accompanying
4
4
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
+ #if defined(HAVE_CONFIG_H)
7
+ #include < config/bitcoin-config.h>
8
+ #endif
9
+
6
10
#include < netbase.h>
7
11
8
12
#include < compat/compat.h>
21
25
#include < limits>
22
26
#include < memory>
23
27
28
+ #if HAVE_SOCKADDR_UN
29
+ #include < sys/un.h>
30
+ #endif
31
+
24
32
// Settings
25
33
static GlobalMutex g_proxyinfo_mutex;
26
34
static Proxy proxyInfo[NET_MAX] GUARDED_BY(g_proxyinfo_mutex);
@@ -446,11 +454,16 @@ bool Socks5(const std::string& strDest, uint16_t port, const ProxyCredentials* a
446
454
447
455
std::unique_ptr<Sock> CreateSockOS (sa_family_t address_family)
448
456
{
449
- // Not IPv4 or IPv6
457
+ // Not IPv4, IPv6 or UNIX
450
458
if (address_family == AF_UNSPEC) return nullptr ;
451
459
452
- // Create a TCP socket in the address family of the specified service.
453
- SOCKET hSocket = socket (address_family, SOCK_STREAM, IPPROTO_TCP);
460
+ int protocol{IPPROTO_TCP};
461
+ #if HAVE_SOCKADDR_UN
462
+ if (address_family == AF_UNIX) protocol = 0 ;
463
+ #endif
464
+
465
+ // Create a socket in the specified address family.
466
+ SOCKET hSocket = socket (address_family, SOCK_STREAM, protocol);
454
467
if (hSocket == INVALID_SOCKET) {
455
468
return nullptr ;
456
469
}
@@ -474,17 +487,21 @@ std::unique_ptr<Sock> CreateSockOS(sa_family_t address_family)
474
487
}
475
488
#endif
476
489
477
- // Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
478
- const int on{1 };
479
- if (sock->SetSockOpt (IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) == SOCKET_ERROR) {
480
- LogPrint (BCLog::NET, " Unable to set TCP_NODELAY on a newly created socket, continuing anyway\n " );
481
- }
482
-
483
490
// Set the non-blocking option on the socket.
484
491
if (!sock->SetNonBlocking ()) {
485
492
LogPrintf (" Error setting socket to non-blocking: %s\n " , NetworkErrorString (WSAGetLastError ()));
486
493
return nullptr ;
487
494
}
495
+
496
+ #if HAVE_SOCKADDR_UN
497
+ if (address_family == AF_UNIX) return sock;
498
+ #endif
499
+
500
+ // Set the no-delay option (disable Nagle's algorithm) on the TCP socket.
501
+ const int on{1 };
502
+ if (sock->SetSockOpt (IPPROTO_TCP, TCP_NODELAY, &on, sizeof (on)) == SOCKET_ERROR) {
503
+ LogPrint (BCLog::NET, " Unable to set TCP_NODELAY on a newly created socket, continuing anyway\n " );
504
+ }
488
505
return sock;
489
506
}
490
507
0 commit comments