private bool ValidateConfigs()
{
IPAddress ipAddress = new IPAddress(0);
if (unloadIPv4 > 0 && NotActiveIPv4Routes > 0 && defaultInterfaceMode.SelectedIndex == 0 ||
unloadIPv4 > 0 && defaultInterfaceMode.SelectedIndex == 1)
{
if (defaultIPv4Interface.SelectedIndex == -1)
{
tabControl1.SelectTab(0);
new BalloonTip("Information", "Select the route's default IPv4 interface", defaultIPv4Interface, BalloonTip.ICON.INFO);
return false;
}
if (defaultIPv4GatewayMode.SelectedIndex != 3)
{
string ipv4Gateway = defaultIPv4Gateway.Text;
if (ipv4Gateway == "")
ipv4Gateway = "0.0.0.0";
if (!IPAddress.TryParse(ipv4Gateway, out ipAddress) ||
ipAddress.AddressFamily != System.Net.Sockets.AddressFamily.InterNetwork ||
Environment.OSVersion.Version.CompareTo(new Version("6.0")) > -1 && IP.CheckIfSameNetwork(ipv4Gateway, "0.0.0.0", "255.0.0.0") && !IP.CheckIfSameNetwork(ipv4Gateway, "0.0.0.0", "255.255.255.255") ||
Environment.OSVersion.Version.CompareTo(new Version("6.0")) < 0 && IP.CheckIfSameNetwork(ipv4Gateway, "0.0.0.0", "255.255.255.255") ||
IP.CheckIfSameNetwork(ipv4Gateway, "224.0.0.0", "224.0.0.0") ||
IP.CheckIfSameNetwork(ipv4Gateway, "240.0.0.0", "240.0.0.0"))
{
tabControl1.SelectTab(0);
new BalloonTip("Warning", "Invalid IPv4 gateway address", defaultIPv4Gateway, BalloonTip.ICON.WARNING);
return false;
}
defaultIPv4Gateway.Text = ipv4Gateway;
}
}
if (unloadIPv6 > 0 && NotActiveIPv6Routes > 0 && defaultInterfaceMode.SelectedIndex == 0 ||
unloadIPv6 > 0 && defaultInterfaceMode.SelectedIndex == 1)
{
if (defaultIPv6Interface.SelectedIndex == -1)
{
tabControl1.SelectTab(1);
new BalloonTip("Information", "Select the route's default IPv6 interface", defaultIPv6Interface, BalloonTip.ICON.INFO);
return false;
}
if (defaultIPv6GatewayMode.SelectedIndex != 3)
{
string ipv6Gateway = defaultIPv6Gateway.Text;
if (ipv6Gateway == "")
ipv6Gateway = "0.0.0.0";
if (!IP.ValidateIPv6(ref ipv6Gateway))
// && !Regex.IsMatch(gateway, @"^(::1|::)$") && IPAddress.TryParse(gateway, out ipAddress) && ipAddress.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)
{
tabControl1.SelectTab(1);
new BalloonTip("Warning", "Invalid IPv6 gateway address", defaultIPv6Gateway, BalloonTip.ICON.WARNING);
return false;
}
defaultIPv6Gateway.Text = ipv6Gateway;
}
}
return true;
}