class Packetman::Config
Attributes
application[RW]
offset[RW]
offset_type[RW]
radix[RW]
start_with_transport[RW]
transport[RW]
wildcard[RW]
Public Class Methods
new()
click to toggle source
# File lib/packetman/config.rb, line 7 def initialize self.transport = "tcp" self.offset = 0 self.offset_type = :bits end
Public Instance Methods
application_override(app_name)
click to toggle source
FIXME figure out a way to do defaults so this can just set defaults
# 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()
click to toggle source
# File lib/packetman/config.rb, line 17 def applications @applications ||= YAML.load(File.read(File.expand_path('../../../config/applications.yml', __FILE__))) end
offset_bits()
click to toggle source
# File lib/packetman/config.rb, line 25 def offset_bits if offset_type == :bytes offset*8 else offset end end
opts()
click to toggle source
# File lib/packetman/config.rb, line 40 def opts @opts ||= OptionParser.new do |opt| opt.banner = "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()
click to toggle source
# 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()
click to toggle source
# File lib/packetman/config.rb, line 21 def payload_query protocols[transport]['payload_query'] unless start_with_transport end
protocols()
click to toggle source
# File lib/packetman/config.rb, line 13 def protocols @protocols ||= YAML.load(File.read(File.expand_path('../../../config/protocols.yml', __FILE__))) end