Class: Packetman::Config
- Inherits:
-
Object
- Object
- Packetman::Config
- Defined in:
- lib/packetman/config.rb
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#offset_type ⇒ Object
Returns the value of attribute offset_type.
-
#radix ⇒ Object
Returns the value of attribute radix.
-
#start_with_transport ⇒ Object
Returns the value of attribute start_with_transport.
-
#transport ⇒ Object
Returns the value of attribute transport.
-
#wildcard ⇒ Object
Returns the value of attribute wildcard.
Instance Method Summary collapse
-
#application_override(app_name) ⇒ Object
FIXME figure out a way to do defaults so this can just set defaults.
- #applications ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #offset_bits ⇒ Object
- #opts ⇒ Object
- #parse_opts ⇒ Object
- #payload_query ⇒ Object
- #protocols ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 |
# File 'lib/packetman/config.rb', line 7 def initialize self.transport = "tcp" self.offset = 0 self.offset_type = :bits end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def application @application end |
#offset ⇒ Object
Returns the value of attribute offset.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def offset @offset end |
#offset_type ⇒ Object
Returns the value of attribute offset_type.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def offset_type @offset_type end |
#radix ⇒ Object
Returns the value of attribute radix.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def radix @radix end |
#start_with_transport ⇒ Object
Returns the value of attribute start_with_transport.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def start_with_transport @start_with_transport end |
#transport ⇒ Object
Returns the value of attribute transport.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def transport @transport end |
#wildcard ⇒ Object
Returns the value of attribute wildcard.
5 6 7 |
# File 'lib/packetman/config.rb', line 5 def wildcard @wildcard end |
Instance Method Details
#application_override(app_name) ⇒ Object
FIXME figure out a way to do defaults so this can just set defaults
34 35 36 37 38 |
# File 'lib/packetman/config.rb', line 34 def application_override(app_name) applications[app_name].each do |key, value| __send__("#{key}=", value) end end |
#applications ⇒ Object
17 18 19 |
# File 'lib/packetman/config.rb', line 17 def applications @applications ||= YAML.load(File.read(File.('../../../config/applications.yml', __FILE__))) end |
#offset_bits ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/packetman/config.rb', line 25 def offset_bits if offset_type == :bytes offset*8 else offset end end |
#opts ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/packetman/config.rb', line 40 def opts @opts ||= OptionParser.new do |opt| opt. = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS] FILTER_STRING" opt.on("-p", "--protocol PROTO", protocols.keys, "Transport Protocol (#{protocols.keys.join(',')})") { |v| self.transport = v } opt.on("-a", "--application APPLICATION", applications.keys, "Application Protocol (#{applications.keys.join(',')}) OVERRIDES ALL OTHER SETTINGS") { |v| application_override(v) } opt.on("-t", "--transport", "OFFSET starts at transport header instead of data payload") { |v| self.start_with_transport = v } opt.on("-r", "--radix RADIX", Integer, "Treat FILTER_STRING as RADIX instead of String") { |v| self.radix = v } opt.on("-o", "--offset OFFSET", Integer, "Offset in bits") { |v| self.offset = v } opt.on("-b", "--byte-offset", "Use 8-bit bytes instead of bits for offset") { |v| self.offset_type = :bytes if v } opt.on("-w", "--wildcard CHARACTER", "Treat CHARACTER as single-character wildcard") { |v| raise "invalid wildcard" if v.to_s.length > 1; self.wildcard = v } opt.on("--table", "Show transport header table") { puts Packetman::Table.new; throw :exit } opt.on("-v", "--version", "Show version") { puts Packetman::VERSION; throw :exit } end end |
#parse_opts ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/packetman/config.rb', line 55 def parse_opts unparsed_opts = opts.parse! if unparsed_opts.length < 1 puts opts throw :exit end unparsed_opts.join(" ") end |
#payload_query ⇒ Object
21 22 23 |
# File 'lib/packetman/config.rb', line 21 def payload_query protocols[transport]['payload_query'] unless start_with_transport end |
#protocols ⇒ Object
13 14 15 |
# File 'lib/packetman/config.rb', line 13 def protocols @protocols ||= YAML.load(File.read(File.('../../../config/protocols.yml', __FILE__))) end |