@@ -79,6 +79,8 @@ inline bool SetNonblocking(int sock) {
7979}
8080
8181struct SockAddr {
82+ sockaddr* addr () { return reinterpret_cast <sockaddr*>(&data); }
83+
8284 union {
8385# if AE_SUPPORT_IPV4 == 1
8486 struct sockaddr_in ipv4;
@@ -87,7 +89,7 @@ struct SockAddr {
8789 struct sockaddr_in6 ipv6;
8890# endif
8991 } data;
90- sockaddr* addr;
92+
9193 std::size_t size;
9294};
9395
@@ -96,18 +98,17 @@ inline SockAddr GetSockAddr(IpAddressPort const& ip_address_port) {
9698 case IpAddress::Version::kIpV4 :
9799# if AE_SUPPORT_IPV4 == 1
98100 {
99- SockAddr sock_addr;
100- sock_addr.addr = reinterpret_cast <sockaddr*>(&sock_addr.data .ipv4 );
101+ SockAddr sock_addr{};
101102 sock_addr.size = sizeof (sock_addr.data .ipv4 );
102103 auto & addr = sock_addr.data .ipv4 ;
103104
104105# ifndef __unix__
105106 addr.sin_len = sizeof (sockaddr_in);
106107# endif // __unix__
107- addr.sin_family = AF_INET;
108108 std::memcpy (&addr.sin_addr .s_addr , ip_address_port.ip .value .ipv4_value ,
109109 4 );
110110 addr.sin_port = ae::SwapToInet (ip_address_port.port );
111+ addr.sin_family = AF_INET;
111112
112113 return sock_addr;
113114 }
@@ -120,15 +121,14 @@ inline SockAddr GetSockAddr(IpAddressPort const& ip_address_port) {
120121 case IpAddress::Version::kIpV6 : {
121122# if AE_SUPPORT_IPV6 == 1
122123 SockAddr sock_addr;
123- sock_addr.addr = reinterpret_cast <sockaddr*>(&sock_addr.data .ipv6 );
124124 sock_addr.size = sizeof (sock_addr.data .ipv6 );
125125 auto & addr = sock_addr.data .ipv6 ;
126126# ifndef __unix__
127127 addr.sin6_len = sizeof (sockaddr_in6);
128128# endif // __unix__
129- addr.sin6_family = AF_INET;
130129 std::memcpy (&addr.sin6_addr , ip_address_port.ip .value .ipv6_value , 16 );
131130 addr.sin6_port = ae::SwapToInet (ip_address_port.port );
131+ addr.sin6_family = AF_INET6;
132132
133133 return sock_addr;
134134 }
@@ -207,7 +207,7 @@ void UnixTcpTransport::ConnectionAction::Connect() {
207207 }
208208
209209 auto addr = unix_tcp_internal::GetSockAddr (transport_->endpoint_ );
210- auto res = connect (socket_, addr.addr , static_cast <socklen_t >(addr.size ));
210+ auto res = connect (socket_, addr.addr () , static_cast <socklen_t >(addr.size ));
211211 if (res == -1 ) {
212212 if ((errno == EAGAIN) || (errno == EINPROGRESS)) {
213213 AE_TELED_DEBUG (" Wait connection" );
0 commit comments