Module: PacketGen::Proto

Defined in:
lib/packetgen/proto.rb

Overview

Module handling some helper methods for protocols

Author:

  • Sylvain Daubert

Since:

  • 2.1.2

Class Method Summary collapse

Class Method Details

.getprotobyname(name) ⇒ Integer?

Get protocol number from its name

Parameters:

  • name (String)

Returns:

  • (Integer, nil)

    return nil for unknown protocol names

Since:

  • 2.1.2



32
33
34
# File 'lib/packetgen/proto.rb', line 32

def self.getprotobyname(name)
  @cache[name]
end

.getprotobynumber(num) ⇒ String?

Get protocol name from its number

Parameters:

  • num (Integer)

Returns:

  • (String, nil)

    return nil for unknown protocol numbers

Since:

  • 2.1.2



39
40
41
# File 'lib/packetgen/proto.rb', line 39

def self.getprotobynumber(num)
  @cache.key(num)
end

.prepare_cacheObject

Since:

  • 2.1.2



18
19
20
21
22
23
24
25
26
# 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..].downcase
    number = Socket.const_get(const_sym)
    @cache[name] = number
  end
end