On link editor, only show nics that match (wlan/wport)

This commit is contained in:
Tim Young 2015-08-09 15:01:18 -06:00
parent 4b3d3d8f4f
commit 0b974171f6
3 changed files with 16 additions and 4 deletions

View File

@ -68,6 +68,7 @@ namespace EduNetworkBuilder
{ {
processing = true; processing = true;
Network myNet = NB.GetNetwork(); Network myNet = NB.GetNetwork();
NicType srcNicType = NicType.none;
string SrcHost=""; string SrcHost="";
if (lbSrcHost.SelectedItem != null) if (lbSrcHost.SelectedItem != null)
SrcHost = lbSrcHost.SelectedItem.ToString(); SrcHost = lbSrcHost.SelectedItem.ToString();
@ -76,7 +77,14 @@ namespace EduNetworkBuilder
DstHost = lbDstHost.SelectedItem.ToString(); DstHost = lbDstHost.SelectedItem.ToString();
string SrcNic = ""; string SrcNic = "";
if (lbSrcNic.SelectedItem != null) if (lbSrcNic.SelectedItem != null)
{
SrcNic = lbSrcNic.SelectedItem.ToString(); SrcNic = lbSrcNic.SelectedItem.ToString();
int sNicIndex = lbSrcNic.SelectedIndex;
NetworkDevice Src = myNet.ItemFromName(lbSrcHost.SelectedItem.ToString());
NetworkCard sNic = null;
if(Src != null) sNic = Src.NicFromName(lbSrcNic.SelectedItem.ToString());
if(sNic != null) srcNicType = sNic.GetNicType;
}
string DstNic = ""; string DstNic = "";
if (lbDstNic.SelectedItem != null) if (lbDstNic.SelectedItem != null)
DstNic = lbDstNic.SelectedItem.ToString(); DstNic = lbDstNic.SelectedItem.ToString();
@ -136,7 +144,7 @@ namespace EduNetworkBuilder
lbDstNic.Items.Clear(); lbDstNic.Items.Clear();
if (lbDstHost.SelectedIndex >= 0) if (lbDstHost.SelectedIndex >= 0)
{ {
List<string> dstNics = myNet.NetworkCardForHostList(lbDstHost.SelectedItem.ToString(),true,true); List<string> dstNics = myNet.NetworkCardForHostList(lbDstHost.SelectedItem.ToString(), true, true, srcNicType);
foreach (string tString in dstNics) foreach (string tString in dstNics)
{ {
lbDstNic.Items.Add(tString); lbDstNic.Items.Add(tString);

View File

@ -732,7 +732,7 @@ namespace EduNetworkBuilder
return false; return false;
} }
public List<string> NetworkCardForHostList(string hostname, bool OnlyUnused = true, bool OnlyLinkable = false) public List<string> NetworkCardForHostList(string hostname, bool OnlyUnused = true, bool OnlyLinkable = false, NicType fromNIC = NicType.none)
{ {
List<string> theList = new List<string>(); List<string> theList = new List<string>();
NetworkDevice tDevice; NetworkDevice tDevice;
@ -743,7 +743,7 @@ namespace EduNetworkBuilder
if(nc.hostname == hostname) if(nc.hostname == hostname)
{ {
tDevice = (NetworkDevice)nc; tDevice = (NetworkDevice)nc;
theList.AddRange(tDevice.NetworkCardStrings(OnlyUnused,OnlyLinkable)); theList.AddRange(tDevice.NetworkCardStrings(OnlyUnused,OnlyLinkable, fromNIC));
} }
} }
} }

View File

@ -621,7 +621,7 @@ namespace EduNetworkBuilder
} }
} }
public List<string> NetworkCardStrings(bool OnlyUnused=true, bool OnlyLinkable=false) public List<string> NetworkCardStrings(bool OnlyUnused=true, bool OnlyLinkable=false, NicType fromNic = NicType.none)
{ {
List<string> macStrings = new List<string>(); List<string> macStrings = new List<string>();
int counter = 0; int counter = 0;
@ -632,6 +632,10 @@ namespace EduNetworkBuilder
CanUse = nic.ConnectedLink == -1; //if it is not linked to anything CanUse = nic.ConnectedLink == -1; //if it is not linked to anything
if (OnlyLinkable && nic.GetNicType == NicType.vpn) CanUse = false; if (OnlyLinkable && nic.GetNicType == NicType.vpn) CanUse = false;
if (OnlyLinkable && nic.GetNicType == NicType.tun) CanUse = false; if (OnlyLinkable && nic.GetNicType == NicType.tun) CanUse = false;
if (fromNic != NicType.none &&
fromNic == NicType.wlan && nic.GetNicType != NicType.wport) CanUse = false;
if (fromNic != NicType.none &&
fromNic == NicType.wport && nic.GetNicType != NicType.wlan) CanUse = false;
if (nic.GetNicType != NicType.lo && (nic.GetNicType != NicType.management_interface || OnlyUnused == false)) if (nic.GetNicType != NicType.lo && (nic.GetNicType != NicType.management_interface || OnlyUnused == false))
{ {
if(CanUse) if(CanUse)