///////////////////////////////////////////////////////
| 811 | |
| 812 | //////////////////////////////////////////////////////////// |
| 813 | unsigned short TcpSocket::getRemotePort() const |
| 814 | { |
| 815 | if (getNativeHandle() != priv::SocketImpl::invalidSocket()) |
| 816 | { |
| 817 | // Retrieve information about the remote end of the socket |
| 818 | sockaddr_in6 addressV6{}; |
| 819 | priv::SocketImpl::AddrLength size = sizeof(addressV6); |
| 820 | if (getpeername(getNativeHandle(), reinterpret_cast<sockaddr*>(&addressV6), &size) != -1) |
| 821 | { |
| 822 | if (addressV6.sin6_family == PF_INET6) |
| 823 | return ntohs(addressV6.sin6_port); |
| 824 | |
| 825 | if (addressV6.sin6_family == PF_INET) |
| 826 | { |
| 827 | sockaddr_in addressV4{}; |
| 828 | std::memcpy(&addressV4, &addressV6, sizeof(addressV4)); |
| 829 | return ntohs(addressV4.sin_port); |
| 830 | } |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | // We failed to retrieve the port |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | |
| 839 | //////////////////////////////////////////////////////////// |
no outgoing calls
no test coverage detected