/// <summary> /// Parses out the arguments of a UDPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List <string> tmp = new List <string>(args.Split(' ')); UDPPortRule rule = new UDPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // instead of an error message, we can just swap them if (p.start > p.end) { int temp = p.start; p.start = p.end; p.end = temp; } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception e) { // probably a parsing error; log it and throw an // exception so the rule isn't touched //LogCenter.WriteErrorLog(e); throw new Exception(); } return(rule); }
/// <summary> /// Parses out the arguments of a UDPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List<string> tmp = new List<string>(args.Split(' ')); UDPPortRule rule = new UDPPortRule(); rule.port_ranges = new List<PortRange>(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // instead of an error message, we can just swap them if (p.start > p.end) { int temp = p.start; p.start = p.end; p.end = temp; } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception e) { // probably a parsing error; log it and throw an // exception so the rule isn't touched //LogCenter.WriteErrorLog(e); throw new Exception(); } return rule; }
/// <summary> /// Parses out the arguments of a TCPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static TCPPortRule GenTCPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List <string> tmp = new List <string>(args.Split(' ')); TCPPortRule rule = new TCPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // someday we'll give more meaningful error messages, but // for now just throw an exception if they're doing something // dumb like range 200-50 if (p.start > p.end) { throw new Exception(); } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parsing error; log it // and throw an exception so the rule isn't changed //LogCenter.WriteErrorLog(e); throw new Exception(); } return(rule); }
/// <summary> /// Parses out the arguments of a TCPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static TCPPortRule GenTCPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List<string> tmp = new List<string>(args.Split(' ')); TCPPortRule rule = new TCPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // someday we'll give more meaningful error messages, but // for now just throw an exception if they're doing something // dumb like range 200-50 if (p.start > p.end) throw new Exception(); // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parsing error; log it // and throw an exception so the rule isn't changed //LogCenter.WriteErrorLog(e); throw new Exception(); } return rule; }