net/StaticSocketAddress: replace cast operator with GetAddress()
The implicit cast operator can be very dangerous.
This commit is contained in:
parent
3441ea9844
commit
7de0a621e3
@ -159,7 +159,7 @@ OneServerSocket::Accept()
|
|||||||
StaticSocketAddress peer_address;
|
StaticSocketAddress peer_address;
|
||||||
size_t peer_address_length = sizeof(peer_address);
|
size_t peer_address_length = sizeof(peer_address);
|
||||||
int peer_fd =
|
int peer_fd =
|
||||||
accept_cloexec_nonblock(Get(), peer_address,
|
accept_cloexec_nonblock(Get(), peer_address.GetAddress(),
|
||||||
&peer_address_length);
|
&peer_address_length);
|
||||||
if (peer_fd < 0) {
|
if (peer_fd < 0) {
|
||||||
const SocketErrorMessage msg;
|
const SocketErrorMessage msg;
|
||||||
@ -306,7 +306,7 @@ ServerSocket::AddFD(int fd, Error &error)
|
|||||||
|
|
||||||
StaticSocketAddress address;
|
StaticSocketAddress address;
|
||||||
socklen_t address_length = sizeof(address);
|
socklen_t address_length = sizeof(address);
|
||||||
if (getsockname(fd, address,
|
if (getsockname(fd, address.GetAddress(),
|
||||||
&address_length) < 0) {
|
&address_length) < 0) {
|
||||||
SetSocketError(error);
|
SetSocketError(error);
|
||||||
error.AddPrefix("Failed to get socket address: ");
|
error.AddPrefix("Failed to get socket address: ");
|
||||||
|
@ -56,11 +56,11 @@ public:
|
|||||||
size);
|
size);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator struct sockaddr *() {
|
struct sockaddr *GetAddress() {
|
||||||
return reinterpret_cast<struct sockaddr *>(&address);
|
return reinterpret_cast<struct sockaddr *>(&address);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator const struct sockaddr *() const {
|
const struct sockaddr *GetAddress() const {
|
||||||
return reinterpret_cast<const struct sockaddr *>(&address);
|
return reinterpret_cast<const struct sockaddr *>(&address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user