private void btnAdd_Click(object sender, EventArgs e)
{
bool Input_Validated = true;
// First make sure that all boxes are filled out
if ((!string.IsNullOrEmpty(this.textBoxConnectionName.Text)) &&
(!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.textBoxConnectionName.Text = this.textBoxConnectionName.Text.Replace(' ', '_');
string ConnInfo = this.textBoxConnectionName.Text;
this.checkedListBoxRecordingName.Items.Add(ConnInfo);
ConnInfo = this.comboBoxNetworkInterface.Text;
this.listBoxLocalAddr.Items.Add(ConnInfo);
ConnInfo = this.txtboxIPAddress.Text;
this.listBoxIPAddress.Items.Add(ConnInfo);
ConnInfo = this.textboxPort.Text;
this.listBoxPort.Items.Add(ConnInfo);
UpdateForwardingCheckBoxes();
}
if (this.checkedListBoxRecordingName.Items.Count > 0)
{
this.checkedListBoxRecordingName.SelectedIndex = this.checkedListBoxRecordingName.Items.Count - 1;
}
if (checkedListBoxRecordingName.Items.Count == 10)
this.btnAdd.Enabled = false;
}