module PacketGen::Proto
Module handling some helper methods for protocols @author Sylvain Daubert @since 2.1.2
Public Class Methods
getprotobyname(name)
click to toggle source
Get protocol number from its name @param [String] name @return [Integer,nil] return nil for unknown protocol names
# File lib/packetgen/proto.rb, line 32 def self.getprotobyname(name) @cache[name] end
getprotobynumber(num)
click to toggle source
Get protocol name from its number @param [Integer] num @return [String,nil] return nil for unknown protocol numbers
# File lib/packetgen/proto.rb, line 39 def self.getprotobynumber(num) @cache.key(num) end
prepare_cache()
click to toggle source
@private cache information used by {.getprotobyname} and
{.getprotobynumber}
# File lib/packetgen/proto.rb, line 18 def self.prepare_cache proto_constants = Socket.constants.grep(/IPPROTO_/) @cache = {} proto_constants.each do |const_sym| name = const_sym.to_s[8..-1].downcase number = Socket.const_get(const_sym) @cache[name] = number end end