ByteArray* Java_java_net_NetworkInterface_getIpv6Addresses(Env* env, JClass* cls, Object* interfaceName) {
    const char* name = rvmGetStringUTFChars(env, interfaceName);
    if (!name) {
        return NULL;
    }
    jint count = 0;
    if (!iterateAddrInfo(env, name, countIpv6AddressesIterator, &count)) {
        return NULL;
    }

    if (count == 0) {
        return NULL;
    }

    ByteArray* result = rvmNewByteArray(env, 16 * 2 * count);
    if (!result) {
        return NULL;
    }

    GetIpv6AddressesData data = {result, 0};
    if (!iterateAddrInfo(env, name, getIpv6AddressesIterator, &data)) {
        return NULL;
    }
    return result;
}
Пример #2
0
ByteArray* Java_aura_rt_VM_newByteArray(Env* env, Class* c, jlong address, jint size) {
    ByteArray* array = rvmNewByteArray(env, size);
    if (array) {
        memcpy(array->values, LONG_TO_PTR(address), size * sizeof(jbyte));
    }
    return array;
}
static jboolean getHardwareAddressIterator(Env* env, struct ifaddrs *ia, void* data) {
    ByteArray** resultPtr = (ByteArray**) data;
    if (ia->ifa_addr->sa_family == AF_LINK) {
        struct sockaddr_dl* addr = (struct sockaddr_dl*) ia->ifa_addr;
        if (addr->sdl_alen == 6) {
            char* bytes = (char*) LLADDR(addr);
            *resultPtr = rvmNewByteArray(env, 6);
            if (*resultPtr) {
                memcpy((*resultPtr)->values, bytes, 6);
            }
            return FALSE; // Stop iteration
        }
    }
    return TRUE; // Continue iteration
}
Пример #4
0
ByteArray* Java_aura_rt_VM_getRuntimeData0(Env* env, Class* c) {
    Options* options = env->vm->options;
    if (!options->runtimeData) {
        return NULL;
    }
    void* p = options->runtimeData;
    jint length = *((jint*) p);
    if (length == 0) {
        return NULL;
    }
    p += sizeof(jint);
    ByteArray* data = rvmNewByteArray(env, length);
    if (!data) {
        return NULL;
    }
    memcpy(data->values, p, length);
    return data;
}
ByteArray* Java_java_net_NetworkInterface_getHardwareAddress(Env* env, JClass* cls, Object* interfaceName) {
    const char* name = rvmGetStringUTFChars(env, interfaceName);
    if (!name) {
        return NULL;
    }
    ByteArray* result = NULL;
#if defined(DARWIN)
    // Darwin doesn't have SIOCGIFHWADDR so we need to use getifaddrs() instead.
    iterateAddrInfo(env, name, getHardwareAddressIterator, &result);
#else
    struct ifreq ifreq;
    if (!ioctl_ifreq(env, interfaceName, &ifreq, SIOCGIFHWADDR)) {
        return NULL;
    }
    if (ifreq.ifr_hwaddr.sa_family == ARPHRD_ETHER) {
        result = rvmNewByteArray(env, 6);
        if (result) {
            memcpy(result->values, ifreq.ifr_hwaddr.sa_data, 6);
        }
    }
#endif
    return result;
}
Пример #6
0
ByteArray* _bcNewByteArray(Env* env, jint length) {
    ENTER;
    ByteArray* array = rvmNewByteArray(env, length);
    LEAVE(array);
}
Пример #7
0
static jboolean parseArrayElementValue(Env* env, void** attributes, Class* arrayClass, Object* classLoader, jvalue* result) {
    jbyte tag = getByte(attributes);
    if (tag != '[') return throwFormatError(env, "Array");

    Class* componentType = arrayClass->componentType;

    jint length = getChar(attributes);
    Array* array = NULL;
    if (CLASS_IS_PRIMITIVE(componentType)) {
        switch (componentType->name[0]) {
        case 'Z':
            array = (Array*) rvmNewBooleanArray(env, length);
            break;
        case 'B':
            array = (Array*) rvmNewByteArray(env, length);
            break;
        case 'S':
            array = (Array*) rvmNewShortArray(env, length);
            break;
        case 'C':
            array = (Array*) rvmNewCharArray(env, length);
            break;
        case 'I':
            array = (Array*) rvmNewIntArray(env, length);
            break;
        case 'J':
            array = (Array*) rvmNewLongArray(env, length);
            break;
        case 'F':
            array = (Array*) rvmNewFloatArray(env, length);
            break;
        case 'D':
            array = (Array*) rvmNewDoubleArray(env, length);
            break;
        }
    } else {
        array = (Array*) rvmNewObjectArray(env, length, NULL, arrayClass, NULL);
    }
    if (!array) return FALSE;

    jint i = 0;
    for (i = 0; i < length; i++) {
        jvalue v;
        if (!parseElementValue(env, attributes, componentType, classLoader, &v)) return FALSE;
        if (CLASS_IS_PRIMITIVE(componentType)) {
            switch (componentType->name[0]) {
            case 'Z':
                ((BooleanArray*) array)->values[i] = v.z;
                break;
            case 'B':
                ((ByteArray*) array)->values[i] = v.b;
                break;
            case 'S':
                ((ShortArray*) array)->values[i] = v.s;
                break;
            case 'C':
                ((CharArray*) array)->values[i] = v.c;
                break;
            case 'I':
                ((IntArray*) array)->values[i] = v.i;
                break;
            case 'J':
                ((LongArray*) array)->values[i] = v.j;
                break;
            case 'F':
                ((FloatArray*) array)->values[i] = v.f;
                break;
            case 'D':
                ((DoubleArray*) array)->values[i] = v.d;
                break;
            }
        } else {
            ((ObjectArray*) array)->values[i] = (Object*) v.l;
        }
    }
    result->l = (jobject) array;
    return result->l ? TRUE : FALSE;
}
Пример #8
0
static jbyteArray NewByteArray(JNIEnv* env, jsize len) {
    return (jbyteArray) rvmNewByteArray((Env*) env, len);
}