add addressPort

This commit is contained in:
Brenton Bostick 2023-02-02 13:38:19 -05:00
parent 40d5f9b5d2
commit 30cfe65b39
2 changed files with 31 additions and 0 deletions

View File

@ -142,6 +142,36 @@ jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr)
return inetAddressObj;
}
int addressPort(const sockaddr_storage addr) {
int port = 0;
switch(addr.ss_family)
{
case AF_INET6:
{
LOGV("IPV6 Address");
sockaddr_in6 *ipv6 = (sockaddr_in6*)&addr;
port = ntohs(ipv6->sin6_port);
LOGV("Port %d", port);
}
break;
case AF_INET:
{
LOGV("IPV4 Address");
sockaddr_in *ipv4 = (sockaddr_in*)&addr;
port = ntohs(ipv4->sin_port);
LOGV("Port: %d", port);
}
break;
default:
{
assert(false && "addr.ss_family is neither AF_INET6 nor AF_INET");
}
}
return port;
}
jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr)
{
LOGV("newInetSocketAddress Called");

View File

@ -88,6 +88,7 @@ jobject createVirtualNetworkConfigOperation(JNIEnv *env, ZT_VirtualNetworkConfig
jobject newInetSocketAddress(JNIEnv *env, const sockaddr_storage &addr);
jobject newInetAddress(JNIEnv *env, const sockaddr_storage &addr);
int addressPort(const sockaddr_storage addr);
jobject newPeer(JNIEnv *env, const ZT_Peer &peer);
jobject newPeerPhysicalPath(JNIEnv *env, const ZT_PeerPhysicalPath &ppp);