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



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

Parameters:

  • num (Integer)

Returns:

  • (String, nil)

    return nil for unknown protocol numbers

Since:

  • 2.1.2



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

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

.prepare_cacheObject

Since:

  • 2.1.2



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