Mercurial > hg > Applications > TreeVNC
changeset 463:5bef0f09f088
create NetworkAddress class
author | mir3636 |
---|---|
date | Wed, 06 Jul 2016 18:12:33 +0900 (2016-07-06) |
parents | b5459c7c8e4d |
children | a817fa255673 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVNCNetwork.java |
diffstat | 2 files changed, 31 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Mon Jul 04 20:19:31 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeManagement.java Wed Jul 06 18:12:33 2016 +0900 @@ -11,11 +11,9 @@ private final int treeId; public LinkedList<TreeVNCNode> nodeList = new LinkedList<TreeVNCNode>(); - boolean runflag = false; + public LinkedList<NetworkAddress> treeAddresses = new LinkedList<NetworkAddress>(); private final int treebranch = 2; private boolean showTreeNode = false; - private byte[] netmask; - private byte[] netaddress; // node id // ttttnnnnnnnnnnnn // tttt 4bit tree number @@ -31,6 +29,18 @@ nodeList.add(me); } + private class NetworkAddress { + InetAddress inetaddress; + byte [] address; + byte [] netmask; + + public NetworkAddress(InetAddress ipaddress, byte[] netaddress, byte[] netmask) { + inetaddress = ipaddress; + address = netaddress; + this.netmask = netmask; + } + } + public int getTreeId() { return treeId; } @@ -254,17 +264,21 @@ return treebranch; } - public void setNetMask(byte[] netmask,byte[] netaddress) { - this.netmask = netmask; - this.netaddress = netaddress; + public void setNetMask(byte[] netmask, byte[] netaddress, InetAddress ipaddress) { + treeAddresses.add(new NetworkAddress(ipaddress,netaddress,netmask) ); } public boolean onTheSameNetwork(InetAddress adr) { byte [] byteadr = adr.getAddress(); - if (byteadr.length != netmask.length) return false; - for(int i=0; i < netmask.length; i++) { - if ((netmask[i] & byteadr[i])!=netaddress[i]) return false; + for (NetworkAddress n : treeAddresses) { + byte [] netmask = n.netmask; + byte [] netaddress = n.address; + if (byteadr.length != netmask.length) continue; + for (int i = 0; i < netmask.length; i++) { + if ((netmask[i] & byteadr[i]) != netaddress[i]) continue; + } + return true; } - return true; + return false; } } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVNCNetwork.java Mon Jul 04 20:19:31 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVNCNetwork.java Wed Jul 06 18:12:33 2016 +0900 @@ -30,23 +30,22 @@ for (Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces(); e.hasMoreElements();) { NetworkInterface ni = e.nextElement(); if (ni.isUp() && ni.supportsMulticast() && !ni.isLoopback()) { - for (InterfaceAddress ipaddress : ni.getInterfaceAddresses()) { - byte [] netmask = getNetMask(ipaddress); + TreeManagement treeManager = new TreeManagement(ni.getDisplayName(), ConnectionParams.DEFAULT_VNC_ROOT, myRfb.getViewer().getShowTree(),treeId++); + addNetworkInterface(ni, treeManager); // it looks like only last address is used + for (InterfaceAddress ipaddress : ni.getInterfaceAddresses()) { + byte [] netmask = getNetMask(ipaddress); String hostName = ipaddress.getAddress().toString(); if (useHostName) { hostName = ipaddress.getAddress().getHostName(); } - TreeManagement treeManager = new TreeManagement(hostName, ConnectionParams.DEFAULT_VNC_ROOT, myRfb.getViewer().getShowTree(),treeId); - treeManager.getList().getFirst().setPort(myRfb.getAcceptPort()); + treeManager.getList().getFirst().setPort(myRfb.getAcceptPort()); byte[] netaddr = ipaddress.getAddress().getAddress(); for(int i=0;i<netaddr.length;i++) { netaddr[i] &= netmask[i]; } - treeManager.setNetMask(netmask,netaddr); - addNetworkInterface(ni, treeManager); // it looks like only last address is used - System.out.println("Interfaces :" + ni.getName() + " treeId=" + treeId + " " + hostName); + treeManager.setNetMask(netmask,netaddr,ipaddress.getAddress()); + System.out.println("Interfaces :" + ni.getName() + " treeId=" + treeId + " " + hostName); } - treeId++; } } }