Skip to content

Commit

Permalink
Fix bug with recursive IP_ADDR_STRING ByReference
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Jul 8, 2018
1 parent 456fbae commit 5bac07c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 9 additions & 3 deletions contrib/platform/src/com/sun/jna/platform/win32/IPHlpAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,18 @@ class IP_ADDRESS_STRING extends Structure {
*/
@FieldOrder({ "Next", "IpAddress", "IpMask", "Context" })
class IP_ADDR_STRING extends Structure {
public IP_ADDR_STRING.ByReference Next;
public Pointer Next; // IP_ADDR_STRING
public IP_ADDRESS_STRING IpAddress;
public IP_ADDRESS_STRING IpMask;
public int Context;

public static class ByReference extends IP_ADDR_STRING implements Structure.ByReference {
public IP_ADDR_STRING(Pointer p) {
super(p);
read();
}

public IP_ADDR_STRING() {
super();
}
}

Expand All @@ -195,7 +201,7 @@ public static class ByReference extends IP_ADDR_STRING implements Structure.ByRe
class FIXED_INFO extends Structure {
public byte[] HostName = new byte[MAX_HOSTNAME_LEN + 4];
public byte[] DomainName = new byte[MAX_DOMAIN_NAME_LEN + 4];
public IP_ADDR_STRING.ByReference CurrentDnsServer; // IP_ADDR_STRING
public Pointer CurrentDnsServer; // IP_ADDR_STRING
public IP_ADDR_STRING DnsServerList;
public int NodeType;
public byte[] ScopeId = new byte[MAX_SCOPE_ID_LEN + 4];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

import com.sun.jna.Memory;
import com.sun.jna.platform.win32.IPHlpAPI.FIXED_INFO;
import com.sun.jna.platform.win32.IPHlpAPI.IP_ADDR_STRING;
import com.sun.jna.platform.win32.IPHlpAPI.MIB_IFROW;
import com.sun.jna.platform.win32.IPHlpAPI.MIB_IF_ROW2;
import com.sun.jna.ptr.IntByReference;
Expand Down Expand Up @@ -120,7 +121,7 @@ public void testGetNetworkParams() {
assertEquals(WinError.ERROR_SUCCESS, IPHlpAPI.INSTANCE.GetNetworkParams(buffer, bufferSize));

// Check all DNS servers are valid IPs
IPHlpAPI.IP_ADDR_STRING dns = buffer.DnsServerList;
IP_ADDR_STRING dns = buffer.DnsServerList;
while (dns != null) {
// Start with 16-char byte array
String addr = new String(dns.IpAddress.String);
Expand All @@ -131,7 +132,7 @@ public void testGetNetworkParams() {
}
// addr is now a dotted-notation IP string. Test valid
assertTrue(ValidIP.matcher(addr).matches());
dns = dns.Next;
dns = dns.Next == null ? null : new IP_ADDR_STRING(dns.Next);
}
}
}

0 comments on commit 5bac07c

Please sign in to comment.