786 } else { 787 caddr[10] = 0xff; 788 caddr[11] = 0xff; 789 caddr[12] = ((address >> 24) & 0xff); 790 caddr[13] = ((address >> 16) & 0xff); 791 caddr[14] = ((address >> 8) & 0xff); 792 caddr[15] = (address & 0xff); 793 } 794 } else { 795 getInet6Address_ipaddress(env, iaObj, (char *)caddr); 796 } 797 sa->sa6.sin6_port = htons(port); 798 memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr)); 799 sa->sa6.sin6_family = AF_INET6; 800 if (len != NULL) { 801 *len = sizeof(struct sockaddr_in6); 802 } 803 804 #ifdef __linux__ 805 /* 806 * On Linux if we are connecting to a link-local address 807 * we need to specify the interface in the scope_id (2.4 kernel only) 808 * 809 * If the scope was cached then we use the cached value. If not cached but 810 * specified in the Inet6Address we use that, but we first check if the 811 * address needs to be routed via the loopback interface. In this case, 812 * we override the specified value with that of the loopback interface. 813 * If no cached value exists and no value was specified by user, then 814 * we try to determine a value from the routing table. In all these 815 * cases the used value is cached for further use. 816 */ 817 if (IN6_IS_ADDR_LINKLOCAL(&sa->sa6.sin6_addr)) { 818 unsigned int cached_scope_id = 0, scope_id = 0; 819 820 if (ia6_cachedscopeidID) { 821 cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID); 822 /* if cached value exists then use it. Otherwise, check 823 * if scope is set in the address. 824 */ 825 if (!cached_scope_id) { 826 if (ia6_scopeidID) { 827 scope_id = getInet6Address_scopeid(env, iaObj); 828 } 829 if (scope_id != 0) { 830 /* check user-specified value for loopback case 831 * that needs to be overridden 832 */ 833 if (kernelIsV24() && needsLoopbackRoute(&sa->sa6.sin6_addr)) { 834 cached_scope_id = lo_scope_id; 835 (*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); 836 } 837 } else { | 786 } else { 787 caddr[10] = 0xff; 788 caddr[11] = 0xff; 789 caddr[12] = ((address >> 24) & 0xff); 790 caddr[13] = ((address >> 16) & 0xff); 791 caddr[14] = ((address >> 8) & 0xff); 792 caddr[15] = (address & 0xff); 793 } 794 } else { 795 getInet6Address_ipaddress(env, iaObj, (char *)caddr); 796 } 797 sa->sa6.sin6_port = htons(port); 798 memcpy((void *)&sa->sa6.sin6_addr, caddr, sizeof(struct in6_addr)); 799 sa->sa6.sin6_family = AF_INET6; 800 if (len != NULL) { 801 *len = sizeof(struct sockaddr_in6); 802 } 803 804 #ifdef __linux__ 805 /* 806 * On Linux if we are connecting to a 807 * 808 * - link-local address 809 * - multicast interface-local or link-local address 810 * 811 * we need to specify the interface in the scope_id. 812 * 813 * If the scope was cached then we use the cached value. If not cached but 814 * specified in the Inet6Address we use that, but we first check if the 815 * address needs to be routed via the loopback interface. In this case, 816 * we override the specified value with that of the loopback interface. 817 * If no cached value exists and no value was specified by user, then 818 * we try to determine a value from the routing table. In all these 819 * cases the used value is cached for further use. 820 */ 821 if (IN6_IS_ADDR_LINKLOCAL(&sa->sa6.sin6_addr) 822 || IN6_IS_ADDR_MC_NODELOCAL(&sa->sa6.sin6_addr) 823 || IN6_IS_ADDR_MC_LINKLOCAL(&sa->sa6.sin6_addr)) { 824 unsigned int cached_scope_id = 0, scope_id = 0; 825 826 if (ia6_cachedscopeidID) { 827 cached_scope_id = (int)(*env)->GetIntField(env, iaObj, ia6_cachedscopeidID); 828 /* if cached value exists then use it. Otherwise, check 829 * if scope is set in the address. 830 */ 831 if (!cached_scope_id) { 832 if (ia6_scopeidID) { 833 scope_id = getInet6Address_scopeid(env, iaObj); 834 } 835 if (scope_id != 0) { 836 /* check user-specified value for loopback case 837 * that needs to be overridden 838 */ 839 if (kernelIsV24() && needsLoopbackRoute(&sa->sa6.sin6_addr)) { 840 cached_scope_id = lo_scope_id; 841 (*env)->SetIntField(env, iaObj, ia6_cachedscopeidID, cached_scope_id); 842 } 843 } else { |