equal
deleted
inserted
replaced
775 */ |
775 */ |
776 JNIEXPORT int JNICALL |
776 JNIEXPORT int JNICALL |
777 NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, |
777 NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port, struct sockaddr *him, |
778 int *len, jboolean v4MappedAddress) { |
778 int *len, jboolean v4MappedAddress) { |
779 jint family; |
779 jint family; |
780 family = (*env)->GetIntField(env, iaObj, ia_familyID); |
780 family = getInetAddress_family(env, iaObj); |
781 #ifdef AF_INET6 |
781 #ifdef AF_INET6 |
782 /* needs work. 1. family 2. clean up him6 etc deallocate memory */ |
782 /* needs work. 1. family 2. clean up him6 etc deallocate memory */ |
783 if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) { |
783 if (ipv6_available() && !(family == IPv4 && v4MappedAddress == JNI_FALSE)) { |
784 struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
784 struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)him; |
785 jbyteArray ipaddress; |
785 jbyteArray ipaddress; |
787 jint address; |
787 jint address; |
788 |
788 |
789 |
789 |
790 if (family == IPv4) { /* will convert to IPv4-mapped address */ |
790 if (family == IPv4) { /* will convert to IPv4-mapped address */ |
791 memset((char *) caddr, 0, 16); |
791 memset((char *) caddr, 0, 16); |
792 address = (*env)->GetIntField(env, iaObj, ia_addressID); |
792 address = getInetAddress_addr(env, iaObj); |
793 if (address == INADDR_ANY) { |
793 if (address == INADDR_ANY) { |
794 /* we would always prefer IPv6 wildcard address |
794 /* we would always prefer IPv6 wildcard address |
795 caddr[10] = 0xff; |
795 caddr[10] = 0xff; |
796 caddr[11] = 0xff; */ |
796 caddr[11] = 0xff; */ |
797 } else { |
797 } else { |
896 if (family == IPv6) { |
896 if (family == IPv6) { |
897 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable"); |
897 JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Protocol family unavailable"); |
898 return -1; |
898 return -1; |
899 } |
899 } |
900 memset((char *) him4, 0, sizeof(struct sockaddr_in)); |
900 memset((char *) him4, 0, sizeof(struct sockaddr_in)); |
901 address = (*env)->GetIntField(env, iaObj, ia_addressID); |
901 address = getInetAddress_addr(env, iaObj); |
902 him4->sin_port = htons((short) port); |
902 him4->sin_port = htons((short) port); |
903 him4->sin_addr.s_addr = (uint32_t) htonl(address); |
903 him4->sin_addr.s_addr = (uint32_t) htonl(address); |
904 him4->sin_family = AF_INET; |
904 him4->sin_family = AF_INET; |
905 *len = sizeof(struct sockaddr_in); |
905 *len = sizeof(struct sockaddr_in); |
906 } |
906 } |