/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include <windows.h>
#include <winsock2.h>
#include "jni.h"
#include "net_util.h"
#include "java_net_DualStackPlainDatagramSocketImpl.h"
/*
* This function "purges" all outstanding ICMP port unreachable packets
* outstanding on a socket and returns JNI_TRUE if any ICMP messages
* have been purged. The rational for purging is to emulate normal BSD
* behaviour whereby receiving a "connection reset" status resets the
* socket.
*/
{
struct timeval t = { 0, 0 };
/*
* Peek at the queue to see if there is an ICMP port unreachable. If there
* is then receive it.
*/
while(1) {
break;
}
break;
}
if (WSAGetLastError() != WSAECONNRESET) {
/* some other error - we don't care here */
break;
}
}
return got_icmp;
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketCreate
* Signature: (Z)I
*/
if (fd == INVALID_SOCKET) {
return -1;
}
if (rv == SOCKET_ERROR) {
return -1;
}
/* SIO_UDP_CONNRESET fixes a "bug" introduced in Windows 2000, which
* returns connection reset errors on unconnected UDP sockets (as well
* as connected sockets). The solution is to only enable this feature
* when the socket is connected.
*/
t = FALSE;
return fd;
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketBind
* Signature: (ILjava/net/InetAddress;I)V
*/
int rv;
return;
}
if (rv == SOCKET_ERROR) {
if (WSAGetLastError() == WSAEACCES) {
}
}
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketConnect
* Signature: (ILjava/net/InetAddress;I)V
*/
int rv;
int t = TRUE;
return;
}
if (rv == SOCKET_ERROR) {
return;
}
/* see comment in socketCreate */
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketDisconnect
* Signature: (I)V
*/
int t = FALSE;
/* see comment in socketCreate */
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketClose
* Signature: (I)V
*/
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketLocalPort
* Signature: (I)I
*/
return -1;
}
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketLocalAddress
*/
int port;
return NULL;
}
return iaObj;
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketReceiveOrPeekData
* Signature: (ILjava/net/DatagramPacket;IZZ)I
*/
char *fullPacket;
/* if we are only peeking. Called from peekData */
if (peek) {
}
if (packetBufferLen > MAX_BUFFER_LEN) {
/* Note: the buffer needn't be greater than 65,536 (0xFFFF)
* the max size of an IP packet. Anything bigger is truncated anyway.
*/
if (packetBufferLen > MAX_PACKET_LEN) {
}
if (!fullPacket) {
return -1;
}
} else {
fullPacket = &(BUF[0]);
}
do {
if (timeout) {
if (prevTime == 0) {
}
if (rv <= 0) {
if (rv == 0) {
"Receive timed out");
} else if (rv == JVM_IO_ERR) {
"Socket closed");
} else if (rv == JVM_IO_INTR) {
"operation interrupted");
}
if (packetBufferLen > MAX_BUFFER_LEN) {
}
return -1;
}
}
/* receive the packet */
/* An icmp port unreachable - we must receive this as Windows
* does not reset the state of the socket until this has been
* received.
*/
if (connected) {
"ICMP Port Unreachable");
if (packetBufferLen > MAX_BUFFER_LEN)
return -1;
} else if (timeout) {
/* Adjust timeout */
if (timeout <= 0) {
"Receive timed out");
if (packetBufferLen > MAX_BUFFER_LEN)
return -1;
}
}
}
} while (retry);
/* truncate the data if the packet's length is too small */
if (rv > packetBufferLen) {
}
if (rv < 0) {
if (WSAGetLastError() == WSAEMSGSIZE) {
/* it is because the buffer is too small. It's UDP, it's
* unreliable, it's all good. discard the rest of the
* data..
*/
} else {
/* failure */
}
}
if (rv == -1) {
} else if (rv == -2) {
"operation interrupted");
} else if (rv < 0) {
} else {
/*
* Check if there is an InetAddress already associated with this
* packet. If so, we check if it is the same source address. We
* can't update any existing InetAddress because it is immutable
*/
if (packetAddress != NULL) {
packetAddress)) {
/* force a new InetAddress to be created */
}
}
if (packetAddress == NULL) {
&port);
/* stuff the new Inetaddress into the packet */
}
/* populate the packet */
(jbyte *)fullPacket);
}
if (packetBufferLen > MAX_BUFFER_LEN) {
}
return port;
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketSend
* Signature: (I[BIILjava/net/InetAddress;IZ)V
*/
char *fullPacket;
int rv;
if (connected) {
sap = 0; /* arg to JVM_Sendto () null in this case */
sa_len = 0;
} else {
return;
}
}
if (length > MAX_BUFFER_LEN) {
/* Note: the buffer needn't be greater than 65,536 (0xFFFF)
* the max size of an IP packet. Anything bigger is truncated anyway.
*/
if (length > MAX_PACKET_LEN) {
}
if (!fullPacket) {
return;
}
} else {
fullPacket = &(BUF[0]);
}
(jbyte *)fullPacket);
if (rv == SOCKET_ERROR) {
if (rv == JVM_IO_ERR) {
} else if (rv == JVM_IO_INTR) {
"operation interrupted");
}
}
if (length > MAX_BUFFER_LEN) {
}
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketSetIntOption
* Signature: (III)V
*/
"Invalid option");
return;
}
}
}
/*
* Class: java_net_DualStackPlainDatagramSocketImpl
* Method: socketGetIntOption
* Signature: (II)I
*/
"Invalid option");
return -1;
}
return -1;
}
return result;
}