From b200bdb5c1a79f8dc5c043d057e9874b78c8d9c9 Mon Sep 17 00:00:00 2001 From: Rozhuk Ivan Date: Tue, 23 Apr 2024 12:19:29 +0300 Subject: [PATCH] Set sin_len/un_len on BSD systems --- CMakeLists.txt | 1 + CodeLite/SocketAPI/clSocketClient.cpp | 7 +++++++ CodeLite/SocketAPI/clSocketServer.cpp | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index c42fab3d82..2c7ce6355a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,6 +118,7 @@ endif() set(IS_FREEBSD 0) if(CMAKE_SYSTEM_NAME MATCHES "^.*BSD$|DragonFly") set(IS_FREEBSD 1) + add_definitions(-D_BSD_SOURCE -DFREEBSD) endif() set(IS_NETBSD 0) set(BUILD_WXC 0) diff --git a/CodeLite/SocketAPI/clSocketClient.cpp b/CodeLite/SocketAPI/clSocketClient.cpp index 89f07f20db..5928e9bdbe 100644 --- a/CodeLite/SocketAPI/clSocketClient.cpp +++ b/CodeLite/SocketAPI/clSocketClient.cpp @@ -27,6 +27,7 @@ #include "clSocketClient.h" #ifndef _WIN32 +#include #include #include #include @@ -52,6 +53,9 @@ bool clSocketClient::ConnectLocal(const wxString& socketPath) #ifndef __WXMSW__ struct sockaddr_un server; m_socket = socket(AF_UNIX, SOCK_STREAM, 0); +#ifdef BSD /* BSD specific code. */ + server.sun_len = sizeof(struct sockaddr_un); +#endif server.sun_family = AF_UNIX; strcpy(server.sun_path, socketPath.mb_str(wxConvUTF8).data()); if(::connect(m_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_un)) < 0) { return false; } @@ -70,6 +74,9 @@ bool clSocketClient::ConnectRemote(const wxString& address, int port, bool& woul const char* ip_addr = address.mb_str(wxConvUTF8).data(); struct sockaddr_in serv_addr; +#ifdef BSD /* BSD specific code. */ + serv_addr.sin_len = sizeof(struct sockaddr_in); +#endif serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(port); diff --git a/CodeLite/SocketAPI/clSocketServer.cpp b/CodeLite/SocketAPI/clSocketServer.cpp index 81f1ebad1c..c2cc8d2515 100644 --- a/CodeLite/SocketAPI/clSocketServer.cpp +++ b/CodeLite/SocketAPI/clSocketServer.cpp @@ -27,6 +27,7 @@ #include "clSocketServer.h" #ifndef _WIN32 +#include #include #include #include @@ -60,6 +61,9 @@ int clSocketServer::CreateServer(const std::string& pipePath) // Prepare the sockaddr_in structure struct sockaddr_un server; +#ifdef BSD /* BSD specific code. */ + server.sun_len = sizeof(struct sockaddr_un); +#endif server.sun_family = AF_UNIX; strcpy(server.sun_path, pipePath.c_str()); @@ -97,6 +101,9 @@ int clSocketServer::CreateServer(const std::string& address, int port) // Prepare the sockaddr_in structure struct sockaddr_in server; +#ifdef BSD /* BSD specific code. */ + server.sin_len = sizeof(struct sockaddr_in); +#endif server.sin_family = AF_INET; #ifdef __WXMSW__ server.sin_addr.s_addr = inet_addr(address.c_str());