Removed
Link Here
|
1 |
--- src/network/C4NetIO.cpp.orig 2018-02-04 15:39:08 UTC |
2 |
+++ src/network/C4NetIO.cpp |
3 |
@@ -523,6 +523,11 @@ C4NetIO::HostAddress::AddressFamily C4Ne |
4 |
gen.sa_family == AF_INET6 ? IPv6 : UnknownFamily; |
5 |
} |
6 |
|
7 |
+size_t C4NetIO::HostAddress::GetAddrLen() const |
8 |
+{ |
9 |
+ return GetFamily() == IPv4 ? sizeof(sockaddr_in) : sizeof(sockaddr_in6); |
10 |
+} |
11 |
+ |
12 |
void C4NetIO::EndpointAddress::SetPort(uint16_t port) |
13 |
{ |
14 |
switch (gen.sa_family) |
15 |
@@ -1195,7 +1200,7 @@ bool C4NetIOTCP::Connect(const C4NetIO:: |
16 |
#endif |
17 |
|
18 |
// connect (async) |
19 |
- if (::connect(nsock, &addr, sizeof addr) == SOCKET_ERROR) |
20 |
+ if (::connect(nsock, &addr, addr.GetAddrLen()) == SOCKET_ERROR) |
21 |
{ |
22 |
if (!HaveWouldBlockError()) // expected |
23 |
{ |
24 |
@@ -1368,7 +1373,7 @@ C4NetIOTCP::Peer *C4NetIOTCP::Accept(SOC |
25 |
addr_t caddr = ConnectAddr; |
26 |
|
27 |
// accept incoming connection? |
28 |
- C4NetIO::addr_t addr; socklen_t iAddrSize = sizeof addr; |
29 |
+ C4NetIO::addr_t addr; socklen_t iAddrSize = addr.GetAddrLen(); |
30 |
if (nsock == INVALID_SOCKET) |
31 |
{ |
32 |
// accept from listener |
33 |
@@ -1497,7 +1502,7 @@ bool C4NetIOTCP::Listen(uint16_t inListe |
34 |
// bind listen socket |
35 |
addr_t addr = addr_t::Any; |
36 |
addr.SetPort(inListenPort); |
37 |
- if (::bind(lsock, &addr, sizeof(addr)) == SOCKET_ERROR) |
38 |
+ if (::bind(lsock, &addr, addr.GetAddrLen()) == SOCKET_ERROR) |
39 |
{ |
40 |
SetError("socket bind failed", true); |
41 |
closesocket(lsock); lsock = INVALID_SOCKET; |
42 |
@@ -2122,7 +2127,7 @@ bool C4NetIOSimpleUDP::Send(const C4NetI |
43 |
// send it |
44 |
C4NetIO::addr_t addr = rPacket.getAddr(); |
45 |
if (::sendto(sock, getBufPtr<char>(rPacket), rPacket.getSize(), 0, |
46 |
- &addr, sizeof(addr)) |
47 |
+ &addr, addr.GetAddrLen()) |
48 |
!= int(rPacket.getSize()) && |
49 |
!HaveWouldBlockError()) |
50 |
{ |