Module: PacketGen::Proto
- Defined in:
- lib/packetgen/proto.rb
Overview
Module handling some helper methods for protocols
Class Method Summary collapse
-
.getprotobyname(name) ⇒ Integer?
Get protocol number from its name.
-
.getprotobynumber(num) ⇒ String?
Get protocol name from its number.
- .prepare_cache ⇒ Object
Class Method Details
.getprotobyname(name) ⇒ Integer?
Get protocol number from its name
33 34 35 |
# File 'lib/packetgen/proto.rb', line 33 def self.getprotobyname(name) @cache[name] end |
.getprotobynumber(num) ⇒ String?
Get protocol name from its number
40 41 42 |
# File 'lib/packetgen/proto.rb', line 40 def self.getprotobynumber(num) @cache.key(num) end |
.prepare_cache ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/packetgen/proto.rb', line 19 def self.prepare_cache proto_constants = Socket.constants.grep(/IPPROTO_/) @cache = {} proto_constants.each do |const_sym| name = const_sym.to_s[8..].downcase number = Socket.const_get(const_sym) @cache[name] = number end end |