mirror of
https://github.com/corda/corda.git
synced 2025-06-18 23:28:21 +00:00
throw UnknownHostException if host is not found in InetAddress.getByName
This commit is contained in:
@ -9,8 +9,8 @@
|
|||||||
details. */
|
details. */
|
||||||
|
|
||||||
#include "jni.h"
|
#include "jni.h"
|
||||||
|
#include "jni-util.h"
|
||||||
#include "avian/machine.h"
|
#include "avian/machine.h"
|
||||||
|
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
|
|
||||||
using namespace avian::classpath::sockets;
|
using namespace avian::classpath::sockets;
|
||||||
@ -88,7 +88,8 @@ Java_java_net_InetAddress_ipv4AddressForName(JNIEnv* e,
|
|||||||
if (host) {
|
if (host) {
|
||||||
return ntohl(reinterpret_cast<in_addr*>(host->h_addr_list[0])->s_addr);
|
return ntohl(reinterpret_cast<in_addr*>(host->h_addr_list[0])->s_addr);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "trouble %d\n", WSAGetLastError());
|
throwNew(e, "java/net/UnknownHostException", 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
addrinfo hints;
|
addrinfo hints;
|
||||||
@ -100,19 +101,20 @@ Java_java_net_InetAddress_ipv4AddressForName(JNIEnv* e,
|
|||||||
int r = getaddrinfo(chars, 0, &hints, &result);
|
int r = getaddrinfo(chars, 0, &hints, &result);
|
||||||
e->ReleaseStringUTFChars(name, chars);
|
e->ReleaseStringUTFChars(name, chars);
|
||||||
|
|
||||||
jint address;
|
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
address = 0;
|
throwNew(e, "java/net/UnknownHostException", 0);
|
||||||
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
address = ntohl
|
int address = ntohl
|
||||||
(reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr.s_addr);
|
(reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr.s_addr);
|
||||||
|
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
}
|
|
||||||
|
|
||||||
return address;
|
return address;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
throwNew(e, "java/lang/OutOfMemoryError", 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -291,6 +291,14 @@ public class Misc {
|
|||||||
expect(java.util.Arrays.equals
|
expect(java.util.Arrays.equals
|
||||||
(new byte[] { 0, 0, 0, 0 },
|
(new byte[] { 0, 0, 0, 0 },
|
||||||
java.net.InetAddress.getByName("0.0.0.0").getAddress()));
|
java.net.InetAddress.getByName("0.0.0.0").getAddress()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
java.net.InetAddress.getByName
|
||||||
|
("bs.thisdomaindoesntexistseriouslynoway");
|
||||||
|
throw new AssertionError();
|
||||||
|
} catch (java.net.UnknownHostException e) {
|
||||||
|
// cool
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class Protected { }
|
protected class Protected { }
|
||||||
|
Reference in New Issue
Block a user