src/solaris/native/java/net/Inet4AddressImpl.c
Print this page
*** 68,78 ****
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[NI_MAXHOST+1];
hostname[0] = '\0';
! if (JVM_GetHostName(hostname, NI_MAXHOST)) {
/* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost");
} else {
struct addrinfo hints, *res;
int error;
--- 68,78 ----
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[NI_MAXHOST+1];
hostname[0] = '\0';
! if (gethostname(hostname, NI_MAXHOST)) {
/* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost");
} else {
struct addrinfo hints, *res;
int error;
*** 330,340 ****
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[NI_MAXHOST+1];
hostname[0] = '\0';
! if (JVM_GetHostName(hostname, sizeof(hostname))) {
/* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost");
} else {
struct addrinfo hints, *res;
int error;
--- 330,340 ----
JNIEXPORT jstring JNICALL
Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
char hostname[NI_MAXHOST+1];
hostname[0] = '\0';
! if (gethostname(hostname, NI_MAXHOST)) {
/* Something went wrong, maybe networking is not setup? */
strcpy(hostname, "localhost");
} else {
struct addrinfo hints, *res;
int error;
*** 727,749 ****
/*
* Let's try to create a RAW socket to send ICMP packets
* This usually requires "root" privileges, so it's likely to fail.
*/
! fd = JVM_Socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (fd != -1) {
/*
* It didn't fail, so we can use ICMP_ECHO requests.
*/
return ping4(env, fd, &him, timeout, netif, ttl);
}
/*
* Can't create a raw socket, so let's try a TCP socket
*/
! fd = JVM_Socket(AF_INET, SOCK_STREAM, 0);
! if (fd == JVM_IO_ERR) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "Can't create socket");
--- 727,749 ----
/*
* Let's try to create a RAW socket to send ICMP packets
* This usually requires "root" privileges, so it's likely to fail.
*/
! fd = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
if (fd != -1) {
/*
* It didn't fail, so we can use ICMP_ECHO requests.
*/
return ping4(env, fd, &him, timeout, netif, ttl);
}
/*
* Can't create a raw socket, so let's try a TCP socket
*/
! fd = socket(AF_INET, SOCK_STREAM, 0);
! if (fd == -1) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "Can't create socket");
*** 767,789 ****
/*
* Make the socket non blocking so we can use select/poll.
*/
SET_NONBLOCKING(fd);
- /* no need to use NET_Connect as non-blocking */
him.sin_port = htons(7); /* Echo */
! connect_rv = JVM_Connect(fd, (struct sockaddr *)&him, len);
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
} else {
! int optlen;
switch (errno) {
case ENETUNREACH: /* Network Unreachable */
case EAFNOSUPPORT: /* Address Family not supported */
case EADDRNOTAVAIL: /* address is not available on the remote machine */
--- 767,788 ----
/*
* Make the socket non blocking so we can use select/poll.
*/
SET_NONBLOCKING(fd);
him.sin_port = htons(7); /* Echo */
! connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
/**
* connection established or refused immediately, either way it means
* we were able to reach the host!
*/
if (connect_rv == 0 || errno == ECONNREFUSED) {
close(fd);
return JNI_TRUE;
} else {
! socklen_t optlen = (socklen_t)sizeof(connect_rv);
switch (errno) {
case ENETUNREACH: /* Network Unreachable */
case EAFNOSUPPORT: /* Address Family not supported */
case EADDRNOTAVAIL: /* address is not available on the remote machine */
*** 809,820 ****
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
/* has connection been established? */
! optlen = sizeof(connect_rv);
! if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);
--- 808,818 ----
}
timeout = NET_Wait(env, fd, NET_WAIT_CONNECT, timeout);
if (timeout >= 0) {
/* has connection been established? */
! if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
if (connect_rv == 0 || connect_rv == ECONNREFUSED) {
close(fd);