Permalink
Browse files

Fix networking on FreeBSD (#1998)

  • Loading branch information...
Partmedia authored and lluchs committed Feb 17, 2018
1 parent e3017ba commit 0c8371f113386026bfbd534c7dd341aa7db28fba
Showing with 10 additions and 4 deletions.
  1. +9 −4 src/network/C4NetIO.cpp
  2. +1 −0 src/network/C4NetIO.h
@@ -523,6 +523,11 @@ C4NetIO::HostAddress::AddressFamily C4NetIO::HostAddress::GetFamily() const
gen.sa_family == AF_INET6 ? IPv6 : UnknownFamily;
}
size_t C4NetIO::HostAddress::GetAddrLen() const
{
return GetFamily() == IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
}
void C4NetIO::EndpointAddress::SetPort(uint16_t port)
{
switch (gen.sa_family)
@@ -1195,7 +1200,7 @@ bool C4NetIOTCP::Connect(const C4NetIO::addr_t &addr) // (mt-safe)
#endif
// connect (async)
if (::connect(nsock, &addr, sizeof addr) == SOCKET_ERROR)
if (::connect(nsock, &addr, addr.GetAddrLen()) == SOCKET_ERROR)
{
if (!HaveWouldBlockError()) // expected
{
@@ -1368,7 +1373,7 @@ C4NetIOTCP::Peer *C4NetIOTCP::Accept(SOCKET nsock, const addr_t &ConnectAddr) //
addr_t caddr = ConnectAddr;
// accept incoming connection?
C4NetIO::addr_t addr; socklen_t iAddrSize = sizeof addr;
C4NetIO::addr_t addr; socklen_t iAddrSize = addr.GetAddrLen();
if (nsock == INVALID_SOCKET)
{
// accept from listener
@@ -1497,7 +1502,7 @@ bool C4NetIOTCP::Listen(uint16_t inListenPort)
// bind listen socket
addr_t addr = addr_t::Any;
addr.SetPort(inListenPort);
if (::bind(lsock, &addr, sizeof(addr)) == SOCKET_ERROR)
if (::bind(lsock, &addr, addr.GetAddrLen()) == SOCKET_ERROR)
{
SetError("socket bind failed", true);
closesocket(lsock); lsock = INVALID_SOCKET;
@@ -2122,7 +2127,7 @@ bool C4NetIOSimpleUDP::Send(const C4NetIOPacket &rPacket)
// send it
C4NetIO::addr_t addr = rPacket.getAddr();
if (::sendto(sock, getBufPtr<char>(rPacket), rPacket.getSize(), 0,
&addr, sizeof(addr))
&addr, addr.GetAddrLen())
!= int(rPacket.getSize()) &&
!HaveWouldBlockError())
{
@@ -94,6 +94,7 @@ class C4NetIO : public StdSchedulerProc
HostAddress(const sockaddr *addr) { SetHost(addr); }
AddressFamily GetFamily() const;
size_t GetAddrLen() const;
void SetScopeId(int scopeId);
int GetScopeId() const;

0 comments on commit 0c8371f

Please sign in to comment.