public static IPAddressTextboxes brushTextboxes(string brush_string, IPAddressTextboxes textboxes) { var converter = new BrushConverter(); var brush = (Brush)converter.ConvertFromString(brush_string); IPAddressTextboxes tmp = textboxes; if (tmp.type == Textbox_FieldType.IP_ADDRESSBLOCK || tmp.type == Textbox_FieldType.NEW_SUBNETMASK_LONG || tmp.type == Textbox_FieldType.SUBNETMASK_LONG) { tmp.first.Background = brush; tmp.second.Background = brush; tmp.third.Background = brush; tmp.forth.Background = brush; return(tmp); } else if (tmp.type == Textbox_FieldType.DESIRED_HOSTNO || tmp.type == Textbox_FieldType.DESIRED_SUBNETNO || tmp.type == Textbox_FieldType.NEW_SUBNETMASK_SHORT || tmp.type == Textbox_FieldType.SUBNETMASK_SHORT) { tmp.first.Background = brush; return(tmp); } else { throw new WrongTypeException(); } }
public static IpV4_FieldStatus getFieldStatus(IPAddressTextboxes subnet_long, IPAddressTextboxes subnet_shortwritten) { bool shortFieldFilled = false; bool longFieldFilled = false; if (subnet_shortwritten.first.Text != "") { shortFieldFilled = true; } if (subnet_long.first.Text != "" || subnet_long.second.Text != "" || subnet_long.third.Text != "" || subnet_long.forth.Text != "") { longFieldFilled = true; } if (shortFieldFilled == true && longFieldFilled == false) { return(IpV4_FieldStatus.SHORTFILLED); } if (shortFieldFilled == false && longFieldFilled == true) { return(IpV4_FieldStatus.LONGFILLED); } if (shortFieldFilled == false && longFieldFilled == false) { return(IpV4_FieldStatus.NOFIELDSFILLED); } ; return(IpV4_FieldStatus.BOTHFILLED); }
public static bool isLegitHostNo(IPAddressTextboxes HostNo, IPAddressTextboxes subnet_short_old) { try { if (HostNo.type == Textbox_FieldType.DESIRED_HOSTNO) { if (subnet_short_old.type == Textbox_FieldType.SUBNETMASK_SHORT) { int maxHostNo = getMaxHostNo(subnet_short_old); int this_HostNo = tryParseTextboxToInt(HostNo.first); if (this_HostNo >= 0 && this_HostNo <= maxHostNo) { return(true); } else { return(false); } } else { throw new WrongTypeException(subnet_short_old, Textbox_FieldType.SUBNETMASK_SHORT); } } else { throw new WrongTypeException(HostNo, Textbox_FieldType.DESIRED_HOSTNO); } }catch (System.OverflowException) { return(false); } }
public static bool isLegitIpV4SubnetMask(IPAddressTextboxes newSubnetMask, IPAddressTextboxes oldSubnetMask) { try { if (oldSubnetMask.type == Textbox_FieldType.SUBNETMASK_SHORT) { if (newSubnetMask.type == Textbox_FieldType.NEW_SUBNETMASK_SHORT) { int shortDigit = tryParseTextboxToInt(newSubnetMask.first); int shortDigit_old = tryParseTextboxToInt(oldSubnetMask.first); if (shortDigit >= shortDigit_old && shortDigit <= 31) { return(true); } return(false); } else { throw new WrongTypeException(newSubnetMask, Textbox_FieldType.NEW_SUBNETMASK_SHORT); } } else { throw new WrongTypeException(oldSubnetMask, Textbox_FieldType.SUBNETMASK_SHORT); } }catch (System.OverflowException) { return(false); } }
public static int getMaxHostNo(IPAddressTextboxes subnet_short_old) { if (subnet_short_old.type == Textbox_FieldType.SUBNETMASK_SHORT) { return(calcHostNo(tryParseTextboxToInt(subnet_short_old.first))); } else { throw new WrongTypeException(subnet_short_old, Textbox_FieldType.SUBNETMASK_SHORT); } }
public static int calcHostNo(IPAddressTextboxes subnet_short_new) { if (subnet_short_new.type == Textbox_FieldType.NEW_SUBNETMASK_SHORT) { int tmp = 32 - tryParseTextboxToInt(subnet_short_new.first); tmp = ((int)Math.Pow(2, tmp)) - 2; return(tmp); } else { throw new WrongTypeException(subnet_short_new, Textbox_FieldType.NEW_SUBNETMASK_SHORT); } }
public static IPAddressTextboxes fillAddressBoxByByte(byte[] byte_array, IPAddressTextboxes to_overwrite) { int a = byte_array[0]; int b = byte_array[1]; int c = byte_array[2]; int d = byte_array[3]; to_overwrite.first.Text = a.ToString(); to_overwrite.second.Text = b.ToString(); to_overwrite.third.Text = c.ToString(); to_overwrite.forth.Text = d.ToString(); return(to_overwrite); }
public static bool isLegitIpV4SubnetMask(IPAddressTextboxes subnetMask) { if (isIpV4Digit(subnetMask.first, true) && isIpV4Digit(subnetMask.second, true) && isIpV4Digit(subnetMask.third, true) && isIpV4Digit(subnetMask.forth, true)) { byte first = byte.Parse(subnetMask.first.Text); byte second = byte.Parse(subnetMask.second.Text); byte third = byte.Parse(subnetMask.third.Text); byte forth = byte.Parse(subnetMask.forth.Text); if (first == 255) { if (second == 255) { if (third == 255) { return(true); } else { if (forth == 0) { return(true); } return(false); } } else { if (third == 0 && forth == 0) { return(true); } return(false); } } else { if (second == 0 && third == 0 && forth == 0) { return(true); } return(false); } } else { return(false); } }
private bool readStruct(IPAddressTextboxes boxes) { try { switch (boxes.type) { case Textbox_FieldType.IP_ADDRESSBLOCK: Ip4_textBox1 = checked (boxes.first); Ip4_textBox2 = checked (boxes.second); Ip4_textBox3 = checked (boxes.third); Ip4_textBox4 = checked (boxes.forth); break; case Textbox_FieldType.SUBNETMASK_LONG: Subnet_textBox1 = checked (boxes.first); Subnet_textBox2 = checked (boxes.second); Subnet_textBox3 = checked (boxes.third); Subnet_textBox4 = checked (boxes.forth); break; case Textbox_FieldType.NEW_SUBNETMASK_LONG: Subnet_textBox1_new = checked (boxes.first); Subnet_textBox2_new = checked (boxes.second); Subnet_textBox3_new = checked (boxes.third); Subnet_textBox4_new = checked (boxes.forth); break; case Textbox_FieldType.SUBNETMASK_SHORT: Subnet_textBox_ShortWritten = checked (boxes.first); break; case Textbox_FieldType.NEW_SUBNETMASK_SHORT: Subnet_textBox_ShortWritten_new = checked (boxes.first); break; case Textbox_FieldType.DESIRED_SUBNETNO: Subnet_desired = checked (boxes.first); break; case Textbox_FieldType.DESIRED_HOSTNO: Hosts_desired = checked (boxes.first); break; } return(true); }catch (System.OverflowException) { return(false); } }
public static int calcSubnetShort(IPAddressTextboxes desired_hostNo) { if (desired_hostNo.type == Textbox_FieldType.DESIRED_HOSTNO) { int x = tryParseTextboxToInt(desired_hostNo.first) + 2; if (x > 0) { double z = Math.Log(x) / Math.Log(2); double n = Math.Ceiling(z); return(32 - (int)n); } else { return(31); } } else { throw new WrongTypeException(desired_hostNo, Textbox_FieldType.DESIRED_HOSTNO); } }
public static int calcSubnetShort(IPAddressTextboxes subnetNo, IPAddressTextboxes subnet_shortwritten_old) { if (subnetNo.type == Textbox_FieldType.DESIRED_SUBNETNO || subnet_shortwritten_old.type == Textbox_FieldType.SUBNETMASK_SHORT) { if (tryParseTextboxToInt(subnetNo.first) == 0) { return(tryParseTextboxToInt(subnet_shortwritten_old.first)); } int tmp; double short_written = Math.Log(tryParseTextboxToInt(subnetNo.first), 2); tmp = (int)Math.Ceiling(short_written); if (tmp == 0) { tmp++; } return(tryParseTextboxToInt(subnet_shortwritten_old.first) + tmp); } else { throw new NotImplementedException(); } }
public static IPAddressTextboxes calcSubnetNo(IPAddressTextboxes SubnetNo, IPAddressTextboxes shortWritten, IPAddressTextboxes shortWritten_old) { if (shortWritten.type == Textbox_FieldType.NEW_SUBNETMASK_SHORT || shortWritten_old.type == Textbox_FieldType.SUBNETMASK_SHORT) { if (SubnetNo.type == Textbox_FieldType.DESIRED_SUBNETNO) { int tmp; int i_shortWritten = tryParseTextboxToInt(shortWritten.first); int i_shortWritten_old = tryParseTextboxToInt(shortWritten_old.first); tmp = (int)Math.Pow(2, i_shortWritten - i_shortWritten_old); SubnetNo.first.Text = tmp.ToString(); return(SubnetNo); } else { throw new WrongTypeException(SubnetNo, Textbox_FieldType.DESIRED_SUBNETNO); } } else { throw new NotImplementedException(); } }
public static IPAddressTextboxes Textboxes_Disabled(IPAddressTextboxes textboxes) { IPAddressTextboxes tmp = textboxes; if (tmp.type == Textbox_FieldType.IP_ADDRESSBLOCK || tmp.type == Textbox_FieldType.NEW_SUBNETMASK_LONG || tmp.type == Textbox_FieldType.SUBNETMASK_LONG) { tmp.first.IsReadOnly = true; tmp.second.IsReadOnly = true; tmp.third.IsReadOnly = true; tmp.forth.IsReadOnly = true; return(tmp); } else if (tmp.type == Textbox_FieldType.DESIRED_HOSTNO || tmp.type == Textbox_FieldType.DESIRED_SUBNETNO || tmp.type == Textbox_FieldType.NEW_SUBNETMASK_SHORT || tmp.type == Textbox_FieldType.SUBNETMASK_SHORT) { tmp.first.IsReadOnly = true; return(tmp); } else { throw new NotImplementedException(); } }
public WrongTypeException(IPAddressTextboxes exp_object, Textbox_FieldType expected) { MessageBox.Show(String.Format(Errorcodes.WRONGTYPE_ERRORMESSAGE, expected, exp_object.type), Errorcodes.WRONGTYPE_HEADER); }