/*
* Copyright (c) 1997, 2013, 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
* 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 <ws2tcpip.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/types.h>
#ifndef IPTOS_TOS_MASK
#define IPTOS_TOS_MASK 0x1e
#endif
#ifndef IPTOS_PREC_MASK
#define IPTOS_PREC_MASK 0xe0
#endif
#include "java_net_TwoStacksPlainDatagramSocketImpl.h"
#include "java_net_SocketOptions.h"
#include "java_net_NetworkInterface.h"
#include "NetworkInterface.h"
#include "jvm.h"
#include "jni_util.h"
#include "net_util.h"
#define IN_CLASSD(i) (((long)(i) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(i) IN_CLASSD(i)
/************************************************************************
* TwoStacksPlainDatagramSocketImpl
*/
static jfieldID IO_fd_fdID;
static jfieldID pdsi_trafficClassID;
jfieldID pdsi_fdID;
jfieldID pdsi_fd1ID;
jfieldID pdsi_fduseID;
jfieldID pdsi_lastfdID;
jfieldID pdsi_timeoutID;
jfieldID pdsi_localPortID;
jfieldID pdsi_connected;
static jclass ia4_clazz;
static jmethodID ia4_ctor;
static CRITICAL_SECTION sizeCheckLock;
/* Windows OS version is XP or better */
static int xp_or_later = 0;
/* Windows OS version is Windows 2000 or better */
static int w2k_or_later = 0;
/*
* Notes about UDP/IPV6 on Windows (XP and 2003 server):
*
* fd always points to the IPv4 fd, and fd1 points to the IPv6 fd.
* Both fds are used when we bind to a wild-card address. When a specific
* address is used, only one of them is used.
*/
/*
* Returns a java.lang.Integer based on 'i'
*/
jobject createInteger(JNIEnv *env, int i) {
static jclass i_class;
static jmethodID i_ctrID;
static jfieldID i_valueID;
if (i_class == NULL) {
jclass c = (*env)->FindClass(env, "java/lang/Integer");
CHECK_NULL_RETURN(c, NULL);
i_ctrID = (*env)->GetMethodID(env, c, "<init>", "(I)V");
CHECK_NULL_RETURN(i_ctrID, NULL);
i_class = (*env)->NewGlobalRef(env, c);
CHECK_NULL_RETURN(i_class, NULL);
}
return ( (*env)->NewObject(env, i_class, i_ctrID, i) );
}
/*
* Returns a java.lang.Boolean based on 'b'
*/
jobject createBoolean(JNIEnv *env, int b) {
static jclass b_class;
static jmethodID b_ctrID;
static jfieldID b_valueID;
if (b_class == NULL) {
jclass c = (*env)->FindClass(env, "java/lang/Boolean");
CHECK_NULL_RETURN(c, NULL);
b_ctrID = (*env)->GetMethodID(env, c, "<init>", "(Z)V");
CHECK_NULL_RETURN(b_ctrID, NULL);
b_class = (*env)->NewGlobalRef(env, c);
CHECK_NULL_RETURN(b_class, NULL);
}
return( (*env)->NewObject(env, b_class, b_ctrID, (jboolean)(b!=0)) );
}
static int getFD(JNIEnv *env, jobject this) {
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
if (fdObj == NULL) {
return -1;
}
return (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
static int getFD1(JNIEnv *env, jobject this) {
jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fd1ID);
if (fdObj == NULL) {
return -1;
}
return (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
/*
* This function returns JNI_TRUE if the datagram size exceeds the underlying
* provider's ability to send to the target address. The following OS
* oddities have been observed :-
*
* 1. On Windows 95/98 if we try to send a datagram > 12k to an application
* on the same machine then the send will fail silently.
*
* 2. On Windows ME if we try to send a datagram > supported by underlying
* provider then send will not return an error.
*
* 3. On Windows NT/2000 if we exceeds the maximum size then send will fail
* with WSAEADDRNOTAVAIL.
*
* 4. On Windows 95/98 if we exceed the maximum size when sending to
* another machine then WSAEINVAL is returned.
*
*/
jboolean exceedSizeLimit(JNIEnv *env, jint fd, jint addr, jint size)
{
#define DEFAULT_MSG_SIZE 65527
static jboolean initDone;
static jboolean is95or98;
static int maxmsg;
typedef struct _netaddr { /* Windows 95/98 only */
unsigned long addr;
struct _netaddr *next;
} netaddr;
static netaddr *addrList;
netaddr *curr;
/*
* First time we are called we must determine which OS this is and also
* get the maximum size supported by the underlying provider.
*
* In addition on 95/98 we must enumerate our IP addresses.
*/
if (!initDone) {
EnterCriticalSection(&sizeCheckLock);
if (initDone) {
/* another thread got there first */
LeaveCriticalSection(&sizeCheckLock);
} else {
OSVERSIONINFO ver;
int len;
/*
* Step 1: Determine which OS this is.
*/
ver.dwOSVersionInfoSize = sizeof(ver);
GetVersionEx(&ver);
is95or98 = JNI_FALSE;
if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS &&
ver.dwMajorVersion == 4 &&
(ver.dwMinorVersion == 0 || ver.dwMinorVersion == 10)) {
is95or98 = JNI_TRUE;
}
/*
* Step 2: Determine the maximum datagram supported by the
* underlying provider. On Windows 95 if winsock hasn't been
* upgraded (ie: unsupported configuration) then we assume
* the default 64k limit.
*/
len = sizeof(maxmsg);
if (NET_GetSockOpt(fd, SOL_SOCKET, SO_MAX_MSG_SIZE, (char *)&maxmsg, &len) < 0) {
maxmsg = DEFAULT_MSG_SIZE;
}
/*
* Step 3: On Windows 95/98 then enumerate the IP addresses on
* this machine. This is neccesary because we need to check if the
* datagram is being sent to an application on the same machine.
*/
if (is95or98) {
char hostname[255];
struct hostent *hp;
if (gethostname(hostname, sizeof(hostname)) == -1) {
LeaveCriticalSection(&sizeCheckLock);
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Unable to obtain hostname");
return JNI_TRUE;
}
hp = (struct hostent *)gethostbyname(hostname);
if (hp != NULL) {
struct in_addr **addrp = (struct in_addr **) hp->h_addr_list;
while (*addrp != (struct in_addr *) 0) {
curr = (netaddr *)malloc(sizeof(netaddr));
if (curr == NULL) {
while (addrList != NULL) {
curr = addrList->next;
free(addrList);
addrList = curr;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
openjdk-8-src-b132-03_mar_2014-windows-native.zip (302个子文件)
check.bmp 166B
TwoStacksPlainDatagramSocketImpl.c 86KB
PLATFORM_API_WinOS_Ports.c 48KB
WindowsNativeDispatcher.c 43KB
TwoStacksPlainSocketImpl.c 38KB
D3DShaderGen.c 34KB
NetworkInterface.c 32KB
OperatingSystemImpl.c 32KB
NativeCreds.c 32KB
net_util_md.c 31KB
HostLocaleProviderAdapter_md.c 29KB
WinNTFileSystem_md.c 28KB
NetworkInterface_winXP.c 27KB
fontpath.c 26KB
nt.c 24KB
WGLGraphicsConfig.c 23KB
Inet6AddressImpl.c 23KB
java_props_md.c 22KB
WGLSurfaceData.c 20KB
io_util_md.c 20KB
WindowsVirtualMachine.c 19KB
ProcessImpl_md.c 18KB
canonicalize_md.c 18KB
Inet4AddressImpl.c 17KB
Net.c 17KB
splashscreen_sys.c 17KB
DualStackPlainDatagramSocketImpl.c 16KB
TimeZone_md.c 16KB
FileDispatcherImpl.c 15KB
lcdglyph.c 15KB
DualStackPlainSocketImpl.c 14KB
PLATFORM_API_WinOS_MidiOut.c 14KB
ResolverConfigurationImpl.c 9KB
FileSystemImpl.c 9KB
DefaultProxySelector.c 9KB
SocketDispatcher.c 9KB
WindowsPreferences.c 9KB
NTLMAuthSequence.c 8KB
DatagramChannelImpl.c 8KB
WindowsSelectorImpl.c 8KB
DatagramDispatcher.c 7KB
WindowsAsynchronousSocketChannelImpl.c 6KB
p11_md.c 6KB
FileChannelImpl.c 6KB
IOUtil.c 6KB
SocketInputStream.c 6KB
SocketOutputStream.c 6KB
jni_util_md.c 6KB
WindowsAttachProvider.c 6KB
Iocp.c 5KB
SocketChannelImpl.c 5KB
WindowsAsynchronousServerSocketChannelImpl.c 4KB
WindowsAsynchronousFileChannelImpl.c 4KB
dirent_md.c 4KB
PLATFORM_API_WinOS_Util.c 4KB
ServerSocketChannelImpl.c 4KB
MappedByteBuffer.c 4KB
portconfig.c 3KB
j2secmod_md.c 3KB
ProcessEnvironment_md.c 3KB
FileOutputStream_md.c 3KB
Console_md.c 3KB
WinCAPISeedGenerator.c 3KB
FileDescriptor_md.c 2KB
FileKey.c 2KB
jvm_symbols_md.c 2KB
RegistryFileTypeDetector.c 2KB
jdk_util_md.c 2KB
WindowsDirectory.c 2KB
RandomAccessFile_md.c 2KB
FileInputStream_md.c 2KB
InetAddressImplFactory.c 2KB
Win32ErrorMode.c 1KB
logging.c 1KB
pcsc_md.c 1KB
awt_Component.cpp 231KB
awt_PrintJob.cpp 142KB
awt_Window.cpp 105KB
awt_Toolkit.cpp 79KB
security.cpp 62KB
D3DContext.cpp 62KB
awt_Frame.cpp 60KB
awt_Font.cpp 53KB
PLATFORM_API_WinOS_DirectSound.cpp 49KB
awt_DnDDT.cpp 46KB
awt_DnDDS.cpp 45KB
D3DBlitLoops.cpp 44KB
GDIWindowSurfaceData.cpp 43KB
awt_Win32GraphicsDevice.cpp 42KB
ShellFolder2.cpp 38KB
awt_PrintControl.cpp 38KB
D3DPipelineManager.cpp 36KB
D3DRenderQueue.cpp 36KB
awt_DesktopProperties.cpp 35KB
D3DTextRenderer.cpp 33KB
WPrinterJob.cpp 33KB
GDIRenderer.cpp 33KB
awt_TrayIcon.cpp 32KB
awt_DataTransferer.cpp 31KB
awt_MenuItem.cpp 30KB
共 302 条
- 1
- 2
- 3
- 4
资源评论
Cceking
- 粉丝: 28
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功