private void btnAddForwarding_Click(object sender, EventArgs e)
{
bool ChecForActivePassed = true;
// First check if forwarding connection is already active
switch ((int)this.numericUpDown1.Value)
{
case 1:
if (this.checkBoxF1.Checked)
ChecForActivePassed = false;
break;
case 2:
if (this.checkBoxF2.Checked)
ChecForActivePassed = false;
break;
case 3:
if (this.checkBoxF3.Checked)
ChecForActivePassed = false;
break;
case 4:
if (this.checkBoxF4.Checked)
ChecForActivePassed = false;
break;
case 5:
if (this.checkBoxF5.Checked)
ChecForActivePassed = false;
break;
case 6:
if (this.checkBoxF6.Checked)
ChecForActivePassed = false;
break;
case 7:
if (this.checkBoxF7.Checked)
ChecForActivePassed = false;
break;
case 8:
if (this.checkBoxF8.Checked)
ChecForActivePassed = false;
break;
case 9:
if (this.checkBoxF9.Checked)
ChecForActivePassed = false;
break;
case 10:
if (this.checkBoxF10.Checked)
ChecForActivePassed = false;
break;
}
if (ChecForActivePassed == false)
{
MessageBox.Show("Not allowed, connection currently active");
}
else
{
bool Input_Validated = true;
// First make sure that all required boxes are filled out
if ((!string.IsNullOrEmpty(this.txtboxIPAddress.Text)) &&
(!string.IsNullOrEmpty(this.comboBoxNetworkInterface.Text)) &&
(!string.IsNullOrEmpty(this.textboxPort.Text)))
{
IPAddress IP;
IPAddress Multicast;
// Validate that a valid IP address is entered
if ((IPAddress.TryParse(this.txtboxIPAddress.Text, out Multicast) != true) || (IPAddress.TryParse(this.comboBoxNetworkInterface.Text, out IP) != true))
{
MessageBox.Show("Not a valid IP address");
Input_Validated = false;
}
else // Add a check that this is a valid multicast address
{
UdpClient TempSock;
TempSock = new UdpClient(2222);// Port does not matter
// Open up a new socket with the net IP address and port number
try
{
TempSock.JoinMulticastGroup(Multicast, 50); // 50 is TTL value
}
catch
{
MessageBox.Show("Not valid Multicast address (has to be in range 224.0.0.0 to 239.255.255.255");
Input_Validated = false;
}
TempSock.Close();
}
int PortNumber;
if (int.TryParse(this.textboxPort.Text, out PortNumber) && (PortNumber >= 1 && PortNumber <= 65535))
{
}
else
{
MessageBox.Show("Invalid Port number");
Input_Validated = false;
}
}
else
{
MessageBox.Show("Please fill out all data fileds");
Input_Validated = false;
}
if (Input_Validated == true)
{
this.listBoxForwardingInterface.Items[(int)this.numericUpDown1.Value - 1] = this.comboBoxNetworkInterface.Text;
this.listBoxForwardingMulticast.Items[(int)this.numericUpDown1.Value - 1] = this.txtboxIPAddress.Text;
this.listBoxForwardingPort.Items[(int)this.numericUpDown1.Value - 1] = this.textboxPort.Text;
// Update the properties so the data gets saved accross sessions.
switch ((int)this.numericUpDown1.Value)
{
case 1:
Properties.Settings.Default.FrwdInterface1 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast1 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort1 = this.textboxPort.Text;
break;
case 2: Properties.Settings.Default.FrwdInterface2 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast2 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort2 = this.textboxPort.Text;
break;
case 3:
Properties.Settings.Default.FrwdInterface3 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast3 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort3 = this.textboxPort.Text;
break;
case 4:
Properties.Settings.Default.FrwdInterface4 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast4 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort4 = this.textboxPort.Text;
break;
case 5:
Properties.Settings.Default.FrwdInterface5 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast5 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort5 = this.textboxPort.Text;
break;
case 6:
Properties.Settings.Default.FrwdInterface6 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast6 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort6 = this.textboxPort.Text;
break;
case 7: Properties.Settings.Default.FrwdInterface7 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast7 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort7 = this.textboxPort.Text;
break;
case 8:
Properties.Settings.Default.FrwdInterface8 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast8 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort8 = this.textboxPort.Text;
break;
case 9:
Properties.Settings.Default.FrwdInterface9 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast9 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort9 = this.textboxPort.Text;
break;
case 10:
Properties.Settings.Default.FrwdInterface10 = this.comboBoxNetworkInterface.Text;
Properties.Settings.Default.FrwdMulticast10 = this.txtboxIPAddress.Text;
Properties.Settings.Default.FrwdPort10 = this.textboxPort.Text;
break;
}
Properties.Settings.Default.Save();
this.listBoxForwardingInterface.SelectedIndex = (int)this.numericUpDown1.Value - 1;
this.listBoxForwardingMulticast.SelectedIndex = (int)this.numericUpDown1.Value - 1;
this.listBoxForwardingPort.SelectedIndex = (int)this.numericUpDown1.Value - 1;
UpdateForwardingCheckBoxes();
}
}
}