This commit is contained in:
Phil Race 2018-07-19 10:17:22 -07:00
commit 28e828130d
129 changed files with 2316 additions and 591 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,8 @@
package com.sun.crypto.provider;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import javax.crypto.IllegalBlockSizeException;
import static com.sun.crypto.provider.AESConstants.AES_BLOCK_SIZE;
@ -68,6 +70,15 @@ final class GCTR extends CounterMode {
return "GCTR";
}
// return the number of blocks until the lower 32 bits roll over
private long blocksUntilRollover() {
ByteBuffer buf = ByteBuffer.wrap(counter, counter.length - 4, 4);
buf.order(ByteOrder.BIG_ENDIAN);
long ctr32 = 0xFFFFFFFFL & buf.getInt();
long blocksLeft = (1L << 32) - ctr32;
return blocksLeft;
}
// input must be multiples of 128-bit blocks when calling update
int update(byte[] in, int inOfs, int inLen, byte[] out, int outOfs) {
if (inLen - inOfs > in.length) {
@ -80,7 +91,25 @@ final class GCTR extends CounterMode {
throw new RuntimeException("output buffer too small");
}
return encrypt(in, inOfs, inLen, out, outOfs);
long blocksLeft = blocksUntilRollover();
int numOfCompleteBlocks = inLen / AES_BLOCK_SIZE;
if (numOfCompleteBlocks >= blocksLeft) {
// Counter Mode encryption cannot be used because counter will
// roll over incorrectly. Use GCM-specific code instead.
byte[] encryptedCntr = new byte[AES_BLOCK_SIZE];
for (int i = 0; i < numOfCompleteBlocks; i++) {
embeddedCipher.encryptBlock(counter, 0, encryptedCntr, 0);
for (int n = 0; n < AES_BLOCK_SIZE; n++) {
int index = (i * AES_BLOCK_SIZE + n);
out[outOfs + index] =
(byte) ((in[inOfs + index] ^ encryptedCntr[n]));
}
GaloisCounterMode.increment32(counter);
}
return inLen;
} else {
return encrypt(in, inOfs, inLen, out, outOfs);
}
}
// input can be arbitrary size when calling doFinal

View file

@ -33,7 +33,6 @@ import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEParameterSpec;
import sun.security.util.HexDumpEncoder;
import sun.security.util.*;
/**
@ -260,21 +259,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
String kdfAlgo = null;
String cipherAlgo = null;
DerValue pBES2Algorithms = new DerValue(encoded);
if (pBES2Algorithms.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 SEQUENCE tag");
}
if (!pkcs5PBES2_OID.equals(pBES2Algorithms.data.getOID())) {
throw new IOException("PBE parameter parsing error: "
+ "expecting the object identifier for PBES2");
}
if (pBES2Algorithms.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 SEQUENCE tag");
}
DerValue pBES2_params = pBES2Algorithms.data.getDerValue();
DerValue pBES2_params = new DerValue(encoded);
if (pBES2_params.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 SEQUENCE tag");
@ -293,7 +278,6 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
@SuppressWarnings("deprecation")
private String parseKDF(DerValue keyDerivationFunc) throws IOException {
String kdfAlgo = null;
if (!pkcs5PBKDF2_OID.equals(keyDerivationFunc.data.getOID())) {
throw new IOException("PBE parameter parsing error: "
@ -318,34 +302,41 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
+ "not an ASN.1 OCTET STRING tag");
}
iCount = pBKDF2_params.data.getInteger();
DerValue keyLength = pBKDF2_params.data.getDerValue();
if (keyLength.tag == DerValue.tag_Integer) {
keysize = keyLength.getInteger() * 8; // keysize (in bits)
}
if (pBKDF2_params.tag == DerValue.tag_Sequence) {
DerValue prf = pBKDF2_params.data.getDerValue();
kdfAlgo_OID = prf.data.getOID();
if (hmacWithSHA1_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA1";
} else if (hmacWithSHA224_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA224";
} else if (hmacWithSHA256_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA256";
} else if (hmacWithSHA384_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA384";
} else if (hmacWithSHA512_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA512";
} else {
throw new IOException("PBE parameter parsing error: "
+ "expecting the object identifier for a HmacSHA key "
+ "derivation function");
// keyLength INTEGER (1..MAX) OPTIONAL,
if (pBKDF2_params.data.available() > 0) {
DerValue keyLength = pBKDF2_params.data.getDerValue();
if (keyLength.tag == DerValue.tag_Integer) {
keysize = keyLength.getInteger() * 8; // keysize (in bits)
}
if (prf.data.available() != 0) {
// parameter is 'NULL' for all HmacSHA KDFs
DerValue parameter = prf.data.getDerValue();
if (parameter.tag != DerValue.tag_Null) {
}
// prf AlgorithmIdentifier {{PBKDF2-PRFs}} DEFAULT algid-hmacWithSHA1
String kdfAlgo = "HmacSHA1";
if (pBKDF2_params.data.available() > 0) {
if (pBKDF2_params.tag == DerValue.tag_Sequence) {
DerValue prf = pBKDF2_params.data.getDerValue();
kdfAlgo_OID = prf.data.getOID();
if (hmacWithSHA1_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA1";
} else if (hmacWithSHA224_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA224";
} else if (hmacWithSHA256_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA256";
} else if (hmacWithSHA384_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA384";
} else if (hmacWithSHA512_OID.equals(kdfAlgo_OID)) {
kdfAlgo = "HmacSHA512";
} else {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 NULL tag");
+ "expecting the object identifier for a HmacSHA key "
+ "derivation function");
}
if (prf.data.available() != 0) {
// parameter is 'NULL' for all HmacSHA KDFs
DerValue parameter = prf.data.getDerValue();
if (parameter.tag != DerValue.tag_Null) {
throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 NULL tag");
}
}
}
}
@ -399,8 +390,6 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
protected byte[] engineGetEncoded() throws IOException {
DerOutputStream out = new DerOutputStream();
DerOutputStream pBES2Algorithms = new DerOutputStream();
pBES2Algorithms.putOID(pkcs5PBES2_OID);
DerOutputStream pBES2_params = new DerOutputStream();
@ -410,7 +399,10 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
DerOutputStream pBKDF2_params = new DerOutputStream();
pBKDF2_params.putOctetString(salt); // choice: 'specified OCTET STRING'
pBKDF2_params.putInteger(iCount);
pBKDF2_params.putInteger(keysize / 8); // derived key length (in octets)
if (keysize > 0) {
pBKDF2_params.putInteger(keysize / 8); // derived key length (in octets)
}
DerOutputStream prf = new DerOutputStream();
// algorithm is id-hmacWithSHA1/SHA224/SHA256/SHA384/SHA512
@ -434,8 +426,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
}
pBES2_params.write(DerValue.tag_Sequence, encryptionScheme);
pBES2Algorithms.write(DerValue.tag_Sequence, pBES2_params);
out.write(DerValue.tag_Sequence, pBES2Algorithms);
out.write(DerValue.tag_Sequence, pBES2_params);
return out.toByteArray();
}

View file

@ -1807,6 +1807,7 @@ public class KeyStore {
keystore.load(dataStream, password);
} else {
keystore.keyStoreSpi.engineLoad(dataStream, param);
keystore.initialized = true;
}
return keystore;
}

View file

@ -106,7 +106,7 @@ public class PatternSyntaxException
}
sb.append(System.lineSeparator());
sb.append(pattern);
if (index >= 0) {
if (index >= 0 && pattern != null && index < pattern.length()) {
sb.append(System.lineSeparator());
for (int i = 0; i < index; i++) sb.append(' ');
sb.append('^');

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -87,6 +87,9 @@ public class ReflectionFactory {
private static boolean noInflation = false;
private static int inflationThreshold = 15;
// true if deserialization constructor checking is disabled
private static boolean disableSerialConstructorChecks = false;
private ReflectionFactory() {
}
@ -424,10 +427,64 @@ public class ReflectionFactory {
return generateConstructor(cl, constructorToCall);
}
/**
* Given a class, determines whether its superclass has
* any constructors that are accessible from the class.
* This is a special purpose method intended to do access
* checking for a serializable class and its superclasses
* up to, but not including, the first non-serializable
* superclass. This also implies that the superclass is
* always non-null, because a serializable class must be a
* class (not an interface) and Object is not serializable.
*
* @param cl the class from which access is checked
* @return whether the superclass has a constructor accessible from cl
*/
private boolean superHasAccessibleConstructor(Class<?> cl) {
Class<?> superCl = cl.getSuperclass();
assert Serializable.class.isAssignableFrom(cl);
assert superCl != null;
if (packageEquals(cl, superCl)) {
// accessible if any non-private constructor is found
for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
if ((ctor.getModifiers() & Modifier.PRIVATE) == 0) {
return true;
}
}
return false;
} else {
// sanity check to ensure the parent is protected or public
if ((superCl.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) == 0) {
return false;
}
// accessible if any constructor is protected or public
for (Constructor<?> ctor : superCl.getDeclaredConstructors()) {
if ((ctor.getModifiers() & (Modifier.PROTECTED | Modifier.PUBLIC)) != 0) {
return true;
}
}
return false;
}
}
/**
* Returns a constructor that allocates an instance of cl and that then initializes
* the instance by calling the no-arg constructor of its first non-serializable
* superclass. This is specified in the Serialization Specification, section 3.1,
* in step 11 of the deserialization process. If cl is not serializable, returns
* cl's no-arg constructor. If no accessible constructor is found, or if the
* class hierarchy is somehow malformed (e.g., a serializable class has no
* superclass), null is returned.
*
* @param cl the class for which a constructor is to be found
* @return the generated constructor, or null if none is available
*/
public final Constructor<?> newConstructorForSerialization(Class<?> cl) {
Class<?> initCl = cl;
while (Serializable.class.isAssignableFrom(initCl)) {
if ((initCl = initCl.getSuperclass()) == null) {
Class<?> prev = initCl;
if ((initCl = initCl.getSuperclass()) == null ||
(!disableSerialConstructorChecks && !superHasAccessibleConstructor(prev))) {
return null;
}
}
@ -653,6 +710,9 @@ public class ReflectionFactory {
}
}
disableSerialConstructorChecks =
"true".equals(props.getProperty("jdk.disableSerialConstructorChecks"));
initted = true;
}

View file

@ -2098,7 +2098,8 @@ public final class PKCS12KeyStore extends KeyStoreSpi {
RetryWithZero.run(pass -> {
// Use JCE
SecretKey skey = getPBEKey(pass);
Cipher cipher = Cipher.getInstance(algOid.toString());
Cipher cipher = Cipher.getInstance(
mapPBEParamsToAlgorithm(algOid, algParams));
cipher.init(Cipher.DECRYPT_MODE, skey, algParams);
loadSafeContents(new DerInputStream(cipher.doFinal(rawData)));
return null;

View file

@ -27,6 +27,7 @@ package sun.security.ssl;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
@ -46,6 +47,9 @@ final class PostHandshakeContext extends HandshakeContext {
"Post-handshake not supported in " + negotiatedProtocol.name);
}
this.localSupportedSignAlgs = new ArrayList<SignatureScheme>(
context.conSession.getLocalSupportedSignatureSchemes());
handshakeConsumers = new LinkedHashMap<>(consumers);
handshakeFinished = true;
}

View file

@ -33,8 +33,11 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.Arrays;
import java.util.Optional;
import java.util.Collection;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.net.ssl.SSLPeerUnverifiedException;
import static sun.security.ssl.ClientAuthType.CLIENT_AUTH_REQUIRED;
import sun.security.ssl.ClientHello.ClientHelloMessage;
import sun.security.ssl.SSLExtension.ExtensionConsumer;
import sun.security.ssl.SSLExtension.SSLExtensionSpec;
@ -167,7 +170,7 @@ final class PreSharedKeyExtension {
int getIdsEncodedLength() {
int idEncodedLength = 0;
for(PskIdentity curId : identities) {
for (PskIdentity curId : identities) {
idEncodedLength += curId.getEncodedLength();
}
@ -190,7 +193,7 @@ final class PreSharedKeyExtension {
byte[] buffer = new byte[encodedLength];
ByteBuffer m = ByteBuffer.wrap(buffer);
Record.putInt16(m, idsEncodedLength);
for(PskIdentity curId : identities) {
for (PskIdentity curId : identities) {
curId.writeEncoded(m);
}
Record.putInt16(m, bindersEncodedLength);
@ -220,7 +223,7 @@ final class PreSharedKeyExtension {
String identitiesString() {
StringBuilder result = new StringBuilder();
for(PskIdentity curId : identities) {
for (PskIdentity curId : identities) {
result.append(curId.toString() + "\n");
}
@ -229,7 +232,7 @@ final class PreSharedKeyExtension {
String bindersString() {
StringBuilder result = new StringBuilder();
for(byte[] curBinder : binders) {
for (byte[] curBinder : binders) {
result.append("{" + Utilities.toHexString(curBinder) + "}\n");
}
@ -328,6 +331,7 @@ final class PreSharedKeyExtension {
public void consume(ConnectionContext context,
HandshakeMessage message,
ByteBuffer buffer) throws IOException {
ClientHelloMessage clientHello = (ClientHelloMessage) message;
ServerHandshakeContext shc = (ServerHandshakeContext)context;
// Is it a supported and enabled extension?
if (!shc.sslConfig.isAvailable(SSLExtension.CH_PRE_SHARED_KEY)) {
@ -367,8 +371,7 @@ final class PreSharedKeyExtension {
int idIndex = 0;
for (PskIdentity requestedId : pskSpec.identities) {
SSLSessionImpl s = sessionCache.get(requestedId.identity);
if (s != null && s.isRejoinable() &&
s.getPreSharedKey().isPresent()) {
if (s != null && canRejoin(clientHello, shc, s)) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine("Resuming session: ", s);
}
@ -392,10 +395,68 @@ final class PreSharedKeyExtension {
// update the context
shc.handshakeExtensions.put(
SSLExtension.CH_PRE_SHARED_KEY, pskSpec);
SSLExtension.CH_PRE_SHARED_KEY, pskSpec);
}
}
private static boolean canRejoin(ClientHelloMessage clientHello,
ServerHandshakeContext shc, SSLSessionImpl s) {
boolean result = s.isRejoinable() && s.getPreSharedKey().isPresent();
// Check protocol version
if (result && s.getProtocolVersion() != shc.negotiatedProtocol) {
if (SSLLogger.isOn &&
SSLLogger.isOn("ssl,handshake,verbose")) {
SSLLogger.finest("Can't resume, incorrect protocol version");
}
result = false;
}
// Validate the required client authentication.
if (result &&
(shc.sslConfig.clientAuthType == CLIENT_AUTH_REQUIRED)) {
try {
s.getPeerPrincipal();
} catch (SSLPeerUnverifiedException e) {
if (SSLLogger.isOn &&
SSLLogger.isOn("ssl,handshake,verbose")) {
SSLLogger.finest(
"Can't resume, " +
"client authentication is required");
}
result = false;
}
// Make sure the list of supported signature algorithms matches
Collection<SignatureScheme> sessionSigAlgs =
s.getLocalSupportedSignatureSchemes();
if (result &&
!shc.localSupportedSignAlgs.containsAll(sessionSigAlgs)) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine("Can't resume. Session uses different " +
"signature algorithms");
}
result = false;
}
}
// Ensure cipher suite can be negotiated
if (result && (!shc.isNegotiable(s.getSuite()) ||
!clientHello.cipherSuites.contains(s.getSuite()))) {
if (SSLLogger.isOn &&
SSLLogger.isOn("ssl,handshake,verbose")) {
SSLLogger.finest(
"Can't resume, unavailable session cipher suite");
}
result = false;
}
return result;
}
private static final
class CHPreSharedKeyUpdate implements HandshakeConsumer {
// Prevent instantiation of this class.
@ -547,6 +608,18 @@ final class PreSharedKeyExtension {
return null;
}
// Make sure the list of supported signature algorithms matches
Collection<SignatureScheme> sessionSigAlgs =
chc.resumingSession.getLocalSupportedSignatureSchemes();
if (!chc.localSupportedSignAlgs.containsAll(sessionSigAlgs)) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
SSLLogger.fine("Existing session uses different " +
"signature algorithms");
}
return null;
}
// The session must have a pre-shared key
Optional<SecretKey> pskOpt = chc.resumingSession.getPreSharedKey();
if (!pskOpt.isPresent()) {
if (SSLLogger.isOn && SSLLogger.isOn("ssl,handshake")) {
@ -658,7 +731,7 @@ final class PreSharedKeyExtension {
} catch (NoSuchAlgorithmException | InvalidKeyException ex) {
throw new IOException(ex);
}
} catch(GeneralSecurityException ex) {
} catch (GeneralSecurityException ex) {
throw new IOException(ex);
}
}

View file

@ -96,7 +96,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
private boolean invalidated;
private X509Certificate[] localCerts;
private PrivateKey localPrivateKey;
private final String[] localSupportedSignAlgs;
private final Collection<SignatureScheme> localSupportedSignAlgs;
private String[] peerSupportedSignAlgs; // for certificate
private boolean useDefaultPeerSignAlgs = false;
private List<byte[]> statusResponses;
@ -144,7 +144,7 @@ final class SSLSessionImpl extends ExtendedSSLSession {
this.sessionId = new SessionId(false, null);
this.host = null;
this.port = -1;
this.localSupportedSignAlgs = new String[0];
this.localSupportedSignAlgs = Collections.emptySet();
this.serverNameIndication = null;
this.requestedServerNames = Collections.<SNIServerName>emptyList();
this.useExtendedMasterSecret = false;
@ -179,8 +179,9 @@ final class SSLSessionImpl extends ExtendedSSLSession {
this.sessionId = id;
this.host = hc.conContext.transport.getPeerHost();
this.port = hc.conContext.transport.getPeerPort();
this.localSupportedSignAlgs =
SignatureScheme.getAlgorithmNames(hc.localSupportedSignAlgs);
this.localSupportedSignAlgs = hc.localSupportedSignAlgs == null ?
Collections.emptySet() :
Collections.unmodifiableCollection(hc.localSupportedSignAlgs);
this.serverNameIndication = hc.negotiatedServerName;
this.requestedServerNames = Collections.<SNIServerName>unmodifiableList(
hc.getRequestedServerNames());
@ -969,16 +970,20 @@ final class SSLSessionImpl extends ExtendedSSLSession {
}
/**
* Gets an array of supported signature algorithms that the local side is
* willing to verify.
* Gets an array of supported signature algorithm names that the local
* side is willing to verify.
*/
@Override
public String[] getLocalSupportedSignatureAlgorithms() {
if (localSupportedSignAlgs != null) {
return localSupportedSignAlgs.clone();
}
return SignatureScheme.getAlgorithmNames(localSupportedSignAlgs);
}
return new String[0];
/**
* Gets an array of supported signature schemes that the local side is
* willing to verify.
*/
public Collection<SignatureScheme> getLocalSupportedSignatureSchemes() {
return localSupportedSignAlgs;
}
/**

View file

@ -393,6 +393,13 @@ class TransportContext implements ConnectionContext, Closeable {
}
void setUseClientMode(boolean useClientMode) {
// Once handshaking has begun, the mode can not be reset for the
// life of this engine.
if (handshakeContext != null || isNegotiated) {
throw new IllegalArgumentException(
"Cannot change mode after SSL traffic has started");
}
/*
* If we need to change the client mode and the enabled
* protocols and cipher suites haven't specifically been
@ -400,13 +407,6 @@ class TransportContext implements ConnectionContext, Closeable {
* default ones.
*/
if (sslConfig.isClientMode != useClientMode) {
// Once handshaking has begun, the mode can not be reset for the
// life of this engine.
if (handshakeContext != null || isNegotiated) {
throw new IllegalArgumentException(
"Cannot change mode after SSL traffic has started");
}
if (sslContext.isDefaultProtocolVesions(
sslConfig.enabledProtocols)) {
sslConfig.enabledProtocols =

View file

@ -297,6 +297,22 @@ JNU_NotifyAll(JNIEnv *env, jobject object);
} \
} while (0) \
#define CHECK_NULL_THROW_NPE(env, x, msg) \
do { \
if ((x) == NULL) { \
JNU_ThrowNullPointerException((env), (msg));\
return; \
} \
} while(0) \
#define CHECK_NULL_THROW_NPE_RETURN(env, x, msg, z)\
do { \
if ((x) == NULL) { \
JNU_ThrowNullPointerException((env), (msg));\
return (z); \
} \
} while(0) \
#define CHECK_NULL_RETURN(x, y) \
do { \
if ((x) == NULL) { \

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -171,32 +171,38 @@ jboolean setInet6Address_ipaddress(JNIEnv *env, jobject iaObj, char *address) {
void setInetAddress_addr(JNIEnv *env, jobject iaObj, int address) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetIntField(env, holder, iac_addressID, address);
}
void setInetAddress_family(JNIEnv *env, jobject iaObj, int family) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetIntField(env, holder, iac_familyID, family);
}
void setInetAddress_hostName(JNIEnv *env, jobject iaObj, jobject host) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE(env, holder, "InetAddress holder is null");
(*env)->SetObjectField(env, holder, iac_hostNameID, host);
(*env)->SetObjectField(env, holder, iac_origHostNameID, host);
}
int getInetAddress_addr(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
return (*env)->GetIntField(env, holder, iac_addressID);
}
int getInetAddress_family(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", -1);
return (*env)->GetIntField(env, holder, iac_familyID);
}
jobject getInetAddress_hostName(JNIEnv *env, jobject iaObj) {
jobject holder = (*env)->GetObjectField(env, iaObj, ia_holderID);
CHECK_NULL_THROW_NPE_RETURN(env, holder, "InetAddress holder is null", NULL);
return (*env)->GetObjectField(env, holder, iac_hostNameID);
}
@ -211,7 +217,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port) {
CHECK_NULL_RETURN(iaObj, NULL);
address = NET_IPv4MappedToIPv4(caddr);
setInetAddress_addr(env, iaObj, address);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
} else {
jboolean ret;
iaObj = (*env)->NewObject(env, ia6_class, ia6_ctrID);
@ -220,6 +228,7 @@ NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port) {
if (ret == JNI_FALSE)
return NULL;
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv6);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
setInet6Address_scopeid(env, iaObj, sa->sa6.sin6_scope_id);
}
*port = ntohs(sa->sa6.sin6_port);
@ -227,7 +236,9 @@ NET_SockaddrToInetAddress(JNIEnv *env, SOCKETADDRESS *sa, int *port) {
iaObj = (*env)->NewObject(env, ia4_class, ia4_ctrID);
CHECK_NULL_RETURN(iaObj, NULL);
setInetAddress_family(env, iaObj, java_net_InetAddress_IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
setInetAddress_addr(env, iaObj, ntohl(sa->sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
*port = ntohs(sa->sa4.sin_port);
}
return iaObj;
@ -238,6 +249,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj)
{
jint family = getInetAddress_family(env, iaObj) ==
java_net_InetAddress_IPv4 ? AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (sa->sa.sa_family == AF_INET6) {
jbyte *caddrNew = (jbyte *)&sa->sa6.sin6_addr;
if (NET_IsIPv4Mapped(caddrNew)) {
@ -247,6 +259,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj)
}
addrNew = NET_IPv4MappedToIPv4(caddrNew);
addrCur = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (addrNew == addrCur) {
return JNI_TRUE;
} else {
@ -273,6 +286,7 @@ NET_SockaddrEqualsInetAddress(JNIEnv *env, SOCKETADDRESS *sa, jobject iaObj)
}
addrNew = ntohl(sa->sa4.sin_addr.s_addr);
addrCur = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, JNI_FALSE);
if (addrNew == addrCur) {
return JNI_TRUE;
} else {

View file

@ -739,13 +739,13 @@ ZIP_Open_Generic(const char *name, char **pmsg, int mode, jlong lastModified)
jzfile *zip = NULL;
/* Clear zip error message */
if (pmsg != 0) {
if (pmsg != NULL) {
*pmsg = NULL;
}
zip = ZIP_Get_From_Cache(name, pmsg, lastModified);
if (zip == NULL && *pmsg == NULL) {
if (zip == NULL && pmsg != NULL && *pmsg == NULL) {
ZFILE zfd = ZFILE_Open(name, mode);
zip = ZIP_Put_In_Cache(name, zfd, pmsg, lastModified);
}

View file

@ -193,7 +193,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in *)
(iterator->ai_addr))->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, i++, iaObj);
iterator = iterator->ai_next;
}

View file

@ -198,6 +198,8 @@ lookupIfLocalhost(JNIEnv *env, const char *hostname, jboolean includeV6)
return NULL;
}
setInetAddress_hostName(env, o, name);
if ((*env)->ExceptionCheck(env))
goto done;
(*env)->SetObjectArrayElement(env, result, index, o);
(*env)->DeleteLocalRef(env, o);
}
@ -355,7 +357,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
inetIndex++;
} else if (iterator->ai_family == AF_INET6) {
@ -376,6 +382,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
setInet6Address_scopeid(env, iaObj, scope);
}
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index++;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -329,11 +329,11 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
(JNIEnv *env, jclass cls, jobject iaObj)
{
netif *ifs, *curr;
int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ?
AF_INET : AF_INET6;
jobject obj = NULL;
jboolean match = JNI_FALSE;
int family = (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) ?
AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
ifs = enumInterfaces(env);
if (ifs == NULL) {
return NULL;
@ -351,7 +351,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
int address1 = htonl(
((struct sockaddr_in *)addrP->addr)->sin_addr.s_addr);
int address2 = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (address1 == address2) {
match = JNI_TRUE;
break;
@ -698,6 +698,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
if (iaObj) {
setInetAddress_addr(env, iaObj, htonl(
((struct sockaddr_in*)addrP->addr)->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
} else {
return NULL;
}
@ -710,6 +711,7 @@ static jobject createNetworkInterface(JNIEnv *env, netif *ifs) {
if (ia2Obj) {
setInetAddress_addr(env, ia2Obj, htonl(
((struct sockaddr_in*)addrP->brdcast)->sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ib4broadcastID, ia2Obj);
} else {
return NULL;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -531,9 +531,12 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
iaObj = NET_SockaddrToInetAddress(env, &rmtaddr, &port);
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (family == AF_INET) { /* this API can't handle IPV6 addresses */
int address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
setInetAddress_addr(env, addressObj, address);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
}
return port;
}
@ -1014,6 +1017,7 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
struct in_addr in;
jobjectArray addrArray;
jsize len;
jint family;
jobject addr;
int i;
@ -1044,8 +1048,11 @@ static void mcast_set_if_by_if_v4(JNIEnv *env, jobject this, int fd, jobject val
in.s_addr = 0;
for (i = 0; i < len; i++) {
addr = (*env)->GetObjectArrayElement(env, addrArray, i);
if (getInetAddress_family(env, addr) == java_net_InetAddress_IPv4) {
family = getInetAddress_family(env, addr);
JNU_CHECK_EXCEPTION(env);
if (family == java_net_InetAddress_IPv4) {
in.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
break;
}
}
@ -1095,7 +1102,7 @@ static void mcast_set_if_by_addr_v4(JNIEnv *env, jobject this, int fd, jobject v
struct in_addr in;
in.s_addr = htonl( getInetAddress_addr(env, value) );
JNU_CHECK_EXCEPTION(env);
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
(const char*)&in, sizeof(in)) < 0) {
JNU_ThrowByNameWithMessageAndLastError
@ -1458,6 +1465,7 @@ jobject getMulticastInterface(JNIEnv *env, jobject this, int fd, jint opt) {
CHECK_NULL_RETURN(addr, NULL);
setInetAddress_addr(env, addr, ntohl(in.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
/*
* For IP_MULTICAST_IF return InetAddress
@ -1890,6 +1898,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
jint fd;
jint family;
jint ipv6_join_leave;
if (IS_NULL(fdObj)) {
@ -1910,7 +1919,9 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
ipv6_join_leave = ipv6_available();
#ifdef __linux__
if (getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4) {
family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION(env);
if (family == java_net_InetAddress_IPv4) {
ipv6_join_leave = JNI_FALSE;
}
#endif
@ -1951,6 +1962,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
}
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname.imr_address.s_addr = 0;
mname.imr_ifindex = (*env)->GetIntField(env, niObj, ni_indexID);
mname_len = sizeof(struct ip_mreqn);
@ -1969,11 +1981,14 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
addr = (*env)->GetObjectArrayElement(env, addrArray, 0);
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
#ifdef __linux__
mname.imr_address.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
mname.imr_ifindex = 0;
#else
mname.imr_interface.s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION(env);
#endif
mname_len = sizeof(struct ip_mreq);
}
@ -2009,6 +2024,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
}
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname.imr_address.s_addr = 0 ;
mname.imr_ifindex = index;
mname_len = sizeof(struct ip_mreqn);
@ -2031,6 +2047,7 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
mname.imr_interface.s_addr = in.s_addr;
#endif
mname.imr_multiaddr.s_addr = htonl(getInetAddress_addr(env, iaObj));
JNU_CHECK_EXCEPTION(env);
mname_len = sizeof(struct ip_mreq);
}
}
@ -2097,10 +2114,11 @@ static void mcast_join_leave(JNIEnv *env, jobject this,
jint address;
family = getInetAddress_family(env, iaObj) == java_net_InetAddress_IPv4 ?
AF_INET : AF_INET6;
JNU_CHECK_EXCEPTION(env);
if (family == AF_INET) { /* will convert to IPv4-mapped address */
memset((char *) caddr, 0, 16);
address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION(env);
caddr[10] = 0xff;
caddr[11] = 0xff;

View file

@ -764,6 +764,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
jboolean v4MappedAddress)
{
jint family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
memset((char *)sa, 0, sizeof(SOCKETADDRESS));
if (ipv6_available() &&
@ -777,6 +778,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
// convert to IPv4-mapped address
memset((char *)caddr, 0, 16);
address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address
* caddr[10] = 0xff;
@ -871,6 +873,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
return -1;
}
address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
sa->sa4.sin_port = htons(port);
sa->sa4.sin_addr.s_addr = htonl(address);
sa->sa4.sin_family = AF_INET;

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -146,7 +146,11 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in *)
(iterator->ai_addr))->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, i++, iaObj);
iterator = iterator->ai_next;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -187,7 +187,11 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
goto cleanupAndReturn;
}
setInetAddress_addr(env, iaObj, ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inetIndex | originalIndex), iaObj);
inetIndex++;
} else if (iterator->ai_family == AF_INET6) {
@ -208,6 +212,8 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
setInet6Address_scopeid(env, iaObj, scope);
}
setInetAddress_hostName(env, iaObj, host);
if ((*env)->ExceptionCheck(env))
goto cleanupAndReturn;
(*env)->SetObjectArrayElement(env, ret, (inet6Index | originalIndex), iaObj);
inet6Index++;
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -586,6 +586,7 @@ jobject createNetworkInterface
/* default ctor will set family to AF_INET */
setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
if (addrs->mask != -1) {
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
if (ibObj == NULL) {
@ -599,6 +600,7 @@ jobject createNetworkInterface
return NULL;
}
setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);
@ -754,8 +756,9 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
(JNIEnv *env, jclass cls, jobject iaObj)
{
netif *ifList, *curr;
jint addr = getInetAddress_addr(env, iaObj);
jobject netifObj = NULL;
jint addr = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
if (ipv6_available()) {

View file

@ -584,7 +584,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
/* default ctor will set family to AF_INET */
setInetAddress_addr(env, iaObj, ntohl(addrs->addr.sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
ibObj = (*env)->NewObject(env, ni_ibcls, ni_ibctrID);
if (ibObj == NULL) {
free_netaddr(netaddrP);
@ -597,6 +597,7 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
return NULL;
}
setInetAddress_addr(env, ia2Obj, ntohl(addrs->brdcast.sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
(*env)->SetObjectField(env, ibObj, ni_ibbroadcastID, ia2Obj);
(*env)->SetShortField(env, ibObj, ni_ibmaskID, addrs->mask);
(*env)->SetObjectArrayElement(env, bindsArr, bind_index++, ibObj);

View file

@ -219,16 +219,16 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_bind0(JNIEnv *env, jobject this,
jobject fd1Obj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
int ipv6_supported = ipv6_available();
int fd, fd1 = -1, lcladdrlen = 0;
jint family;
SOCKETADDRESS lcladdr;
if (getInetAddress_family(env, addressObj) == java_net_InetAddress_IPv6 &&
!ipv6_supported)
{
family = getInetAddress_family(env, addressObj);
JNU_CHECK_EXCEPTION(env);
if (family == java_net_InetAddress_IPv6 && !ipv6_supported) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported");
return;
}
if (IS_NULL(fdObj) || (ipv6_supported && IS_NULL(fd1Obj))) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "socket closed");
return;
@ -344,6 +344,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_connect0
}
family = getInetAddress_family(env, address);
JNU_CHECK_EXCEPTION(env);
if (family == java_net_InetAddress_IPv6 && !ipv6_available()) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Protocol family not supported");
@ -455,6 +456,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_send
}
family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION(env);
if (family == java_net_InetAddress_IPv4) {
fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
} else {
@ -584,6 +586,7 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
return -1;
} else {
address = getInetAddress_addr(env, addressObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
/* We only handle IPv4 for now. Will support IPv6 once its in the os */
family = AF_INET;
}
@ -657,7 +660,9 @@ Java_java_net_TwoStacksPlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
return 0;
}
setInetAddress_addr(env, addressObj, ntohl(remote_addr.sa4.sin_addr.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, -1);
setInetAddress_family(env, addressObj, java_net_InetAddress_IPv4);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
/* return port */
return ntohs(remote_addr.sa4.sin_port);
@ -1349,6 +1354,7 @@ static int getInetAddrFromIf (JNIEnv *env, int family, jobject nif, jobject *iad
int fam;
addr = (*env)->GetObjectArrayElement(env, addrArray, i);
fam = getInetAddress_family(env, addr);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (fam == family) {
*iaddr = addr;
return 0;
@ -1367,6 +1373,7 @@ static int getInet4AddrFromIf (JNIEnv *env, jobject nif, struct in_addr *iaddr)
}
iaddr->s_addr = htonl(getInetAddress_addr(env, addr));
JNU_CHECK_EXCEPTION_RETURN(env, -1);
return 0;
}
@ -1471,6 +1478,7 @@ static void setMulticastInterface(JNIEnv *env, jobject this, int fd, int fd1,
struct in_addr in;
in.s_addr = htonl(getInetAddress_addr(env, value));
JNU_CHECK_EXCEPTION(env);
if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_IF,
(const char*)&in, sizeof(in)) < 0) {
JNU_ThrowByNameWithMessageAndLastError
@ -1712,7 +1720,7 @@ static jobject getIPv4NetworkInterface (JNIEnv *env, jobject this, int fd, jint
CHECK_NULL_RETURN(addr, NULL);
setInetAddress_addr(env, addr, ntohl(in.s_addr));
JNU_CHECK_EXCEPTION_RETURN(env, NULL);
/*
* For IP_MULTICAST_IF return InetAddress
*/

View file

@ -794,6 +794,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
jboolean v4MappedAddress)
{
jint family = getInetAddress_family(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
memset((char *)sa, 0, sizeof(SOCKETADDRESS));
if (ipv6_available() &&
@ -808,6 +809,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
// convert to IPv4-mapped address
memset((char *)caddr, 0, 16);
address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (address == INADDR_ANY) {
/* we would always prefer IPv6 wildcard address
* caddr[10] = 0xff;
@ -846,6 +848,7 @@ NET_InetAddressToSockaddr(JNIEnv *env, jobject iaObj, int port,
return -1;
}
address = getInetAddress_addr(env, iaObj);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
sa->sa4.sin_port = htons((short)port);
sa->sa4.sin_addr.s_addr = (u_long)htonl(address);
sa->sa4.sin_family = AF_INET;