7030256: Cleanup/Remove code supporting old Windows versions (98, NT, 2000, etc)
Reviewed-by: alanb, mduigou
This commit is contained in:
parent
ebba49aa62
commit
d6fce83042
@ -37,10 +37,6 @@ include FILES_c.gmk
|
||||
AUTO_FILES_JAVA_DIRS = java/net
|
||||
|
||||
ifeq ($(PLATFORM), windows)
|
||||
# Windows 9x module only needed on 32-bit build
|
||||
ifeq ($(ARCH_DATA_MODEL), 32)
|
||||
FILES_c += NetworkInterface_win9x.c
|
||||
endif
|
||||
FILES_c += NTLMAuthSequence.c
|
||||
FILES_c += NetworkInterface_winXP.c
|
||||
else
|
||||
@ -96,7 +92,9 @@ include $(BUILDDIR)/common/Mapfile-vers.gmk
|
||||
include $(BUILDDIR)/common/Library.gmk
|
||||
|
||||
ifeq ($(PLATFORM), windows)
|
||||
OTHER_LDLIBS = ws2_32.lib $(JVMLIB)
|
||||
OTHER_LDLIBS = ws2_32.lib $(JVMLIB) \
|
||||
secur32.lib iphlpapi.lib delayimp.lib \
|
||||
/DELAYLOAD:secur32.dll /DELAYLOAD:iphlpapi.dll
|
||||
else
|
||||
OTHER_LDLIBS = $(LIBSOCKET) $(LIBNSL) -ldl $(JVMLIB)
|
||||
endif
|
||||
|
@ -90,6 +90,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
jobjectArray ret = 0;
|
||||
int retLen = 0;
|
||||
jboolean preferIPv6Address;
|
||||
static jfieldID ia_preferIPv6AddressID;
|
||||
|
||||
int error=0;
|
||||
struct addrinfo hints, *res, *resNew = NULL;
|
||||
@ -116,166 +117,163 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
|
||||
hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
|
||||
CHECK_NULL_RETURN(hostname, NULL);
|
||||
|
||||
if (NET_addrtransAvailable()) {
|
||||
static jfieldID ia_preferIPv6AddressID;
|
||||
if (ia_preferIPv6AddressID == NULL) {
|
||||
jclass c = (*env)->FindClass(env,"java/net/InetAddress");
|
||||
if (c) {
|
||||
ia_preferIPv6AddressID =
|
||||
(*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z");
|
||||
}
|
||||
if (ia_preferIPv6AddressID == NULL) {
|
||||
JNU_ReleaseStringPlatformChars(env, host, hostname);
|
||||
return NULL;
|
||||
}
|
||||
if (ia_preferIPv6AddressID == NULL) {
|
||||
jclass c = (*env)->FindClass(env,"java/net/InetAddress");
|
||||
if (c) {
|
||||
ia_preferIPv6AddressID =
|
||||
(*env)->GetStaticFieldID(env, c, "preferIPv6Address", "Z");
|
||||
}
|
||||
/* get the address preference */
|
||||
preferIPv6Address
|
||||
= (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
|
||||
|
||||
/* Try once, with our static buffer. */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
error = (*getaddrinfo_ptr)(hostname, NULL, &hints, &res);
|
||||
|
||||
if (error) {
|
||||
/* report error */
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
|
||||
(char *)hostname);
|
||||
if (ia_preferIPv6AddressID == NULL) {
|
||||
JNU_ReleaseStringPlatformChars(env, host, hostname);
|
||||
return NULL;
|
||||
} else {
|
||||
int i = 0;
|
||||
int inetCount = 0, inet6Count = 0, inetIndex, inet6Index;
|
||||
struct addrinfo *itr, *last, *iterator = res;
|
||||
while (iterator != NULL) {
|
||||
int skip = 0;
|
||||
itr = resNew;
|
||||
while (itr != NULL) {
|
||||
if (iterator->ai_family == itr->ai_family &&
|
||||
iterator->ai_addrlen == itr->ai_addrlen) {
|
||||
if (itr->ai_family == AF_INET) { /* AF_INET */
|
||||
struct sockaddr_in *addr1, *addr2;
|
||||
addr1 = (struct sockaddr_in *)iterator->ai_addr;
|
||||
addr2 = (struct sockaddr_in *)itr->ai_addr;
|
||||
if (addr1->sin_addr.s_addr ==
|
||||
addr2->sin_addr.s_addr) {
|
||||
skip = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int t;
|
||||
struct sockaddr_in6 *addr1, *addr2;
|
||||
addr1 = (struct sockaddr_in6 *)iterator->ai_addr;
|
||||
addr2 = (struct sockaddr_in6 *)itr->ai_addr;
|
||||
}
|
||||
}
|
||||
/* get the address preference */
|
||||
preferIPv6Address
|
||||
= (*env)->GetStaticBooleanField(env, ia_class, ia_preferIPv6AddressID);
|
||||
|
||||
for (t = 0; t < 16; t++) {
|
||||
if (addr1->sin6_addr.s6_addr[t] !=
|
||||
addr2->sin6_addr.s6_addr[t]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t < 16) {
|
||||
itr = itr->ai_next;
|
||||
continue;
|
||||
} else {
|
||||
skip = 1;
|
||||
/* Try once, with our static buffer. */
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_flags = AI_CANONNAME;
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
|
||||
error = getaddrinfo(hostname, NULL, &hints, &res);
|
||||
|
||||
if (error) {
|
||||
/* report error */
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
|
||||
(char *)hostname);
|
||||
JNU_ReleaseStringPlatformChars(env, host, hostname);
|
||||
return NULL;
|
||||
} else {
|
||||
int i = 0;
|
||||
int inetCount = 0, inet6Count = 0, inetIndex, inet6Index;
|
||||
struct addrinfo *itr, *last, *iterator = res;
|
||||
while (iterator != NULL) {
|
||||
int skip = 0;
|
||||
itr = resNew;
|
||||
while (itr != NULL) {
|
||||
if (iterator->ai_family == itr->ai_family &&
|
||||
iterator->ai_addrlen == itr->ai_addrlen) {
|
||||
if (itr->ai_family == AF_INET) { /* AF_INET */
|
||||
struct sockaddr_in *addr1, *addr2;
|
||||
addr1 = (struct sockaddr_in *)iterator->ai_addr;
|
||||
addr2 = (struct sockaddr_in *)itr->ai_addr;
|
||||
if (addr1->sin_addr.s_addr ==
|
||||
addr2->sin_addr.s_addr) {
|
||||
skip = 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int t;
|
||||
struct sockaddr_in6 *addr1, *addr2;
|
||||
addr1 = (struct sockaddr_in6 *)iterator->ai_addr;
|
||||
addr2 = (struct sockaddr_in6 *)itr->ai_addr;
|
||||
|
||||
for (t = 0; t < 16; t++) {
|
||||
if (addr1->sin6_addr.s6_addr[t] !=
|
||||
addr2->sin6_addr.s6_addr[t]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (iterator->ai_family != AF_INET &&
|
||||
iterator->ai_family != AF_INET6) {
|
||||
/* we can't handle other family types */
|
||||
skip = 1;
|
||||
break;
|
||||
if (t < 16) {
|
||||
itr = itr->ai_next;
|
||||
continue;
|
||||
} else {
|
||||
skip = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
itr = itr->ai_next;
|
||||
} else if (iterator->ai_family != AF_INET &&
|
||||
iterator->ai_family != AF_INET6) {
|
||||
/* we can't handle other family types */
|
||||
skip = 1;
|
||||
break;
|
||||
}
|
||||
itr = itr->ai_next;
|
||||
}
|
||||
|
||||
if (!skip) {
|
||||
struct addrinfo *next
|
||||
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
|
||||
if (!next) {
|
||||
JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
memcpy(next, iterator, sizeof(struct addrinfo));
|
||||
next->ai_next = NULL;
|
||||
if (resNew == NULL) {
|
||||
resNew = next;
|
||||
} else {
|
||||
last->ai_next = next;
|
||||
}
|
||||
last = next;
|
||||
i++;
|
||||
if (iterator->ai_family == AF_INET) {
|
||||
inetCount ++;
|
||||
} else if (iterator->ai_family == AF_INET6) {
|
||||
inet6Count ++;
|
||||
}
|
||||
if (!skip) {
|
||||
struct addrinfo *next
|
||||
= (struct addrinfo*) malloc(sizeof(struct addrinfo));
|
||||
if (!next) {
|
||||
JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
iterator = iterator->ai_next;
|
||||
}
|
||||
retLen = i;
|
||||
iterator = resNew;
|
||||
i = 0;
|
||||
ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
|
||||
|
||||
if (IS_NULL(ret)) {
|
||||
/* we may have memory to free at the end of this */
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
if (preferIPv6Address) {
|
||||
inetIndex = inet6Count;
|
||||
inet6Index = 0;
|
||||
} else {
|
||||
inetIndex = 0;
|
||||
inet6Index = inetCount;
|
||||
}
|
||||
|
||||
while (iterator != NULL) {
|
||||
memcpy(next, iterator, sizeof(struct addrinfo));
|
||||
next->ai_next = NULL;
|
||||
if (resNew == NULL) {
|
||||
resNew = next;
|
||||
} else {
|
||||
last->ai_next = next;
|
||||
}
|
||||
last = next;
|
||||
i++;
|
||||
if (iterator->ai_family == AF_INET) {
|
||||
jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
|
||||
if (IS_NULL(iaObj)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
(*env)->SetIntField(env, iaObj, ni_iaaddressID,
|
||||
ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
|
||||
(*env)->SetObjectField(env, iaObj, ni_iahostID, host);
|
||||
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
|
||||
inetIndex ++;
|
||||
inetCount ++;
|
||||
} else if (iterator->ai_family == AF_INET6) {
|
||||
jint scope = 0;
|
||||
jbyteArray ipaddress;
|
||||
jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
|
||||
if (IS_NULL(iaObj)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
ipaddress = (*env)->NewByteArray(env, 16);
|
||||
if (IS_NULL(ipaddress)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
(*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
|
||||
(jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
|
||||
scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
|
||||
if (scope != 0) { /* zero is default value, no need to set */
|
||||
(*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
|
||||
(*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
|
||||
}
|
||||
(*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
|
||||
(*env)->SetObjectField(env, iaObj, ni_iahostID, host);
|
||||
(*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
|
||||
inet6Index ++;
|
||||
inet6Count ++;
|
||||
}
|
||||
iterator = iterator->ai_next;
|
||||
}
|
||||
iterator = iterator->ai_next;
|
||||
}
|
||||
retLen = i;
|
||||
iterator = resNew;
|
||||
i = 0;
|
||||
ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
|
||||
|
||||
if (IS_NULL(ret)) {
|
||||
/* we may have memory to free at the end of this */
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
|
||||
if (preferIPv6Address) {
|
||||
inetIndex = inet6Count;
|
||||
inet6Index = 0;
|
||||
} else {
|
||||
inetIndex = 0;
|
||||
inet6Index = inetCount;
|
||||
}
|
||||
|
||||
while (iterator != NULL) {
|
||||
if (iterator->ai_family == AF_INET) {
|
||||
jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
|
||||
if (IS_NULL(iaObj)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
(*env)->SetIntField(env, iaObj, ni_iaaddressID,
|
||||
ntohl(((struct sockaddr_in*)iterator->ai_addr)->sin_addr.s_addr));
|
||||
(*env)->SetObjectField(env, iaObj, ni_iahostID, host);
|
||||
(*env)->SetObjectArrayElement(env, ret, inetIndex, iaObj);
|
||||
inetIndex ++;
|
||||
} else if (iterator->ai_family == AF_INET6) {
|
||||
jint scope = 0;
|
||||
jbyteArray ipaddress;
|
||||
jobject iaObj = (*env)->NewObject(env, ni_ia6cls, ni_ia6ctrID);
|
||||
if (IS_NULL(iaObj)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
ipaddress = (*env)->NewByteArray(env, 16);
|
||||
if (IS_NULL(ipaddress)) {
|
||||
ret = NULL;
|
||||
goto cleanupAndReturn;
|
||||
}
|
||||
(*env)->SetByteArrayRegion(env, ipaddress, 0, 16,
|
||||
(jbyte *)&(((struct sockaddr_in6*)iterator->ai_addr)->sin6_addr));
|
||||
scope = ((struct sockaddr_in6*)iterator->ai_addr)->sin6_scope_id;
|
||||
if (scope != 0) { /* zero is default value, no need to set */
|
||||
(*env)->SetIntField(env, iaObj, ia6_scopeidID, scope);
|
||||
(*env)->SetBooleanField(env, iaObj, ia6_scopeidsetID, JNI_TRUE);
|
||||
}
|
||||
(*env)->SetObjectField(env, iaObj, ni_ia6ipaddressID, ipaddress);
|
||||
(*env)->SetObjectField(env, iaObj, ni_iahostID, host);
|
||||
(*env)->SetObjectArrayElement(env, ret, inet6Index, iaObj);
|
||||
inet6Index ++;
|
||||
}
|
||||
iterator = iterator->ai_next;
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,8 +289,7 @@ cleanupAndReturn:
|
||||
JNU_ReleaseStringPlatformChars(env, host, hostname);
|
||||
}
|
||||
|
||||
if (NET_addrtransAvailable())
|
||||
(*freeaddrinfo_ptr)(res);
|
||||
freeaddrinfo(res);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -312,44 +309,41 @@ Java_java_net_Inet6AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
|
||||
int len = 0;
|
||||
jbyte caddr[16];
|
||||
|
||||
if (NET_addrtransAvailable()) {
|
||||
struct sockaddr_in him4;
|
||||
struct sockaddr_in6 him6;
|
||||
struct sockaddr *sa;
|
||||
struct sockaddr_in him4;
|
||||
struct sockaddr_in6 him6;
|
||||
struct sockaddr *sa;
|
||||
|
||||
/*
|
||||
* For IPv4 addresses construct a sockaddr_in structure.
|
||||
*/
|
||||
if ((*env)->GetArrayLength(env, addrArray) == 4) {
|
||||
jint addr;
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
|
||||
addr = ((caddr[0]<<24) & 0xff000000);
|
||||
addr |= ((caddr[1] <<16) & 0xff0000);
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
} else {
|
||||
/*
|
||||
* For IPv4 addresses construct a sockaddr_in structure.
|
||||
* For IPv6 address construct a sockaddr_in6 structure.
|
||||
*/
|
||||
if ((*env)->GetArrayLength(env, addrArray) == 4) {
|
||||
jint addr;
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
|
||||
addr = ((caddr[0]<<24) & 0xff000000);
|
||||
addr |= ((caddr[1] <<16) & 0xff0000);
|
||||
addr |= ((caddr[2] <<8) & 0xff00);
|
||||
addr |= (caddr[3] & 0xff);
|
||||
memset((char *) &him4, 0, sizeof(him4));
|
||||
him4.sin_addr.s_addr = (uint32_t) htonl(addr);
|
||||
him4.sin_family = AF_INET;
|
||||
sa = (struct sockaddr *) &him4;
|
||||
len = sizeof(him4);
|
||||
} else {
|
||||
/*
|
||||
* For IPv6 address construct a sockaddr_in6 structure.
|
||||
*/
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
|
||||
memset((char *) &him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
him6.sin6_family = AF_INET6;
|
||||
sa = (struct sockaddr *) &him6 ;
|
||||
len = sizeof(him6) ;
|
||||
}
|
||||
(*env)->GetByteArrayRegion(env, addrArray, 0, 16, caddr);
|
||||
memset((char *) &him6, 0, sizeof(him6));
|
||||
memcpy((void *)&(him6.sin6_addr), caddr, sizeof(struct in6_addr) );
|
||||
him6.sin6_family = AF_INET6;
|
||||
sa = (struct sockaddr *) &him6 ;
|
||||
len = sizeof(him6) ;
|
||||
}
|
||||
|
||||
error = (*getnameinfo_ptr)(sa, len, host, NI_MAXHOST, NULL, 0,
|
||||
NI_NAMEREQD);
|
||||
error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
}
|
||||
if (!error) {
|
||||
ret = (*env)->NewStringUTF(env, host);
|
||||
}
|
||||
|
||||
if (ret == NULL) {
|
||||
|
@ -53,36 +53,6 @@
|
||||
* order and this ensures consistent device number across invocations.
|
||||
*/
|
||||
|
||||
|
||||
/* IP helper library routines */
|
||||
int (PASCAL FAR *GetIpAddrTable_fn)();
|
||||
int (PASCAL FAR *GetIfTable_fn)();
|
||||
int (PASCAL FAR *GetFriendlyIfIndex_fn)();
|
||||
int (PASCAL FAR *GetAdaptersAddresses_fn)();
|
||||
int (PASCAL FAR *GetAdaptersInfo_fn)();
|
||||
int (PASCAL FAR *GetNumberOfInterfaces_fn)();
|
||||
|
||||
/* Enumeration routines */
|
||||
typedef int (*EnumerateNetInterfaces)(JNIEnv *, netif **);
|
||||
typedef int(*EnumerateNetAddresses)(JNIEnv *, netif *, netaddr **);
|
||||
|
||||
static EnumerateNetInterfaces enumInterfaces_fn;
|
||||
static EnumerateNetAddresses enumAddresses_fn;
|
||||
|
||||
/* Windows 9x routines are external (not needed on 64-bit) */
|
||||
#ifndef _WIN64
|
||||
extern int enumInterfaces_win9x(JNIEnv *, netif **);
|
||||
extern int enumAddresses_win9x(JNIEnv *, netif *, netaddr **);
|
||||
extern int init_win9x(void);
|
||||
#endif
|
||||
|
||||
|
||||
/* Windows 95/98/ME running */
|
||||
static jboolean isW9x;
|
||||
|
||||
/* Windows version supports */
|
||||
static jboolean os_supports_ipv6;
|
||||
|
||||
/* various JNI ids */
|
||||
|
||||
jclass ni_class; /* NetworkInterface */
|
||||
@ -154,10 +124,10 @@ MIB_IFROW *getIF(jint index) {
|
||||
*/
|
||||
size = sizeof(MIB_IFTABLE);
|
||||
tableP = (MIB_IFTABLE *)malloc(size);
|
||||
count = (*GetIfTable_fn)(tableP, &size, TRUE);
|
||||
count = GetIfTable(tableP, &size, TRUE);
|
||||
if (count == ERROR_INSUFFICIENT_BUFFER || count == ERROR_BUFFER_OVERFLOW) {
|
||||
tableP = (MIB_IFTABLE *)realloc(tableP, size);
|
||||
count = (*GetIfTable_fn)(tableP, &size, TRUE);
|
||||
count = GetIfTable(tableP, &size, TRUE);
|
||||
}
|
||||
|
||||
if (count != NO_ERROR) {
|
||||
@ -172,7 +142,7 @@ MIB_IFROW *getIF(jint index) {
|
||||
/*
|
||||
* Warning the real index is obtained by GetFriendlyIfIndex()
|
||||
*/
|
||||
ifindex = (*GetFriendlyIfIndex_fn)(ifrowP->dwIndex);
|
||||
ifindex = GetFriendlyIfIndex(ifrowP->dwIndex);
|
||||
if (ifindex == index) {
|
||||
/*
|
||||
* Create a copy of the entry so that we can free the table.
|
||||
@ -199,7 +169,7 @@ MIB_IFROW *getIF(jint index) {
|
||||
* occurs then netifPP be returned as list of netif structures or NULL
|
||||
* if no interfaces are found.
|
||||
*/
|
||||
int enumInterfaces_win(JNIEnv *env, netif **netifPP)
|
||||
int enumInterfaces(JNIEnv *env, netif **netifPP)
|
||||
{
|
||||
MIB_IFTABLE *tableP;
|
||||
MIB_IFROW *ifrowP;
|
||||
@ -215,32 +185,16 @@ int enumInterfaces_win(JNIEnv *env, netif **netifPP)
|
||||
*/
|
||||
size = sizeof(MIB_IFTABLE);
|
||||
tableP = (MIB_IFTABLE *)malloc(size);
|
||||
ret = (*GetIfTable_fn)(tableP, &size, TRUE);
|
||||
ret = GetIfTable(tableP, &size, TRUE);
|
||||
if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) {
|
||||
tableP = (MIB_IFTABLE *)realloc(tableP, size);
|
||||
ret = (*GetIfTable_fn)(tableP, &size, TRUE);
|
||||
ret = GetIfTable(tableP, &size, TRUE);
|
||||
}
|
||||
|
||||
if (ret != NO_ERROR) {
|
||||
if (tableP != NULL)
|
||||
free(tableP);
|
||||
|
||||
#ifndef _WIN64
|
||||
if (isW9x && ret == ERROR_NOT_SUPPORTED) {
|
||||
/*
|
||||
* If ERROR_NOT_SUPPORTED is returned on Windows 98 it means that
|
||||
* IE5.0 has been installed. In this case we revert to the Windows 95
|
||||
* approach and avoid using the IP Helper Library.
|
||||
* See: http://support.microsoft.com/support/kb/articles/q234/5/73.asp
|
||||
*/
|
||||
enumInterfaces_fn = enumInterfaces_win9x;
|
||||
enumAddresses_fn = enumAddresses_win9x;
|
||||
init_win9x();
|
||||
|
||||
return (*enumInterfaces_fn)(env, netifPP);
|
||||
}
|
||||
#endif
|
||||
|
||||
JNU_ThrowByName(env, "java/lang/Error",
|
||||
"IP Helper Library GetIfTable function failed");
|
||||
|
||||
@ -328,7 +282,7 @@ int enumInterfaces_win(JNIEnv *env, netif **netifPP)
|
||||
curr->displayName[ifrowP->dwDescrLen] = '\0';
|
||||
curr->dwIndex = ifrowP->dwIndex;
|
||||
curr->ifType = ifrowP->dwType;
|
||||
curr->index = (*GetFriendlyIfIndex_fn)(ifrowP->dwIndex);
|
||||
curr->index = GetFriendlyIfIndex(ifrowP->dwIndex);
|
||||
|
||||
/*
|
||||
* Put the interface at tail of list as GetIfTable(,,TRUE) is
|
||||
@ -384,10 +338,10 @@ int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP)
|
||||
size = sizeof(MIB_IPADDRTABLE);
|
||||
tableP = (MIB_IPADDRTABLE *)malloc(size);
|
||||
|
||||
ret = (*GetIpAddrTable_fn)(&tableP, &size, FALSE);
|
||||
ret = GetIpAddrTable(tableP, &size, FALSE);
|
||||
if (ret == ERROR_INSUFFICIENT_BUFFER || ret == ERROR_BUFFER_OVERFLOW) {
|
||||
tableP = (MIB_IPADDRTABLE *)realloc(tableP, size);
|
||||
ret = (*GetIpAddrTable_fn)(tableP, &size, FALSE);
|
||||
ret = GetIpAddrTable(tableP, &size, FALSE);
|
||||
}
|
||||
if (ret != NO_ERROR) {
|
||||
if (tableP) {
|
||||
@ -477,71 +431,6 @@ int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP)
|
||||
JNIEXPORT void JNICALL
|
||||
Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls)
|
||||
{
|
||||
OSVERSIONINFO ver;
|
||||
HANDLE h;
|
||||
|
||||
/*
|
||||
* First check if this is a Windows 9x machine.
|
||||
*/
|
||||
ver.dwOSVersionInfoSize = sizeof(ver);
|
||||
GetVersionEx(&ver);
|
||||
if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && ver.dwMajorVersion == 4) {
|
||||
isW9x = JNI_TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try to load the IP Helper Library and obtain the entry points we
|
||||
* require. This will succeed on 98, NT SP4+, 2000 & XP. It will
|
||||
* fail on Windows 95 (if IE hasn't been updated) and old versions
|
||||
* of NT (IP helper library only appeared at SP4). If it fails on
|
||||
* Windows 9x we will use the registry approach, otherwise if it
|
||||
* fails we throw an Error indicating that we have an incompatible
|
||||
* IP helper library.
|
||||
*/
|
||||
h = LoadLibrary("iphlpapi.dll");
|
||||
if (h != NULL) {
|
||||
GetIpAddrTable_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetIpAddrTable");
|
||||
GetIfTable_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetIfTable");
|
||||
GetFriendlyIfIndex_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetFriendlyIfIndex");
|
||||
GetNumberOfInterfaces_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetNumberOfInterfaces");
|
||||
GetAdaptersAddresses_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetAdaptersAddresses");
|
||||
GetAdaptersInfo_fn =
|
||||
(int (PASCAL FAR *)())GetProcAddress(h, "GetAdaptersInfo");
|
||||
}
|
||||
|
||||
/* IPv6 is supported on Windows versions if the following APIs avail */
|
||||
|
||||
os_supports_ipv6 = (GetAdaptersAddresses_fn != NULL) &&
|
||||
(GetNumberOfInterfaces_fn != NULL) &&
|
||||
(GetAdaptersInfo_fn != NULL);
|
||||
|
||||
if (GetIpAddrTable_fn == NULL ||
|
||||
GetIfTable_fn == NULL ||
|
||||
GetFriendlyIfIndex_fn == NULL) {
|
||||
|
||||
#ifndef _WIN64
|
||||
if (isW9x) {
|
||||
/* Use Windows 9x registry approach which requires initialization */
|
||||
enumInterfaces_fn = enumInterfaces_win9x;
|
||||
enumAddresses_fn = enumAddresses_win9x;
|
||||
init_win9x();
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
JNU_ThrowByName(env, "java/lang/Error",
|
||||
"Incompatible IP helper library (iphlpapi.dll)");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
enumInterfaces_fn = enumInterfaces_win;
|
||||
enumAddresses_fn = enumAddresses_win;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the various JNI ids that we require
|
||||
*/
|
||||
@ -581,7 +470,8 @@ Java_java_net_NetworkInterface_init(JNIEnv *env, jclass cls)
|
||||
* populate the InetAddress array based on the IP addresses for this
|
||||
* interface.
|
||||
*/
|
||||
jobject createNetworkInterface(JNIEnv *env, netif *ifs, int netaddrCount, netaddr *netaddrP)
|
||||
jobject createNetworkInterface
|
||||
(JNIEnv *env, netif *ifs, int netaddrCount, netaddr *netaddrP)
|
||||
{
|
||||
jobject netifObj;
|
||||
jobject name, displayName;
|
||||
@ -596,7 +486,8 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs, int netaddrCount, netadd
|
||||
netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
|
||||
name = (*env)->NewStringUTF(env, ifs->name);
|
||||
if (ifs->dNameIsUnicode) {
|
||||
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName, wcslen ((PWCHAR)ifs->displayName));
|
||||
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
|
||||
(jsize)wcslen ((PWCHAR)ifs->displayName));
|
||||
} else {
|
||||
displayName = (*env)->NewStringUTF(env, ifs->displayName);
|
||||
}
|
||||
@ -612,7 +503,7 @@ jobject createNetworkInterface(JNIEnv *env, netif *ifs, int netaddrCount, netadd
|
||||
* Note that 0 is a valid number of addresses.
|
||||
*/
|
||||
if (netaddrCount < 0) {
|
||||
netaddrCount = (*enumAddresses_fn)(env, ifs, &netaddrP);
|
||||
netaddrCount = enumAddresses_win(env, ifs, &netaddrP);
|
||||
if ((*env)->ExceptionOccurred(env)) {
|
||||
free_netaddr(netaddrP);
|
||||
return NULL;
|
||||
@ -725,12 +616,13 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByName0
|
||||
const char *name_utf;
|
||||
jobject netifObj = NULL;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getByName0_XP (env, cls, name);
|
||||
}
|
||||
|
||||
/* get the list of interfaces */
|
||||
if ((*enumInterfaces_fn)(env, &ifList) < 0) {
|
||||
if (enumInterfaces(env, &ifList) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -771,12 +663,13 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByIndex0
|
||||
netif *ifList, *curr;
|
||||
jobject netifObj = NULL;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getByIndex0_XP (env, cls, index);
|
||||
}
|
||||
|
||||
/* get the list of interfaces */
|
||||
if ((*enumInterfaces_fn)(env, &ifList) < 0) {
|
||||
if (enumInterfaces(env, &ifList) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -812,12 +705,13 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
|
||||
jint addr = (*env)->GetIntField(env, iaObj, ni_iaAddr);
|
||||
jobject netifObj = NULL;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getByInetAddress0_XP (env, cls, iaObj);
|
||||
}
|
||||
|
||||
/* get the list of interfaces */
|
||||
if ((*enumInterfaces_fn)(env, &ifList) < 0) {
|
||||
if (enumInterfaces(env, &ifList) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -832,7 +726,7 @@ JNIEXPORT jobject JNICALL Java_java_net_NetworkInterface_getByInetAddress0
|
||||
netaddr *addrP;
|
||||
|
||||
/* enumerate the addresses on this interface */
|
||||
count = (*enumAddresses_fn)(env, curr, &addrList);
|
||||
count = enumAddresses_win(env, curr, &addrList);
|
||||
if (count < 0) {
|
||||
free_netif(ifList);
|
||||
return NULL;
|
||||
@ -881,14 +775,15 @@ JNIEXPORT jobjectArray JNICALL Java_java_net_NetworkInterface_getAll
|
||||
jobjectArray netIFArr;
|
||||
jint arr_index;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getAll_XP (env, cls);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get list of interfaces
|
||||
*/
|
||||
count = (*enumInterfaces_fn)(env, &ifList);
|
||||
count = enumInterfaces(env, &ifList);
|
||||
if (count < 0) {
|
||||
return NULL;
|
||||
}
|
||||
@ -934,13 +829,16 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0
|
||||
(JNIEnv *env, jclass cls, jstring name, jint index) {
|
||||
jboolean ret = JNI_FALSE;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_isUp0_XP(env, cls, name, index);
|
||||
} else {
|
||||
MIB_IFROW *ifRowP;
|
||||
ifRowP = getIF(index);
|
||||
if (ifRowP != NULL) {
|
||||
ret = ifRowP->dwAdminStatus == 1 && (ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL || ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED);
|
||||
ret = ifRowP->dwAdminStatus == 1 &&
|
||||
(ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL ||
|
||||
ifRowP->dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED);
|
||||
free(ifRowP);
|
||||
}
|
||||
}
|
||||
@ -952,11 +850,13 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isUp0
|
||||
* Method: isP2P0
|
||||
* Signature: (Ljava/lang/String;I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0(JNIEnv *env, jclass cls, jstring name, jint index) {
|
||||
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isP2P0
|
||||
(JNIEnv *env, jclass cls, jstring name, jint index) {
|
||||
MIB_IFROW *ifRowP;
|
||||
jboolean ret = JNI_FALSE;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_isP2P0_XP(env, cls, name, index);
|
||||
} else {
|
||||
ifRowP = getIF(index);
|
||||
@ -983,7 +883,8 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0
|
||||
MIB_IFROW *ifRowP;
|
||||
jboolean ret = JNI_FALSE;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_isLoopback0_XP(env, cls, name, index);
|
||||
} else {
|
||||
ifRowP = getIF(index);
|
||||
@ -1003,22 +904,8 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_isLoopback0
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0
|
||||
(JNIEnv *env, jclass cls, jstring name, jint index) {
|
||||
MIB_IFROW *ifRowP;
|
||||
jboolean ret = JNI_TRUE;
|
||||
|
||||
// Let's try to use the newer API (XP & 2003 only)
|
||||
if (GetAdaptersAddresses_fn != NULL) {
|
||||
ret = Java_java_net_NetworkInterface_supportsMulticast0_XP(env, cls,
|
||||
return Java_java_net_NetworkInterface_supportsMulticast0_XP(env, cls,
|
||||
name, index);
|
||||
return ret;
|
||||
}
|
||||
ifRowP = getIF(index);
|
||||
if (ifRowP != NULL) {
|
||||
if (ifRowP->dwType == MIB_IF_TYPE_LOOPBACK)
|
||||
ret = JNI_FALSE;
|
||||
free(ifRowP);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1026,12 +913,14 @@ JNIEXPORT jboolean JNICALL Java_java_net_NetworkInterface_supportsMulticast0
|
||||
* Method: getMacAddr0
|
||||
* Signature: ([bLjava/lang/String;I)[b
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
|
||||
JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0
|
||||
(JNIEnv *env, jclass class, jbyteArray addrArray, jstring name, jint index) {
|
||||
jbyteArray ret = NULL;
|
||||
int len;
|
||||
MIB_IFROW *ifRowP;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getMacAddr0_XP(env, class, name, index);
|
||||
} else {
|
||||
ifRowP = getIF(index);
|
||||
@ -1058,11 +947,13 @@ JNIEXPORT jbyteArray JNICALL Java_java_net_NetworkInterface_getMacAddr0(JNIEnv *
|
||||
* Method: getMTU0
|
||||
* Signature: ([bLjava/lang/String;I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0(JNIEnv *env, jclass class, jstring name, jint index) {
|
||||
JNIEXPORT jint JNICALL Java_java_net_NetworkInterface_getMTU0
|
||||
(JNIEnv *env, jclass class, jstring name, jint index) {
|
||||
jint ret = -1;
|
||||
MIB_IFROW *ifRowP;
|
||||
|
||||
if (os_supports_ipv6 && ipv6_available()) {
|
||||
// Retained for now to support IPv4 only stack, java.net.preferIPv4Stack
|
||||
if (ipv6_available()) {
|
||||
return Java_java_net_NetworkInterface_getMTU0_XP(env, class, name, index);
|
||||
} else {
|
||||
ifRowP = getIF(index);
|
||||
|
@ -87,338 +87,6 @@ extern jfieldID ni_ibaddressID; /* InterfaceAddress.address */
|
||||
extern jfieldID ni_ibbroadcastID; /* InterfaceAddress.broadcast */
|
||||
extern jfieldID ni_ibmaskID; /* InterfaceAddress.maskLength */
|
||||
|
||||
int enumInterfaces_win(JNIEnv *env, netif **netifPP);
|
||||
|
||||
/* We have included iphlpapi.h which includes iptypes.h which has the definition
|
||||
* for MAX_ADAPTER_DESCRIPTION_LENGTH (along with the other definitions in this
|
||||
* ifndef block). Therefore if MAX_ADAPTER_DESCRIPTION_LENGTH is defined we can
|
||||
* be sure that the other definitions are also defined */
|
||||
#ifndef MAX_ADAPTER_DESCRIPTION_LENGTH
|
||||
|
||||
/*
|
||||
* Following includes come from iptypes.h
|
||||
*/
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4201)
|
||||
|
||||
#include <time.h>
|
||||
|
||||
// Definitions and structures used by getnetworkparams and getadaptersinfo apis
|
||||
|
||||
#define MAX_ADAPTER_DESCRIPTION_LENGTH 128 // arb.
|
||||
#define MAX_ADAPTER_NAME_LENGTH 256 // arb.
|
||||
#define MAX_ADAPTER_ADDRESS_LENGTH 8 // arb.
|
||||
#define DEFAULT_MINIMUM_ENTITIES 32 // arb.
|
||||
#define MAX_HOSTNAME_LEN 128 // arb.
|
||||
#define MAX_DOMAIN_NAME_LEN 128 // arb.
|
||||
#define MAX_SCOPE_ID_LEN 256 // arb.
|
||||
|
||||
//
|
||||
// types
|
||||
//
|
||||
|
||||
// Node Type
|
||||
|
||||
#define BROADCAST_NODETYPE 1
|
||||
#define PEER_TO_PEER_NODETYPE 2
|
||||
#define MIXED_NODETYPE 4
|
||||
#define HYBRID_NODETYPE 8
|
||||
|
||||
//
|
||||
// IP_ADDRESS_STRING - store an IP address as a dotted decimal string
|
||||
//
|
||||
|
||||
typedef struct {
|
||||
char String[4 * 4];
|
||||
} IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING;
|
||||
|
||||
//
|
||||
// IP_ADDR_STRING - store an IP address with its corresponding subnet mask,
|
||||
// both as dotted decimal strings
|
||||
//
|
||||
|
||||
typedef struct _IP_ADDR_STRING {
|
||||
struct _IP_ADDR_STRING* Next;
|
||||
IP_ADDRESS_STRING IpAddress;
|
||||
IP_MASK_STRING IpMask;
|
||||
DWORD Context;
|
||||
} IP_ADDR_STRING, *PIP_ADDR_STRING;
|
||||
|
||||
//
|
||||
// ADAPTER_INFO - per-adapter information. All IP addresses are stored as
|
||||
// strings
|
||||
//
|
||||
|
||||
typedef struct _IP_ADAPTER_INFO {
|
||||
struct _IP_ADAPTER_INFO* Next;
|
||||
DWORD ComboIndex;
|
||||
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
|
||||
char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
|
||||
UINT AddressLength;
|
||||
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
|
||||
DWORD Index;
|
||||
UINT Type;
|
||||
UINT DhcpEnabled;
|
||||
PIP_ADDR_STRING CurrentIpAddress;
|
||||
IP_ADDR_STRING IpAddressList;
|
||||
IP_ADDR_STRING GatewayList;
|
||||
IP_ADDR_STRING DhcpServer;
|
||||
BOOL HaveWins;
|
||||
IP_ADDR_STRING PrimaryWinsServer;
|
||||
IP_ADDR_STRING SecondaryWinsServer;
|
||||
time_t LeaseObtained;
|
||||
time_t LeaseExpires;
|
||||
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
|
||||
|
||||
#ifdef _WINSOCK2API_
|
||||
|
||||
//
|
||||
// The following types require Winsock2.
|
||||
//
|
||||
|
||||
typedef enum {
|
||||
IpPrefixOriginOther = 0,
|
||||
IpPrefixOriginManual,
|
||||
IpPrefixOriginWellKnown,
|
||||
IpPrefixOriginDhcp,
|
||||
IpPrefixOriginRouterAdvertisement,
|
||||
} IP_PREFIX_ORIGIN;
|
||||
|
||||
typedef enum {
|
||||
IpSuffixOriginOther = 0,
|
||||
IpSuffixOriginManual,
|
||||
IpSuffixOriginWellKnown,
|
||||
IpSuffixOriginDhcp,
|
||||
IpSuffixOriginLinkLayerAddress,
|
||||
IpSuffixOriginRandom,
|
||||
} IP_SUFFIX_ORIGIN;
|
||||
|
||||
typedef enum {
|
||||
IpDadStateInvalid = 0,
|
||||
IpDadStateTentative,
|
||||
IpDadStateDuplicate,
|
||||
IpDadStateDeprecated,
|
||||
IpDadStatePreferred,
|
||||
} IP_DAD_STATE;
|
||||
|
||||
typedef struct _IP_ADAPTER_UNICAST_ADDRESS {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD Flags;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_UNICAST_ADDRESS *Next;
|
||||
SOCKET_ADDRESS Address;
|
||||
|
||||
IP_PREFIX_ORIGIN PrefixOrigin;
|
||||
IP_SUFFIX_ORIGIN SuffixOrigin;
|
||||
IP_DAD_STATE DadState;
|
||||
|
||||
ULONG ValidLifetime;
|
||||
ULONG PreferredLifetime;
|
||||
ULONG LeaseLifetime;
|
||||
} IP_ADAPTER_UNICAST_ADDRESS, *PIP_ADAPTER_UNICAST_ADDRESS;
|
||||
|
||||
typedef struct _IP_ADAPTER_ANYCAST_ADDRESS {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD Flags;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_ANYCAST_ADDRESS *Next;
|
||||
SOCKET_ADDRESS Address;
|
||||
} IP_ADAPTER_ANYCAST_ADDRESS, *PIP_ADAPTER_ANYCAST_ADDRESS;
|
||||
|
||||
typedef struct _IP_ADAPTER_MULTICAST_ADDRESS {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD Flags;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_MULTICAST_ADDRESS *Next;
|
||||
SOCKET_ADDRESS Address;
|
||||
} IP_ADAPTER_MULTICAST_ADDRESS, *PIP_ADAPTER_MULTICAST_ADDRESS;
|
||||
|
||||
//
|
||||
// Per-address Flags
|
||||
//
|
||||
#define IP_ADAPTER_ADDRESS_DNS_ELIGIBLE 0x01
|
||||
#define IP_ADAPTER_ADDRESS_TRANSIENT 0x02
|
||||
|
||||
typedef struct _IP_ADAPTER_DNS_SERVER_ADDRESS {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD Reserved;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_DNS_SERVER_ADDRESS *Next;
|
||||
SOCKET_ADDRESS Address;
|
||||
} IP_ADAPTER_DNS_SERVER_ADDRESS, *PIP_ADAPTER_DNS_SERVER_ADDRESS;
|
||||
|
||||
typedef struct _IP_ADAPTER_PREFIX {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD Flags;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_PREFIX *Next;
|
||||
SOCKET_ADDRESS Address;
|
||||
ULONG PrefixLength;
|
||||
} IP_ADAPTER_PREFIX, *PIP_ADAPTER_PREFIX;
|
||||
|
||||
//
|
||||
// Per-adapter Flags
|
||||
//
|
||||
#define IP_ADAPTER_DDNS_ENABLED 0x01
|
||||
#define IP_ADAPTER_REGISTER_ADAPTER_SUFFIX 0x02
|
||||
#define IP_ADAPTER_DHCP_ENABLED 0x04
|
||||
#define IP_ADAPTER_RECEIVE_ONLY 0x08
|
||||
#define IP_ADAPTER_NO_MULTICAST 0x10
|
||||
#define IP_ADAPTER_IPV6_OTHER_STATEFUL_CONFIG 0x20
|
||||
|
||||
//
|
||||
// OperStatus values from RFC 2863
|
||||
//
|
||||
typedef enum {
|
||||
IfOperStatusUp = 1,
|
||||
IfOperStatusDown,
|
||||
IfOperStatusTesting,
|
||||
IfOperStatusUnknown,
|
||||
IfOperStatusDormant,
|
||||
IfOperStatusNotPresent,
|
||||
IfOperStatusLowerLayerDown
|
||||
} IF_OPER_STATUS;
|
||||
|
||||
//
|
||||
// Scope levels from RFC 2373 used with ZoneIndices array.
|
||||
//
|
||||
typedef enum {
|
||||
ScopeLevelInterface = 1,
|
||||
ScopeLevelLink = 2,
|
||||
ScopeLevelSubnet = 3,
|
||||
ScopeLevelAdmin = 4,
|
||||
ScopeLevelSite = 5,
|
||||
ScopeLevelOrganization = 8,
|
||||
ScopeLevelGlobal = 14
|
||||
} SCOPE_LEVEL;
|
||||
|
||||
typedef struct _IP_ADAPTER_ADDRESSES {
|
||||
union {
|
||||
ULONGLONG Alignment;
|
||||
struct {
|
||||
ULONG Length;
|
||||
DWORD IfIndex;
|
||||
};
|
||||
};
|
||||
struct _IP_ADAPTER_ADDRESSES *Next;
|
||||
PCHAR AdapterName;
|
||||
PIP_ADAPTER_UNICAST_ADDRESS FirstUnicastAddress;
|
||||
PIP_ADAPTER_ANYCAST_ADDRESS FirstAnycastAddress;
|
||||
PIP_ADAPTER_MULTICAST_ADDRESS FirstMulticastAddress;
|
||||
PIP_ADAPTER_DNS_SERVER_ADDRESS FirstDnsServerAddress;
|
||||
PWCHAR DnsSuffix;
|
||||
PWCHAR Description;
|
||||
PWCHAR FriendlyName;
|
||||
BYTE PhysicalAddress[MAX_ADAPTER_ADDRESS_LENGTH];
|
||||
DWORD PhysicalAddressLength;
|
||||
DWORD Flags;
|
||||
DWORD Mtu;
|
||||
DWORD IfType;
|
||||
IF_OPER_STATUS OperStatus;
|
||||
DWORD Ipv6IfIndex;
|
||||
DWORD ZoneIndices[16];
|
||||
PIP_ADAPTER_PREFIX FirstPrefix;
|
||||
} IP_ADAPTER_ADDRESSES, *PIP_ADAPTER_ADDRESSES;
|
||||
|
||||
//
|
||||
// Flags used as argument to GetAdaptersAddresses().
|
||||
// "SKIP" flags are added when the default is to include the information.
|
||||
// "INCLUDE" flags are added when the default is to skip the information.
|
||||
//
|
||||
#define GAA_FLAG_SKIP_UNICAST 0x0001
|
||||
#define GAA_FLAG_SKIP_ANYCAST 0x0002
|
||||
#define GAA_FLAG_SKIP_MULTICAST 0x0004
|
||||
#define GAA_FLAG_SKIP_DNS_SERVER 0x0008
|
||||
#define GAA_FLAG_INCLUDE_PREFIX 0x0010
|
||||
#define GAA_FLAG_SKIP_FRIENDLY_NAME 0x0020
|
||||
|
||||
#endif /* _WINSOCK2API_ */
|
||||
|
||||
//
|
||||
// IP_PER_ADAPTER_INFO - per-adapter IP information such as DNS server list.
|
||||
//
|
||||
|
||||
typedef struct _IP_PER_ADAPTER_INFO {
|
||||
UINT AutoconfigEnabled;
|
||||
UINT AutoconfigActive;
|
||||
PIP_ADDR_STRING CurrentDnsServer;
|
||||
IP_ADDR_STRING DnsServerList;
|
||||
} IP_PER_ADAPTER_INFO, *PIP_PER_ADAPTER_INFO;
|
||||
|
||||
//
|
||||
// FIXED_INFO - the set of IP-related information which does not depend on DHCP
|
||||
//
|
||||
|
||||
typedef struct {
|
||||
char HostName[MAX_HOSTNAME_LEN + 4] ;
|
||||
char DomainName[MAX_DOMAIN_NAME_LEN + 4];
|
||||
PIP_ADDR_STRING CurrentDnsServer;
|
||||
IP_ADDR_STRING DnsServerList;
|
||||
UINT NodeType;
|
||||
char ScopeId[MAX_SCOPE_ID_LEN + 4];
|
||||
UINT EnableRouting;
|
||||
UINT EnableProxy;
|
||||
UINT EnableDns;
|
||||
} FIXED_INFO, *PFIXED_INFO;
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
#endif /*!MAX_ADAPTER_DESCRIPTION_LENGTH*/
|
||||
|
||||
#ifndef IP_INTERFACE_NAME_INFO_DEFINED
|
||||
#define IP_INTERFACE_NAME_INFO_DEFINED
|
||||
|
||||
typedef struct ip_interface_name_info {
|
||||
ULONG Index; // Interface Index
|
||||
ULONG MediaType; // Interface Types - see ipifcons.h
|
||||
UCHAR ConnectionType;
|
||||
UCHAR AccessType;
|
||||
GUID DeviceGuid; // Device GUID is the guid of the device
|
||||
// that IP exposes
|
||||
GUID InterfaceGuid; // Interface GUID, if not GUID_NULL is the
|
||||
// GUID for the interface mapped to the device.
|
||||
} IP_INTERFACE_NAME_INFO, *PIP_INTERFACE_NAME_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* from ipifcons.h */
|
||||
|
||||
#ifndef IF_TYPE_PPP
|
||||
#define IF_TYPE_PPP 23
|
||||
#endif
|
||||
|
||||
#ifndef IF_TYPE_SOFTWARE_LOOPBACK
|
||||
#define IF_TYPE_SOFTWARE_LOOPBACK 24
|
||||
#endif
|
||||
|
||||
#ifndef IF_TYPE_SLIP
|
||||
#define IF_TYPE_SLIP 28
|
||||
#endif
|
||||
|
||||
#ifndef IF_TYPE_TUNNEL
|
||||
#define IF_TYPE_TUNNEL 131
|
||||
#endif
|
||||
int enumInterfaces(JNIEnv *env, netif **netifPP);
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -43,14 +43,6 @@
|
||||
extern int enumAddresses_win(JNIEnv *env, netif *netifP, netaddr **netaddrPP);
|
||||
int getAddrsFromAdapter(IP_ADAPTER_ADDRESSES *ptr, netaddr **netaddrPP);
|
||||
|
||||
/* IP helper library routines */
|
||||
int (PASCAL FAR *GetIpAddrTable_fn)();
|
||||
int (PASCAL FAR *GetIfTable_fn)();
|
||||
int (PASCAL FAR *GetFriendlyIfIndex_fn)();
|
||||
int (PASCAL FAR *GetAdaptersAddresses_fn)();
|
||||
int (PASCAL FAR *GetAdaptersInfo_fn)();
|
||||
int (PASCAL FAR *GetNumberOfInterfaces_fn)();
|
||||
|
||||
#ifdef DEBUG
|
||||
void printnif (netif *nif) {
|
||||
#ifdef _WIN64
|
||||
@ -96,14 +88,14 @@ static int getAdapters (JNIEnv *env, IP_ADAPTER_ADDRESSES **adapters) {
|
||||
flags = GAA_FLAG_SKIP_DNS_SERVER;
|
||||
flags |= GAA_FLAG_SKIP_MULTICAST;
|
||||
flags |= GAA_FLAG_INCLUDE_PREFIX;
|
||||
ret = (*GetAdaptersAddresses_fn) (AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
if (ret == ERROR_BUFFER_OVERFLOW) {
|
||||
adapterInfo = (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len);
|
||||
if (adapterInfo == 0) {
|
||||
return -1;
|
||||
}
|
||||
bufsize = len;
|
||||
ret = (*GetAdaptersAddresses_fn) (AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
ret = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
}
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
free (adapterInfo);
|
||||
@ -133,7 +125,7 @@ IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env, jint index) {
|
||||
flags = GAA_FLAG_SKIP_DNS_SERVER;
|
||||
flags |= GAA_FLAG_SKIP_MULTICAST;
|
||||
flags |= GAA_FLAG_INCLUDE_PREFIX;
|
||||
val = (*GetAdaptersAddresses_fn) (AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
if (val == ERROR_BUFFER_OVERFLOW) {
|
||||
adapterInfo = (IP_ADAPTER_ADDRESSES *) realloc (adapterInfo, len);
|
||||
if (adapterInfo == 0) {
|
||||
@ -141,7 +133,7 @@ IP_ADAPTER_ADDRESSES *getAdapter (JNIEnv *env, jint index) {
|
||||
return NULL;
|
||||
}
|
||||
bufsize = len;
|
||||
val = (*GetAdaptersAddresses_fn) (AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
val = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, adapterInfo, &len);
|
||||
}
|
||||
if (val != ERROR_SUCCESS) {
|
||||
free (adapterInfo);
|
||||
@ -182,7 +174,7 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP)
|
||||
* as what previous JDK versions would return.
|
||||
*/
|
||||
|
||||
ret = enumInterfaces_win (env, netifPP);
|
||||
ret = enumInterfaces(env, netifPP);
|
||||
if (ret == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
@ -221,7 +213,7 @@ int getAllInterfacesAndAddresses (JNIEnv *env, netif **netifPP)
|
||||
* (b) IPv6 information for IPv6 only interfaces (probably tunnels)
|
||||
*
|
||||
* For compatibility with previous releases we use the naming
|
||||
* information gotten from enumInterfaces_win() for (a) entries
|
||||
* information gotten from enumInterfaces() for (a) entries
|
||||
* However, the index numbers are taken from the new API.
|
||||
*
|
||||
* The procedure is to go through the list of adapters returned
|
||||
@ -439,7 +431,8 @@ static jobject createNetworkInterfaceXP(JNIEnv *env, netif *ifs)
|
||||
netifObj = (*env)->NewObject(env, ni_class, ni_ctor);
|
||||
name = (*env)->NewStringUTF(env, ifs->name);
|
||||
if (ifs->dNameIsUnicode) {
|
||||
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName, wcslen ((PWCHAR)ifs->displayName));
|
||||
displayName = (*env)->NewString(env, (PWCHAR)ifs->displayName,
|
||||
(jsize)wcslen ((PWCHAR)ifs->displayName));
|
||||
} else {
|
||||
displayName = (*env)->NewStringUTF(env, ifs->displayName);
|
||||
}
|
||||
|
@ -39,10 +39,6 @@
|
||||
/* true if SO_RCVTIMEO is supported */
|
||||
jboolean isRcvTimeoutSupported = JNI_TRUE;
|
||||
|
||||
LPFN_GETADDRINFO getaddrinfo_ptr = NULL;
|
||||
LPFN_FREEADDRINFO freaddrinfo_ptr = NULL;
|
||||
LPFN_GETNAMEINFO getnameinfo_ptr = NULL;
|
||||
|
||||
/*
|
||||
* Table of Windows Sockets errors, the specific exception we
|
||||
* throw for the error, and the error text.
|
||||
@ -233,38 +229,15 @@ NET_GetFileDescriptorID(JNIEnv *env)
|
||||
|
||||
jint IPv6_supported()
|
||||
{
|
||||
HMODULE lib;
|
||||
int fd = socket(AF_INET6, SOCK_STREAM, 0) ;
|
||||
if (fd < 0) {
|
||||
SOCKET s = socket(AF_INET6, SOCK_STREAM, 0) ;
|
||||
if (s < 0) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
closesocket (fd);
|
||||
|
||||
if ((lib = LoadLibrary ("ws2_32.dll")) == NULL) {
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if ((getaddrinfo_ptr = (LPFN_GETADDRINFO)GetProcAddress (lib, "getaddrinfo")) == NULL) {
|
||||
FreeLibrary (lib);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if ((freeaddrinfo_ptr = (LPFN_FREEADDRINFO)GetProcAddress (lib, "freeaddrinfo")) == NULL) {
|
||||
FreeLibrary (lib);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
if ((getnameinfo_ptr = (LPFN_GETNAMEINFO)GetProcAddress (lib, "getnameinfo")) == NULL) {
|
||||
FreeLibrary (lib);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
FreeLibrary(lib);
|
||||
closesocket(s);
|
||||
|
||||
return JNI_TRUE;
|
||||
}
|
||||
|
||||
jboolean NET_addrtransAvailable() {
|
||||
return (jboolean)(getaddrinfo_ptr != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return the default TOS value
|
||||
*/
|
||||
@ -664,7 +637,7 @@ NET_BindV6(struct ipv6bind* b) {
|
||||
if (family == AF_INET && (b->addr->him4.sin_addr.s_addr != INADDR_ANY)) {
|
||||
/* bind to v4 only */
|
||||
int ret;
|
||||
ret = NET_Bind (b->ipv4_fd, (struct sockaddr *)b->addr,
|
||||
ret = NET_Bind ((int)b->ipv4_fd, (struct sockaddr *)b->addr,
|
||||
sizeof (struct sockaddr_in));
|
||||
if (ret == SOCKET_ERROR) {
|
||||
CLOSE_SOCKETS_AND_RETURN;
|
||||
@ -676,7 +649,7 @@ NET_BindV6(struct ipv6bind* b) {
|
||||
if (family == AF_INET6 && (!IN6_IS_ADDR_ANY(&b->addr->him6.sin6_addr))) {
|
||||
/* bind to v6 only */
|
||||
int ret;
|
||||
ret = NET_Bind (b->ipv6_fd, (struct sockaddr *)b->addr,
|
||||
ret = NET_Bind ((int)b->ipv6_fd, (struct sockaddr *)b->addr,
|
||||
sizeof (struct SOCKADDR_IN6));
|
||||
if (ret == SOCKET_ERROR) {
|
||||
CLOSE_SOCKETS_AND_RETURN;
|
||||
@ -691,15 +664,15 @@ NET_BindV6(struct ipv6bind* b) {
|
||||
memset (&oaddr, 0, sizeof(oaddr));
|
||||
if (family == AF_INET) {
|
||||
ofamily = AF_INET6;
|
||||
fd = b->ipv4_fd;
|
||||
ofd = b->ipv6_fd;
|
||||
fd = (int)b->ipv4_fd;
|
||||
ofd = (int)b->ipv6_fd;
|
||||
port = (u_short)GET_PORT (b->addr);
|
||||
IN6ADDR_SETANY (&oaddr.him6);
|
||||
oaddr.him6.sin6_port = port;
|
||||
} else {
|
||||
ofamily = AF_INET;
|
||||
ofd = b->ipv4_fd;
|
||||
fd = b->ipv6_fd;
|
||||
ofd = (int)b->ipv4_fd;
|
||||
fd = (int)b->ipv6_fd;
|
||||
port = (u_short)GET_PORT (b->addr);
|
||||
oaddr.him4.sin_family = AF_INET;
|
||||
oaddr.him4.sin_port = port;
|
||||
@ -744,11 +717,11 @@ NET_BindV6(struct ipv6bind* b) {
|
||||
b->ipv6_fd = SOCKET_ERROR;
|
||||
|
||||
/* create two new sockets */
|
||||
fd = socket (family, sotype, 0);
|
||||
fd = (int)socket (family, sotype, 0);
|
||||
if (fd == SOCKET_ERROR) {
|
||||
CLOSE_SOCKETS_AND_RETURN;
|
||||
}
|
||||
ofd = socket (ofamily, sotype, 0);
|
||||
ofd = (int)socket (ofamily, sotype, 0);
|
||||
if (ofd == SOCKET_ERROR) {
|
||||
CLOSE_SOCKETS_AND_RETURN;
|
||||
}
|
||||
@ -1001,10 +974,10 @@ NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout)
|
||||
}
|
||||
|
||||
int NET_Socket (int domain, int type, int protocol) {
|
||||
int sock;
|
||||
SOCKET sock;
|
||||
sock = socket (domain, type, protocol);
|
||||
if (sock != INVALID_SOCKET) {
|
||||
SetHandleInformation((HANDLE)(uintptr_t)sock, HANDLE_FLAG_INHERIT, FALSE);
|
||||
}
|
||||
return sock;
|
||||
return (int)sock;
|
||||
}
|
||||
|
@ -209,10 +209,6 @@ int
|
||||
);
|
||||
#endif
|
||||
|
||||
LPFN_GETADDRINFO getaddrinfo_ptr;
|
||||
LPFN_FREEADDRINFO freeaddrinfo_ptr;
|
||||
LPFN_GETNAMEINFO getnameinfo_ptr;
|
||||
|
||||
/* used to disable connection reset messages on Windows XP */
|
||||
#ifndef SIO_UDP_CONNRESET
|
||||
#define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
|
||||
@ -302,8 +298,6 @@ void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
|
||||
|
||||
void NET_ThrowSocketException(JNIEnv *env, char* msg);
|
||||
|
||||
jboolean NET_addrtransAvailable();
|
||||
|
||||
/*
|
||||
* differs from NET_Timeout() as follows:
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 2008, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2002, 2011, 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
|
||||
@ -30,6 +30,7 @@
|
||||
#include <iprtrmib.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <iphlpapi.h>
|
||||
|
||||
#include "jni_util.h"
|
||||
|
||||
@ -42,93 +43,17 @@
|
||||
#define IS_SL_FOUND(sts) (sts & STS_SL_FOUND)
|
||||
#define IS_NS_FOUND(sts) (sts & STS_NS_FOUND)
|
||||
|
||||
/*
|
||||
* Visual C++ SP3 (as required by J2SE 1.4.0) is missing some of
|
||||
* the definitions required for the IP helper library routines that
|
||||
* were added in Windows 98 & Windows 2000.
|
||||
*/
|
||||
#ifndef MAX_ADAPTER_NAME_LENGTH
|
||||
|
||||
#define MAX_ADAPTER_ADDRESS_LENGTH 8
|
||||
#define MAX_ADAPTER_DESCRIPTION_LENGTH 128
|
||||
#define MAX_ADAPTER_NAME_LENGTH 256
|
||||
#define MAX_HOSTNAME_LEN 128
|
||||
#define MAX_DOMAIN_NAME_LEN 128
|
||||
#define MAX_SCOPE_ID_LEN 256
|
||||
|
||||
typedef struct {
|
||||
char String[4 * 4];
|
||||
} IP_ADDRESS_STRING, *PIP_ADDRESS_STRING, IP_MASK_STRING, *PIP_MASK_STRING;
|
||||
|
||||
typedef struct _IP_ADDR_STRING {
|
||||
struct _IP_ADDR_STRING* Next;
|
||||
IP_ADDRESS_STRING IpAddress;
|
||||
IP_MASK_STRING IpMask;
|
||||
DWORD Context;
|
||||
} IP_ADDR_STRING, *PIP_ADDR_STRING;
|
||||
|
||||
typedef struct _IP_ADAPTER_INFO {
|
||||
struct _IP_ADAPTER_INFO* Next;
|
||||
DWORD ComboIndex;
|
||||
char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
|
||||
char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
|
||||
UINT AddressLength;
|
||||
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
|
||||
DWORD Index;
|
||||
UINT Type;
|
||||
UINT DhcpEnabled;
|
||||
PIP_ADDR_STRING CurrentIpAddress;
|
||||
IP_ADDR_STRING IpAddressList;
|
||||
IP_ADDR_STRING GatewayList;
|
||||
IP_ADDR_STRING DhcpServer;
|
||||
BOOL HaveWins;
|
||||
IP_ADDR_STRING PrimaryWinsServer;
|
||||
IP_ADDR_STRING SecondaryWinsServer;
|
||||
time_t LeaseObtained;
|
||||
time_t LeaseExpires;
|
||||
} IP_ADAPTER_INFO, *PIP_ADAPTER_INFO;
|
||||
|
||||
typedef struct _FIXED_INFO {
|
||||
char HostName[MAX_HOSTNAME_LEN + 4] ;
|
||||
char DomainName[MAX_DOMAIN_NAME_LEN + 4];
|
||||
PIP_ADDR_STRING CurrentDnsServer;
|
||||
IP_ADDR_STRING DnsServerList;
|
||||
UINT NodeType;
|
||||
char ScopeId[MAX_SCOPE_ID_LEN + 4];
|
||||
UINT EnableRouting;
|
||||
UINT EnableProxy;
|
||||
UINT EnableDns;
|
||||
} FIXED_INFO, *PFIXED_INFO;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* IP helper library routine used on 98/2000/XP */
|
||||
static int (PASCAL FAR *GetNetworkParams_fn)();
|
||||
static int (PASCAL FAR *GetAdaptersInfo_fn)();
|
||||
static int (PASCAL FAR *NotifyAddrChange_fn)();
|
||||
|
||||
/*
|
||||
* Routines to obtain domain name and name servers are OS specific
|
||||
*/
|
||||
typedef int (*LoadConfig)(char *sl, char *ns);
|
||||
static LoadConfig loadconfig_fn;
|
||||
|
||||
|
||||
/*
|
||||
* JNI ids
|
||||
*/
|
||||
/* JNI ids */
|
||||
static jfieldID searchlistID;
|
||||
static jfieldID nameserversID;
|
||||
|
||||
|
||||
/*
|
||||
* Utility routine to append s2 to s1 with a space delimiter.
|
||||
* strappend(s1="abc", "def") => "abc def"
|
||||
* strappend(s1="", "def") => "def
|
||||
*/
|
||||
void strappend(char *s1, char *s2) {
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
if (s2[0] == '\0') /* nothing to append */
|
||||
return;
|
||||
@ -145,356 +70,6 @@ void strappend(char *s1, char *s2) {
|
||||
strcat(s1, s2);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Windows 95/98/ME for static TCP/IP configuration.
|
||||
*
|
||||
* Use registry approach for statically configured TCP/IP settings.
|
||||
* Registry entries described in "MS TCP/IP and Windows 95 Networking"
|
||||
* (Microsoft TechNet site).
|
||||
*/
|
||||
static int loadStaticConfig9x(char *sl, char *ns) {
|
||||
LONG ret;
|
||||
HANDLE hKey;
|
||||
DWORD dwLen;
|
||||
ULONG ulType;
|
||||
char result[MAX_STR_LEN];
|
||||
int sts = STS_NO_CONFIG;
|
||||
|
||||
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
"SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP",
|
||||
0,
|
||||
KEY_READ,
|
||||
(PHKEY)&hKey);
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
/*
|
||||
* Determine suffix list
|
||||
*/
|
||||
result[0] = '\0';
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "SearchList", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
if ((ret != ERROR_SUCCESS) || (strlen(result) == 0)) {
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "Domain", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
}
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
assert(ulType == REG_SZ);
|
||||
if (strlen(result) > 0) {
|
||||
strappend(sl, result);
|
||||
sts |= STS_SL_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine DNS name server(s)
|
||||
*/
|
||||
result[0] = '\0';
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "NameServer", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
assert(ulType == REG_SZ);
|
||||
if (strlen(result) > 0) {
|
||||
strappend(ns, result);
|
||||
sts |= STS_NS_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Windows 95
|
||||
*
|
||||
* Use registry approach for statically configured TCP/IP settings
|
||||
* (see loadStaticConfig9x).
|
||||
*
|
||||
* If DHCP is used we examine the DHCP vendor specific extensions. We parse
|
||||
* this based on format described in RFC 2132.
|
||||
*
|
||||
* If Dial-up Networking (DUN) is used then this TCP/IP settings cannot
|
||||
* be determined here.
|
||||
*/
|
||||
static int loadConfig95(char *sl, char *ns) {
|
||||
int sts;
|
||||
int index;
|
||||
LONG ret;
|
||||
HANDLE hKey;
|
||||
DWORD dwLen;
|
||||
ULONG ulType;
|
||||
char optionInfo[MAX_STR_LEN];
|
||||
|
||||
/*
|
||||
* First try static configuration - if found we are done.
|
||||
*/
|
||||
sts = loadStaticConfig9x(sl, ns);
|
||||
if (IS_SL_FOUND(sts) && IS_NS_FOUND(sts)) {
|
||||
return sts;
|
||||
}
|
||||
|
||||
/*
|
||||
* Try DHCP. DHCP information is stored in :-
|
||||
* SYSTEM\CurrentControlSet\Services\VxD\DHCP\DhcpInfoXX
|
||||
*
|
||||
* The key is normally DhcpInfo00\OptionInfo (see Article Q255245 on
|
||||
* Microsoft site). However when multiple cards are added & removed we
|
||||
* have observed that it can be located in DhcpInfo{01,02, ...}.
|
||||
* As a hack we search all DhcpInfoXX keys until we find OptionInfo.
|
||||
*/
|
||||
for (index=0; index<99; index++) {
|
||||
char key[MAX_STR_LEN];
|
||||
sprintf(key, "SYSTEM\\CurrentControlSet\\Services\\VxD\\DHCP\\DhcpInfo%02d",
|
||||
index);
|
||||
|
||||
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, (PHKEY)&hKey);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
/* end of DhcpInfoXX entries */
|
||||
break;
|
||||
}
|
||||
|
||||
dwLen = sizeof(optionInfo);
|
||||
ret = RegQueryValueEx(hKey, "OptionInfo", NULL, &ulType,
|
||||
(LPBYTE)optionInfo, &dwLen);
|
||||
RegCloseKey(hKey);
|
||||
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
/* OptionInfo found */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If OptionInfo was found then we parse (as the 'options' field of
|
||||
* the DHCP packet - see RFC 2132).
|
||||
*/
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
unsigned int pos = 0;
|
||||
|
||||
while (pos < dwLen) {
|
||||
int code, len;
|
||||
|
||||
code = optionInfo[pos];
|
||||
pos++;
|
||||
if (pos >= dwLen) break; /* bad packet */
|
||||
|
||||
len = optionInfo[pos];
|
||||
pos++;
|
||||
|
||||
if (pos+len > dwLen) break; /* bad packet */
|
||||
|
||||
/*
|
||||
* Domain Name - see RFC 2132 section 3.17
|
||||
*/
|
||||
if (!IS_SL_FOUND(sts)) {
|
||||
if (code == 0xf) {
|
||||
char domain[MAX_STR_LEN];
|
||||
|
||||
assert(len < MAX_STR_LEN);
|
||||
|
||||
memcpy((void *)domain, (void *)&(optionInfo[pos]), (size_t)len);
|
||||
domain[len] = '\0';
|
||||
|
||||
strappend(sl, domain);
|
||||
sts |= STS_SL_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* DNS Option - see RFC 2132 section 3.8
|
||||
*/
|
||||
if (!IS_NS_FOUND(sts)) {
|
||||
if (code == 6 && (len % 4) == 0) {
|
||||
while (len > 0 && pos < dwLen) {
|
||||
char addr[32];
|
||||
sprintf(addr, "%d.%d.%d.%d",
|
||||
(unsigned char)optionInfo[pos],
|
||||
(unsigned char)optionInfo[pos+1],
|
||||
(unsigned char)optionInfo[pos+2],
|
||||
(unsigned char)optionInfo[pos+3]);
|
||||
pos += 4;
|
||||
len -= 4;
|
||||
|
||||
/*
|
||||
* Append to list of name servers
|
||||
*/
|
||||
strappend(ns, addr);
|
||||
sts |= STS_NS_FOUND;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Onto the next options
|
||||
*/
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
/*
|
||||
* Windows 98/ME
|
||||
*
|
||||
* Use registry approach for statically configured TCP/IP settings
|
||||
* (see loadStaticConfig9x).
|
||||
*
|
||||
* If configuration is not static then use IP helper library routine
|
||||
* GetNetworkParams to obtain the network settings which include the
|
||||
* domain name and the DNS servers. Note that we use the registry in
|
||||
* preference to GetNetworkParams as the domain name is not populated
|
||||
* by GetNetworkParams if the configuration is static.
|
||||
*/
|
||||
static int loadConfig98(char *sl, char *ns) {
|
||||
FIXED_INFO *infoP;
|
||||
ULONG size;
|
||||
DWORD ret;
|
||||
int sts;
|
||||
|
||||
/*
|
||||
* Use registry approach to pick up static configuation.
|
||||
*/
|
||||
sts = loadStaticConfig9x(sl, ns);
|
||||
if (IS_SL_FOUND(sts) && IS_NS_FOUND(sts)) {
|
||||
return sts;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use IP helper library to obtain dynamic configuration (DHCP and
|
||||
* DUN).
|
||||
*/
|
||||
size = sizeof(FIXED_INFO);
|
||||
infoP = (FIXED_INFO *)malloc(size);
|
||||
if (infoP) {
|
||||
ret = (*GetNetworkParams_fn)(infoP, &size);
|
||||
if (ret == ERROR_BUFFER_OVERFLOW) {
|
||||
infoP = (FIXED_INFO *)realloc(infoP, size);
|
||||
if (infoP != NULL)
|
||||
ret = (*GetNetworkParams_fn)(infoP, &size);
|
||||
}
|
||||
}
|
||||
if (infoP == NULL) {
|
||||
return sts;
|
||||
}
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
/*
|
||||
* Use DomainName if search-list not specified.
|
||||
*/
|
||||
if (!IS_SL_FOUND(sts)) {
|
||||
strappend(sl, infoP->DomainName);
|
||||
sts |= STS_SL_FOUND;
|
||||
}
|
||||
|
||||
/*
|
||||
* Use DnsServerList if not statically configured.
|
||||
*/
|
||||
if (!IS_NS_FOUND(sts)) {
|
||||
PIP_ADDR_STRING dnsP = &(infoP->DnsServerList);
|
||||
do {
|
||||
strappend(ns, (char *)&(dnsP->IpAddress));
|
||||
dnsP = dnsP->Next;
|
||||
} while (dnsP != NULL);
|
||||
sts |= STS_NS_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
free(infoP);
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Windows NT
|
||||
*
|
||||
* Use registry approach based on settings described in "TCP/IP and
|
||||
* NBT Configuration Parameters for Windows" - Article Q12062 on
|
||||
* Microsoft site.
|
||||
*
|
||||
* All non-RAS TCP/IP settings are stored in HKEY_LOCAL_MACHINE in
|
||||
* the SYSTEM\CurrentControlSet\Services\Tcpip\Parameters key.
|
||||
*
|
||||
* If SearchList if not provided then return Domain or DhcpDomain.
|
||||
* If Domain is specified it overrides DhcpDomain even if DHCP is
|
||||
* enabled.
|
||||
*
|
||||
* DNS name servers based on NameServer or DhcpNameServer settings.
|
||||
* NameServer overrides DhcpNameServer even if DHCP is enabled.
|
||||
*/
|
||||
static int loadConfigNT(char *sl, char *ns) {
|
||||
LONG ret;
|
||||
HANDLE hKey;
|
||||
DWORD dwLen;
|
||||
ULONG ulType;
|
||||
char result[MAX_STR_LEN];
|
||||
int sts = STS_NO_CONFIG;
|
||||
|
||||
ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
|
||||
0,
|
||||
KEY_READ,
|
||||
(PHKEY)&hKey);
|
||||
if (ret != ERROR_SUCCESS) {
|
||||
return sts;
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine search list
|
||||
*/
|
||||
result[0] = '\0';
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "SearchList", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
if ((ret != ERROR_SUCCESS) || (strlen(result) == 0)) {
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "Domain", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
if ((ret != ERROR_SUCCESS) || (strlen(result) == 0)) {
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "DhcpDomain", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
}
|
||||
}
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
assert(ulType == REG_SZ);
|
||||
if (strlen(result) > 0) {
|
||||
strappend(sl, result);
|
||||
sts |= STS_SL_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Determine DNS name server(s)
|
||||
*/
|
||||
result[0] = '\0';
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "NameServer", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
if ((ret != ERROR_SUCCESS) || (strlen(result) == 0)) {
|
||||
dwLen = sizeof(result);
|
||||
ret = RegQueryValueEx(hKey, "DhcpNameServer", NULL, &ulType,
|
||||
(LPBYTE)&result, &dwLen);
|
||||
}
|
||||
if (ret == ERROR_SUCCESS) {
|
||||
assert(ulType == REG_SZ);
|
||||
if (strlen(result) > 0) {
|
||||
strappend(ns, result);
|
||||
sts |= STS_NS_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Windows 2000/XP
|
||||
*
|
||||
@ -510,7 +85,7 @@ static int loadConfigNT(char *sl, char *ns) {
|
||||
* names of each adapter and then query the corresponding registry
|
||||
* settings to obtain NameServer/DhcpNameServer and Domain/DhcpDomain.
|
||||
*/
|
||||
static int loadConfig2000(char *sl, char *ns) {
|
||||
static int loadConfig(char *sl, char *ns) {
|
||||
IP_ADAPTER_INFO *adapterP;
|
||||
ULONG size;
|
||||
DWORD ret;
|
||||
@ -547,10 +122,10 @@ static int loadConfig2000(char *sl, char *ns) {
|
||||
*/
|
||||
size = sizeof(IP_ADAPTER_INFO);
|
||||
adapterP = (IP_ADAPTER_INFO *)malloc(size);
|
||||
ret = (*GetAdaptersInfo_fn)(adapterP, &size);
|
||||
ret = GetAdaptersInfo(adapterP, &size);
|
||||
if (ret == ERROR_BUFFER_OVERFLOW) {
|
||||
adapterP = (IP_ADAPTER_INFO *)realloc(adapterP, size);
|
||||
ret = (*GetAdaptersInfo_fn)(adapterP, &size);
|
||||
ret = GetAdaptersInfo(adapterP, &size);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -648,87 +223,15 @@ static int loadConfig2000(char *sl, char *ns) {
|
||||
|
||||
|
||||
/*
|
||||
* Initialization :-
|
||||
*
|
||||
* 1. Based on OS version set the function pointer for OS specific load
|
||||
* configuration routine.
|
||||
*
|
||||
* 2. On 98/2000/XP load the IP helper library.
|
||||
*
|
||||
* 3. Initialize JNI field IDs.
|
||||
*
|
||||
* Initialize JNI field IDs.
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_sun_net_dns_ResolverConfigurationImpl_init0(JNIEnv *env, jclass cls)
|
||||
{
|
||||
OSVERSIONINFO ver;
|
||||
jboolean loadHelperLibrary = JNI_TRUE;
|
||||
|
||||
/*
|
||||
* First we figure out which OS is running
|
||||
*/
|
||||
ver.dwOSVersionInfoSize = sizeof(ver);
|
||||
GetVersionEx(&ver);
|
||||
|
||||
if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
|
||||
if ((ver.dwMajorVersion == 4) && (ver.dwMinorVersion == 0)) {
|
||||
/*
|
||||
* Windows 95
|
||||
*/
|
||||
loadHelperLibrary = JNI_FALSE;
|
||||
loadconfig_fn = loadConfig95;
|
||||
} else {
|
||||
/*
|
||||
* Windows 98/ME
|
||||
*/
|
||||
loadHelperLibrary = JNI_TRUE;
|
||||
loadconfig_fn = loadConfig98;
|
||||
}
|
||||
}
|
||||
|
||||
if (ver.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
if (ver.dwMajorVersion <= 4) {
|
||||
/*
|
||||
* Windows NT
|
||||
*/
|
||||
loadHelperLibrary = JNI_FALSE;
|
||||
loadconfig_fn = loadConfigNT;
|
||||
} else {
|
||||
/*
|
||||
* Windows 2000/XP
|
||||
*/
|
||||
loadHelperLibrary = JNI_TRUE;
|
||||
loadconfig_fn = loadConfig2000;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* On 98/2000/XP we load the IP Helper Library.
|
||||
*/
|
||||
if (loadHelperLibrary) {
|
||||
HANDLE h = LoadLibrary("iphlpapi.dll");
|
||||
|
||||
if (h != NULL) {
|
||||
GetNetworkParams_fn = (int (PASCAL FAR *)())GetProcAddress(h, "GetNetworkParams");
|
||||
GetAdaptersInfo_fn = (int (PASCAL FAR *)())GetProcAddress(h, "GetAdaptersInfo");
|
||||
|
||||
NotifyAddrChange_fn = (int (PASCAL FAR *)())GetProcAddress(h, "NotifyAddrChange");
|
||||
}
|
||||
|
||||
if (GetNetworkParams_fn == NULL || GetAdaptersInfo_fn == NULL) {
|
||||
JNU_ThrowByName(env, "java/lang/UnsatisfiedLinkError", "iphlpapi.dll");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Get JNI ids
|
||||
*/
|
||||
searchlistID = (*env)->GetStaticFieldID(env, cls, "os_searchlist",
|
||||
"Ljava/lang/String;");
|
||||
nameserversID = (*env)->GetStaticFieldID(env, cls, "os_nameservers",
|
||||
"Ljava/lang/String;");
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -746,8 +249,7 @@ Java_sun_net_dns_ResolverConfigurationImpl_loadDNSconfig0(JNIEnv *env, jclass cl
|
||||
searchlist[0] = '\0';
|
||||
nameservers[0] = '\0';
|
||||
|
||||
/* call OS specific routine */
|
||||
(void)(*loadconfig_fn)(searchlist, nameservers);
|
||||
loadConfig(searchlist, nameservers);
|
||||
|
||||
/*
|
||||
* Populate static fields in sun.net.DefaultResolverConfiguration
|
||||
@ -772,17 +274,15 @@ Java_sun_net_dns_ResolverConfigurationImpl_notifyAddrChange0(JNIEnv *env, jclass
|
||||
HANDLE h;
|
||||
DWORD rc, xfer;
|
||||
|
||||
if (NotifyAddrChange_fn != NULL) {
|
||||
ol.hEvent = (HANDLE)0;
|
||||
rc = (*NotifyAddrChange_fn)(&h, &ol);
|
||||
if (rc == ERROR_IO_PENDING) {
|
||||
rc = GetOverlappedResult(h, &ol, &xfer, TRUE);
|
||||
if (rc != 0) {
|
||||
return 0; /* address changed */
|
||||
}
|
||||
ol.hEvent = (HANDLE)0;
|
||||
rc = NotifyAddrChange(&h, &ol);
|
||||
if (rc == ERROR_IO_PENDING) {
|
||||
rc = GetOverlappedResult(h, &ol, &xfer, TRUE);
|
||||
if (rc != 0) {
|
||||
return 0; /* address changed */
|
||||
}
|
||||
}
|
||||
|
||||
/* NotifyAddrChange not support or error */
|
||||
/* error */
|
||||
return -1;
|
||||
}
|
||||
|
@ -41,18 +41,6 @@
|
||||
#define SECURITY_WIN32
|
||||
#include "sspi.h"
|
||||
|
||||
|
||||
/*
|
||||
* OS calls loaded from DLL on intialization
|
||||
*/
|
||||
|
||||
static FREE_CREDENTIALS_HANDLE_FN pFreeCredentialsHandle;
|
||||
static ACQUIRE_CREDENTIALS_HANDLE_FN pAcquireCredentialsHandle;
|
||||
static FREE_CONTEXT_BUFFER_FN pFreeContextBuffer;
|
||||
static INITIALIZE_SECURITY_CONTEXT_FN pInitializeSecurityContext;
|
||||
static COMPLETE_AUTH_TOKEN_FN pCompleteAuthToken;
|
||||
static DELETE_SECURITY_CONTEXT_FN pDeleteSecurityContext;
|
||||
|
||||
static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle);
|
||||
|
||||
static jfieldID ntlm_ctxHandleID;
|
||||
@ -63,48 +51,8 @@ static HINSTANCE lib = NULL;
|
||||
JNIEXPORT void JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_initFirst
|
||||
(JNIEnv *env, jclass clazz)
|
||||
{
|
||||
OSVERSIONINFO version;
|
||||
UCHAR libName[MAX_PATH];
|
||||
|
||||
ntlm_ctxHandleID = (*env)->GetFieldID(env, clazz, "ctxHandle", "J");
|
||||
ntlm_crdHandleID = (*env)->GetFieldID(env, clazz, "crdHandle", "J");
|
||||
|
||||
version.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
||||
GetVersionEx (&version);
|
||||
|
||||
if (version.dwPlatformId == VER_PLATFORM_WIN32_NT) {
|
||||
strcpy (libName, "security.dll" );
|
||||
}
|
||||
else if (version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) {
|
||||
strcpy (libName, "secur32.dll" );
|
||||
}
|
||||
|
||||
lib = LoadLibrary (libName);
|
||||
|
||||
pFreeCredentialsHandle
|
||||
= (FREE_CREDENTIALS_HANDLE_FN) GetProcAddress(
|
||||
lib, "FreeCredentialsHandle" );
|
||||
|
||||
pAcquireCredentialsHandle
|
||||
= (ACQUIRE_CREDENTIALS_HANDLE_FN) GetProcAddress(
|
||||
lib, "AcquireCredentialsHandleA" );
|
||||
|
||||
pFreeContextBuffer
|
||||
= (FREE_CONTEXT_BUFFER_FN) GetProcAddress(
|
||||
lib, "FreeContextBuffer" );
|
||||
|
||||
pInitializeSecurityContext
|
||||
= (INITIALIZE_SECURITY_CONTEXT_FN) GetProcAddress(
|
||||
lib, "InitializeSecurityContextA" );
|
||||
|
||||
pCompleteAuthToken
|
||||
= (COMPLETE_AUTH_TOKEN_FN) GetProcAddress(
|
||||
lib, "CompleteAuthToken" );
|
||||
|
||||
pDeleteSecurityContext
|
||||
= (DELETE_SECURITY_CONTEXT_FN) GetProcAddress(
|
||||
lib, "DeleteSecurityContext" );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -158,17 +106,17 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
|
||||
|
||||
if ( pUser != NULL ) {
|
||||
AuthId.User = (unsigned char *) pUser;
|
||||
AuthId.UserLength = strlen( pUser );
|
||||
AuthId.UserLength = (unsigned long) strlen( pUser );
|
||||
}
|
||||
|
||||
if ( pPassword != NULL ) {
|
||||
AuthId.Password = (unsigned char *) pPassword;
|
||||
AuthId.PasswordLength = strlen( pPassword );
|
||||
AuthId.PasswordLength = (unsigned long) strlen( pPassword );
|
||||
}
|
||||
|
||||
if ( pDomain != NULL ) {
|
||||
AuthId.Domain = (unsigned char *) pDomain;
|
||||
AuthId.DomainLength = strlen( pDomain );
|
||||
AuthId.DomainLength = (unsigned long) strlen( pDomain );
|
||||
}
|
||||
|
||||
AuthId.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
|
||||
@ -176,7 +124,7 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
|
||||
pAuthId = NULL;
|
||||
}
|
||||
|
||||
ss = pAcquireCredentialsHandle(
|
||||
ss = AcquireCredentialsHandleA(
|
||||
NULL, "NTLM", SECPKG_CRED_OUTBOUND,
|
||||
NULL, pAuthId, NULL, NULL,
|
||||
pCred, <ime
|
||||
@ -258,7 +206,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
|
||||
* need to send the out buffer if there are bytes to send
|
||||
*/
|
||||
|
||||
ss = pInitializeSecurityContext(
|
||||
ss = InitializeSecurityContextA(
|
||||
pCred, pCtx, NULL, 0, 0, SECURITY_NATIVE_DREP,
|
||||
lastToken ? &InBuffDesc : NULL, 0, newContext, &OutBuffDesc,
|
||||
&ContextAttributes, <ime
|
||||
@ -274,7 +222,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
|
||||
}
|
||||
|
||||
if ((ss == SEC_I_COMPLETE_NEEDED) || (ss == SEC_I_COMPLETE_AND_CONTINUE) ) {
|
||||
ss = pCompleteAuthToken( pCtx, &OutBuffDesc );
|
||||
ss = CompleteAuthToken( pCtx, &OutBuffDesc );
|
||||
|
||||
if (ss < 0) {
|
||||
endSequence (pCred, pCtx);
|
||||
@ -300,12 +248,12 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
|
||||
|
||||
static void endSequence (PCredHandle credHand, PCtxtHandle ctxHandle) {
|
||||
if (credHand != 0) {
|
||||
pFreeCredentialsHandle (credHand);
|
||||
free (credHand);
|
||||
FreeCredentialsHandle(credHand);
|
||||
free(credHand);
|
||||
}
|
||||
|
||||
if (ctxHandle != 0) {
|
||||
pDeleteSecurityContext(ctxHandle);
|
||||
free (ctxHandle);
|
||||
DeleteSecurityContext(ctxHandle);
|
||||
free(ctxHandle);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user