File: network_interface.rb

package info (click to toggle)
ruby-vmstat 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 344 kB
  • sloc: ruby: 1,136; ansic: 347; makefile: 3
file content (33 lines) | stat: -rw-r--r-- 1,323 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module Vmstat
  # Gathered the network interface information.
  # @attr [Symbol] name the system name for the network interface.
  # @attr [Fixnum] in_bytes the number od bytes that where received inbound.
  # @attr [Fixnum] in_errors the number of errors that where received inbound.
  # @attr [Fixnum] in_drops the number of drops that where received inbound.
  # @attr [Fixnum] out_bytes the number od bytes that where send outbound.
  # @attr [Fixnum] out_errors the number od errors that where send outbound.
  # @attr [Fixnum] type the type of the interface (bsd numbers)
  class NetworkInterface < Struct.new(:name, :in_bytes, :in_errors, :in_drops,
                                      :out_bytes, :out_errors, :type)

    # The type of ethernet devices on freebsd/mac os x
    ETHERNET_TYPE = 0x06

    # The type of loopback devices on freebsd/mac os x
    LOOPBACK_TYPE = 0x18

    # Checks if this network interface is a loopback device.
    # @return [TrueClass, FalseClass] true if it is a loopback device, false
    #   otherwise.
    def loopback?
      type == LOOPBACK_TYPE
    end

    # Checks if this network interface is a ethernet device.
    # @return [TrueClass, FalseClass] true if it is a ethernet device, false
    #   otherwise.
    def ethernet?
      type == ETHERNET_TYPE
    end
  end
end