< prev index next >

src/java.base/unix/native/libnio/ch/InheritedChannel.c

Print this page
rev 55750 : UDS support, temporary commit


  40 static int matchFamily(SOCKETADDRESS *sa) {
  41     return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
  42 }
  43 
  44 JNIEXPORT void JNICALL
  45 Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla)
  46 {
  47     /* Initialize InetAddress IDs before later use of NET_XXX functions */
  48     initInetAddressIDs(env);
  49 }
  50 
  51 JNIEXPORT jobject JNICALL
  52 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
  53 {
  54     SOCKETADDRESS sa;
  55     socklen_t len = sizeof(SOCKETADDRESS);
  56     jobject remote_ia = NULL;
  57     jint remote_port;
  58 
  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 
  65     return remote_ia;
  66 }
  67 
  68 JNIEXPORT jint JNICALL
  69 Java_sun_nio_ch_InheritedChannel_peerPort0(JNIEnv *env, jclass cla, jint fd)
  70 {
  71     SOCKETADDRESS sa;
  72     socklen_t len = sizeof(SOCKETADDRESS);
  73     jint remote_port = -1;
  74 
  75     if (getpeername(fd, &sa.sa, &len) == 0) {
  76         if (matchFamily(&sa)) {
  77             NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
  78         }
  79     }
  80 
  81     return remote_port;
  82 }
  83 
  84 JNIEXPORT jint JNICALL
  85 Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
  86 {
  87     int sotype;
  88     socklen_t arglen = sizeof(sotype);
  89     if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
  90         if (sotype == SOCK_STREAM)
  91             return sun_nio_ch_InheritedChannel_SOCK_STREAM;
  92         if (sotype == SOCK_DGRAM)
  93             return sun_nio_ch_InheritedChannel_SOCK_DGRAM;
  94     }
  95     return sun_nio_ch_InheritedChannel_UNKNOWN;
  96 }
  97 
  98 JNIEXPORT jint JNICALL
  99 Java_sun_nio_ch_InheritedChannel_dup(JNIEnv *env, jclass cla, jint fd)
 100 {
 101    int newfd = dup(fd);




  40 static int matchFamily(SOCKETADDRESS *sa) {
  41     return (sa->sa.sa_family == (ipv6_available() ? AF_INET6 : AF_INET));
  42 }
  43 
  44 JNIEXPORT void JNICALL
  45 Java_sun_nio_ch_InheritedChannel_initIDs(JNIEnv *env, jclass cla)
  46 {
  47     /* Initialize InetAddress IDs before later use of NET_XXX functions */
  48     initInetAddressIDs(env);
  49 }
  50 
  51 JNIEXPORT jobject JNICALL
  52 Java_sun_nio_ch_InheritedChannel_peerAddress0(JNIEnv *env, jclass cla, jint fd)
  53 {
  54     SOCKETADDRESS sa;
  55     socklen_t len = sizeof(SOCKETADDRESS);
  56     jobject remote_ia = NULL;
  57     jint remote_port;
  58 
  59     if (getpeername(fd, &sa.sa, &len) == 0) {
  60         // TODO: rename remote_ia variable and matchFamily method
  61         if (matchFamily(&sa)) {
  62             // TODO: move to some common function
  63             jobject inetAddress = NET_SockaddrToInetAddress(env, &sa, (int *)&remote_port);
  64             jclass isa_class = (*env)->FindClass(env, "java/net/InetSocketAddress");
  65             jmethodID isa_ctor = (*env)->GetMethodID(env, isa_class, "<init>", "(Ljava/net/InetAddress;I)V");
  66             remote_ia = (*env)->NewObject(env, isa_class, isa_ctor, inetAddress, remote_port);
  67         } else if (sa.sa.sa_family == AF_UNIX) {
  68             // TODO: move to some common function
  69             jclass usa_class = (*env)->FindClass(env, "java/net/UnixSocketAddress");
  70             jmethodID usa_ctor = (*env)->GetMethodID(env, usa_class, "<init>", "()V");
  71             remote_ia = (*env)->NewObject(env, usa_class, usa_ctor);
  72         }
  73     }
  74 
  75     return remote_ia;
















  76 }
  77 
  78 JNIEXPORT jint JNICALL
  79 Java_sun_nio_ch_InheritedChannel_soType0(JNIEnv *env, jclass cla, jint fd)
  80 {
  81     int sotype;
  82     socklen_t arglen = sizeof(sotype);
  83     if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) == 0) {
  84         if (sotype == SOCK_STREAM)
  85             return sun_nio_ch_InheritedChannel_SOCK_STREAM;
  86         if (sotype == SOCK_DGRAM)
  87             return sun_nio_ch_InheritedChannel_SOCK_DGRAM;
  88     }
  89     return sun_nio_ch_InheritedChannel_UNKNOWN;
  90 }
  91 
  92 JNIEXPORT jint JNICALL
  93 Java_sun_nio_ch_InheritedChannel_dup(JNIEnv *env, jclass cla, jint fd)
  94 {
  95    int newfd = dup(fd);


< prev index next >