Class: Packetman::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/packetman/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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

#applicationObject

Returns the value of attribute application.



5
6
7
# File 'lib/packetman/config.rb', line 5

def application
  @application
end

#offsetObject

Returns the value of attribute offset.



5
6
7
# File 'lib/packetman/config.rb', line 5

def offset
  @offset
end

#offset_typeObject

Returns the value of attribute offset_type.



5
6
7
# File 'lib/packetman/config.rb', line 5

def offset_type
  @offset_type
end

#radixObject

Returns the value of attribute radix.



5
6
7
# File 'lib/packetman/config.rb', line 5

def radix
  @radix
end

#start_with_transportObject

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

#transportObject

Returns the value of attribute transport.



5
6
7
# File 'lib/packetman/config.rb', line 5

def transport
  @transport
end

#wildcardObject

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

#applicationsObject



17
18
19
# File 'lib/packetman/config.rb', line 17

def applications
  @applications ||= YAML.load(File.read(File.expand_path('../../../config/applications.yml', __FILE__)))
end

#offset_bitsObject



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

#optsObject



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.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_optsObject



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_queryObject



21
22
23
# File 'lib/packetman/config.rb', line 21

def payload_query
  protocols[transport]['payload_query'] unless start_with_transport
end

#protocolsObject



13
14
15
# File 'lib/packetman/config.rb', line 13

def protocols
  @protocols ||= YAML.load(File.read(File.expand_path('../../../config/protocols.yml', __FILE__)))
end