30 #include <fcntl.h> 31 32 #include "jni.h" 33 34 #include "jni.h" 35 #include "jni_util.h" 36 #include "net_util.h" 37 38 #include "sun_nio_ch_InheritedChannel.h" 39 40 static int matchFamily(struct sockaddr *sa) { 41 int family = sa->sa_family; 42 #ifdef AF_INET6 43 if (ipv6_available()) { 44 return (family == AF_INET6); 45 } 46 #endif 47 return (family == AF_INET); 48 } 49 50 JNIEXPORT jobject JNICALL 51 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd) 52 { 53 struct sockaddr *sa; 54 socklen_t sa_len; 55 jobject remote_ia = NULL; 56 jint remote_port; 57 58 NET_AllocSockaddr(&sa, (int *)&sa_len); 59 if (getpeername(fd, sa, &sa_len) == 0) { 60 if (matchFamily(sa)) { 61 remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); 62 } 63 } 64 free((void *)sa); 65 66 return remote_ia; 67 } 68 69 | 30 #include <fcntl.h> 31 32 #include "jni.h" 33 34 #include "jni.h" 35 #include "jni_util.h" 36 #include "net_util.h" 37 38 #include "sun_nio_ch_InheritedChannel.h" 39 40 static int matchFamily(struct sockaddr *sa) { 41 int family = sa->sa_family; 42 #ifdef AF_INET6 43 if (ipv6_available()) { 44 return (family == AF_INET6); 45 } 46 #endif 47 return (family == AF_INET); 48 } 49 50 JNIEXPORT void JNICALL 51 Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla) 52 { 53 /* Initialize InetAddress IDs before later use of NET_XXX functions */ 54 initInetAddressIDs(env); 55 } 56 57 JNIEXPORT jobject JNICALL 58 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd) 59 { 60 struct sockaddr *sa; 61 socklen_t sa_len; 62 jobject remote_ia = NULL; 63 jint remote_port; 64 65 NET_AllocSockaddr(&sa, (int *)&sa_len); 66 if (getpeername(fd, sa, &sa_len) == 0) { 67 if (matchFamily(sa)) { 68 remote_ia = NET_SockaddrToInetAddress(env, sa, (int *)&remote_port); 69 } 70 } 71 free((void *)sa); 72 73 return remote_ia; 74 } 75 76 |