Skip to content

Commit

Permalink
Set sin_len/un_len on BSD systems (#3356)
Browse files Browse the repository at this point in the history
  • Loading branch information
rozhuk-im committed May 14, 2024
1 parent b7e7f14 commit 24250b5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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)
Expand Down
7 changes: 7 additions & 0 deletions CodeLite/SocketAPI/clSocketClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "clSocketClient.h"

#ifndef _WIN32
#include <sys/param.h>
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
Expand All @@ -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; }
Expand All @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions CodeLite/SocketAPI/clSocketServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "clSocketServer.h"

#ifndef _WIN32
#include <sys/param.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 24250b5

Please sign in to comment.