JNIEXPORT jint JNICALL Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd) { SOCKETADDRESS sa; socklen_t len = sizeof(SOCKETADDRESS); jint remote_port = -1; if (getpeername(fd, &sa.sa, &len) == 0) { if (matchFamily(&sa.sa)) { NET_SockaddrToInetAddress(env, &sa.sa, (int *)&remote_port); } } return remote_port; }
JNIEXPORT jint JNICALL Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd) { struct sockaddr *sa; socklen_t sa_len; jint remote_port = -1; NET_AllocSockaddr(&sa, (int *)&sa_len); if (getpeername(fd, sa, &sa_len) == 0) { if (matchFamily(sa)) { NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); } } free((void *)sa); return remote_port; }