# class GxG::Entity::LocalSystem

SysInfo provide default filesystem object

### Public Class Methods

new(bootstrap_data={}) click to toggle source
Calls superclass method

    # File lib/gxg/gxg_entities.rb, line 15
    def initialize(bootstrap_data={})
      # Rather than only using RUBY_PLATFORM, I want to define the *specific* environment on that platform to help further characterize what is at hand.
      super()
      # @thread_safety = ::Mutex.new
      @thread_safety = ::Mutex.new
      @details = {}
      #
      @details[:architecture] = bootstrap_data.delete(:architecture)
      #
      # ### Process bootstrap_data regarding platform and environment
      @details[:platform] = bootstrap_data.delete(:platform)
      @details[:platform_version] = GxG::Version.new(bootstrap_data.delete(:platform_version))
      @details[:platform_configuration] = {:process => {}, :flags => {}}
      @details[:environment] = bootstrap_data.delete(:environment)
      @details[:environment_variant] = bootstrap_data.delete(:environment_variant)
      if bootstrap_data[:environment_version]
        @details[:environment_version] = GxG::Version.new(bootstrap_data.delete(:environment_version))
      else
        @details[:environment_version] = nil
      end
      @details[:environment_configuration] = {}
      #
      # ### Process CPU info
      @details[:processors] = bootstrap_data.delete(:processors)
      @details[:processors].process! do |item, selector, container|
        if selector.is_any?(::String, ::Symbol)
          # hash/struct processing
          if selector.is_a?(Symbol)
            key = selector
          else
            key = selector.to_s.to_sym
          end
          # massage data by key
          # [:processor, :vendor_id, :cpu_family, :model, :model_name, :stepping, :cpu_mhz, :cache_size, :physical_id, :siblings, :core_id, :cpu_cores, :apicid, :initial_apicid, ::fpu, :fpu_exception, :cpuid_level, :wp, :flags, :bogomips, :clflush_size, :cache_alignment, :address_sizes, :power_management]
          entry = nil
          case key
          when :processor, :cpu_family, :model, :stepping, :physical_id, :siblings, :core_id, :cpu_cores, :apicid, :initial_apicid, :cpuid_level, :clflush_size, :cache_alignment
            entry = item.to_s.numeric_values()
            if entry.is_a?(Hash)
              item = entry[:integer]
            end
          when :cpu_mhz, :bogomips
            entry = item.to_s.numeric_values()
            if entry.is_a?(Hash)
              item = entry[:float]
            end
          when :cache_size
            entry = item.to_s.numeric_values([:byte])
            if entry.is_a?(Hash)
              item = entry[:byte]
            end
          when :address_sizes
            entry = item.to_s.numeric_values([:bit],",")
            if entry.is_a?(Array)
              item = {:physical_bits => (entry[0][:bit] || entry[0][:integer]), :virtual_bits => (entry[1][:bit] || entry[1][:integer])}
            end
          when :flags
            item = item.to_s.split(" ").to_enum.map do |flag|
              flag.to_sym
            end
          end
          if item
            if container.is_a?(::Hash)
              container.delete(selector)
              container[(key)] = item
            end
          end
        end
        nil
      end
      # TODO: Build up a list of flags that the cpu supports and are *actually* in use (i.e. PAE, ...)
      @details[:platform_flags] = {}
      # Gather platform kernel configuration data for processing.
      case @details[:platform]
      when :linux
        release = (`uname -r`.split("\n")[0])
        likely_paths = ["/proc/config.gz",("/lib/modules/#{release}/build/.config"),("/usr/src/linux-#{release}/.config"),("/usr/src/linux-#{release}/configs/#{release}-#{@details[:architecture]}.config"),("/boot/config-#{release}")]
        raw_data = ""
        likely_paths.to_enum.each do |the_path|
          if ::File.exist?(the_path)
            # Note: at this point in everything it is ok for file io that blocks.
            if the_path == "/proc/config.gz"
              ::Zlib::GzipReader.open(the_path) { |gz|  raw_data = gz.read }
            else
              ::File.open(the_path, "r") { |i|  raw_data = i.read }
            end
            break
          end
        end
        # process raw_data (each line)
        raw_flags = {}
        raw_data.to_enum(:each_line).each do |line_text|
          flag = nil
          setting = nil
          if line_text.size > 0
            if line_text[0] == "#"
              if line_text.include?("is not set")
                # cull unset thing and make its value nil.
                flag = line_text[1..-1].scan(/[A-Z_]*/)[0]
                if flag.size > 0
                  # exclude redundant 'CONFIG' portion
                  flag = flag.split("_")[1..-1].join("_")
                else
                  flag = nil
                end
              end
            else
              flag, setting = line_text.split("=")
              # exclude redundant 'CONFIG' portion
              flag = flag.split("_")[1..-1].join("_")
              if (setting == "y" || setting == "y\n")
                setting = true
              end
              if (setting == "n" || setting == "n\n")
                setting = false
              end
            end
          end
          if (flag)
            raw_flags[(flag)] = setting
          end
        end
        raw_data = nil
        # Note: I am *loathe* to use strings instead of symbols in hashes generally, but I don't like what ruby does
        # with symbols and memory for temporary data sets (looking at you matz and my slapping hand twitches).
        universal_synonyms = {"X86_PAE" => "physical_address_extension"}
        universal_synonyms["X86_32_SMP"] = "symetric_multiprocessing"
        universal_synonyms["X86_64_SMP"] = "symetric_multiprocessing"
        universal_synonyms["X86_HT"] = "hyperthreading"
        universal_synonyms["SWAP"] = "virtual_memory"
        #
        raw_flags.each_pair do |selector,value|
          #
          if universal_synonyms[(selector)]
            # include the flag ONLY if it is actually enabled (in use) on this build of the kernel
            if value
              @details[:platform_configuration][:flags][(universal_synonyms[(selector)].to_sym)] = value
            end
          end
        end
        # end linux area
      end
      #
      # ### Memory crap:
      #
      # Set computational and storage/memory limits by platform and environment:
      # See (with respect to Ruby) : http://www.rubynotes.net/uk/operating-systems/windows/item/82-physical-memory-limits.html
      # Note: RVALUE size (consumption size) is determined in a completely separate manner than the limit size (according to cpu virtual addressing bits used).
      # default for 32 bit OS used:
      system_memory = self.memory()
      per_process_max = 2147483648
      case @details[:platform]
      when :linux
        # for :linux : See http://linuxfollies.blogspot.com/2010/10/linux-memory-limits-rlimits.html
        # Note: Process::getrlimit("AS") does not reflect the reality of total ram + total swap space as a limit.
        if @details[:processors][0][:address_sizes].is_a?(::Hash)
          if @details[:processors][0][:address_sizes][:virtual_bits] == 32
            if @details[:platform_configuration][:flags][:physical_address_extension]
              # ??? what does that do to the memory limit under 32 bits
              # 3.12GB rumored: 3350074490.88 (rounded-down)
              per_process_max = 3350074490
            else
              per_process_max = 3221225472
            end
          end
        end
        if @details[:processors][0][:address_sizes].is_a?(::Hash)
          if @details[:processors][0][:address_sizes][:virtual_bits] == 64
            # odd thing: they built 64bit computers that only have slots enough for 2GB max ram (imagine!)
            # So... to deal with this dilemma, I'm going to set the per_process_max to system_memory[:actual][:total] (:actual=RAM) unless it is really a full 8TB+.
            if system_memory[:actual][:total] >= 8796093022208
              per_process_max = 8796093022208
            else
              per_process_max = system_memory[:actual][:total]
            end
          end
        else
          # virtual bits reading NOT supported:
          if ([ -1 ].pack('l!').length * 8) == 32
            if @details[:platform_configuration][:flags][:physical_address_extension]
              # ??? what does that do to the memory limit under 32 bits
              # 3.12GB rumored: 3350074490.88 (rounded-down)
              per_process_max = 3350074490
            else
              per_process_max = 3221225472
            end
          end
          if ([ -1 ].pack('l!').length * 8) == 64
            if system_memory[:actual][:total] >= 8796093022208
              per_process_max = 8796093022208
            else
              per_process_max = system_memory[:actual][:total]
            end
          end
        end
      when :windows
        # for :windows : See http://msdn.microsoft.com/en-us/library/windows/desktop/aa366778%28v=vs.85%29.aspx
        # And "4GB-tuning' at http://msdn.microsoft.com/en-us/library/windows/desktop/bb613473%28v=vs.85%29.aspx
        # And "BCDEdit /set' at http://msdn.microsoft.com/en-us/library/ff542202.aspx
        # TODO: :windows : find a way to test if IMAGE_FILE_LARGE_ADDRESS_AWARE is set, whether os runs in PAE mode, and
        # what BCDEdit /set Increaseuserva (gigabytes-as-megabytes) was set to. (kernel_mode address space = 4GB-(2048MB-to-3072MB value of it))
        # on infamous /3GB switch in boot.ini : http://www.ditii.com/2007/04/14/memory-management-demystifying-3gb/
        if @details[:processors][0][:address_sizes][:virtual_bits] == 32
          # :windows 32-bit : 2GB per process memory limit (non-contiguous-only)
          per_process_max = 2147483648
        end
        if @details[:processors][0][:address_sizes][:virtual_bits] == 64
          # :if IMAGE_FILE_LARGE_ADDRESS_AWARE is set on process image, then 8TB max per 64-bit process, except on Intel Itanium-based systems (7TB)
          # otherwise (if unset, and since we have no F'n way to tell within ruby):
          per_process_max = 2147483648
        end
      end
      #
      if system_memory[:total][:total] >= per_process_max
        @details[:memory_limits]={:process => ((per_process_max)..(system_memory[:total][:total]))}
      else
        @details[:memory_limits]={:process => ((system_memory[:total][:total])..(system_memory[:total][:total]))}
      end
      # stock setrlimit will ignore the 'hard-wired' limit reset to actual available memory (both kinds), but the overridden GxG::Engine::getrlimit(:AS) will respect it.
      # GxG::Engine::memory_available() is built around these limits to ensure you do not encounter an issue without some warning (no Exabyte delusions).
      # ::Process::setrlimit(:AS,@details[:memory_limits][:process].min,@details[:memory_limits][:process].max)
      #
      # ### Initial Buffer Sizes
      # TODO: find a clever way to determine the platform's maximum buffer size (after linux 2.6.14 (I think) buffers are now 16x4KiB).
      @details[:memory_limits][:buffers] = {:default => 4096, :terminal => 1024,:socket => {:ipc => {}}, :ipv4 => {:tcp => {}, :udp => {}}}
      # Attribution: http://www.psc.edu/networking/projects/tcptune/#detailed and
      # http://www.psc.edu/networking/projects/tcptune/#tutorial
      #
      case @details[:platform]
      when :linux
        # TODO: provide for better version comparisons: create >, <. etc methods that accept a string to interperet or a value instance.
        # See: http://www.pixelbeat.org/programming/stdio_buffering/
        platform_version = @details[:platform_version].value
        if platform_version[:major] > 2
          @details[:memory_limits][:buffers][:default] = 65536
        end
        if platform_version[:major] == 2
          if platform_version[:minor] >= 6
            if platform_version[:teeny] >= 14
              @details[:memory_limits][:buffers][:default] = 65536
            end
          end
        end
      end
      #
      # ### The Ruby runtime itself
      # Now defined in GxG::Engine as a chance to correct some 'free-form-jazz-ensemble-a-la-SpinalTap' stuff from the guys at Ruby Core! :)
      #
      # ### Network stuff
      # node (or host) name:
      @details[:nodename] = ::Socket.gethostname
      @details[:network] = {}
      begin
        address = ::TCPSocket.getaddress(@details[:nodename])
      rescue Exception
        # raise Exception, "You need to edit your host file, and add an alias for this host."
        # exit 1
        address = nil
      end
      # netstat --interfaces --all --verbose --extend
      #
      @details[:network][:hostname] = @details[:nodename]
      # TODO: @gather localhost info: convert ip address info to std. ip_addr objects
      @details[:network][:address] = address
      @details[:network][:hosts] = []
      #        raw_list = Sys::Host.info
      #        raw_list.to_enum.each do |entry|
      #          new_entry = {}
      #          entry.each_pair do |key,item|
      #            # TODO: @gather hosts info: convert ip address info to std. ip_addr objects
      #            new_entry[(key.to_sym)] = item
      #          end
      #          @details[:network][:hosts] << new_entry
      #          #
      #        end
      #
      # TODO: inventory each network interface and host address of the system
      # then, attach active, kernel supported, protocols
      # then, use self["a/setting/path"] to set the data for each setting of each protocol of each nic that is supported and active.
      protocols = {
        :ipv4=>{:settings=>{:tcp => {}, :udp => {}}, :aliases=>["IP"], :proto=>0},
        :icmp=>{:settings=>{}, :aliases=>["ICMP"], :proto=>1},
        :igmp=>{:settings=>{}, :aliases=>["IGMP"], :proto=>2},
        :ggp=>{:settings=>{}, :aliases=>["GGP"], :proto=>3},
        :ipencap=>{:settings=>{}, :aliases=>["IP-ENCAP"], :proto=>4},
        :st=>{:settings=>{}, :aliases=>["ST"], :proto=>5},
        :tcp=>{:settings=>{}, :aliases=>["TCP"], :proto=>6},
        :egp=>{:settings=>{}, :aliases=>["EGP"], :proto=>8},
        :igp=>{:settings=>{}, :aliases=>["IGP"], :proto=>9},
        :pup=>{:settings=>{}, :aliases=>["PUP"], :proto=>12},
        :udp=>{:settings=>{}, :aliases=>["UDP"], :proto=>17},
        :hmp=>{:settings=>{}, :aliases=>["HMP"], :proto=>20},
        :"xns-idp"=>{:settings=>{}, :aliases=>["XNS-IDP"], :proto=>22},
        :rdp=>{:settings=>{}, :aliases=>["RDP"], :proto=>27},
        :"iso-tp4"=>{:settings=>{}, :aliases=>["ISO-TP4"], :proto=>29},
        :dccp=>{:settings=>{}, :aliases=>["DCCP"], :proto=>33},
        :xtp=>{:settings=>{}, :aliases=>["XTP"], :proto=>36},
        :ddp=>{:settings=>{}, :aliases=>["DDP"], :proto=>37},
        :"idpr-cmtp"=>{:settings=>{}, :aliases=>["IDPR-CMTP"], :proto=>38},
        :ipv6=>{:settings=>{:tcp=>{}, :udp=>{}}, :aliases=>["IPv6"], :proto=>41},
        :"ipv6-route"=>{:settings=>{}, :aliases=>["IPv6-Route"], :proto=>43},
        :"ipv6-frag"=>{:settings=>{}, :aliases=>["IPv6-Frag"], :proto=>44},
        :idrp=>{:settings=>{}, :aliases=>["IDRP"], :proto=>45},
        :rsvp=>{:settings=>{}, :aliases=>["RSVP"], :proto=>46},
        :gre=>{:settings=>{}, :aliases=>["GRE"], :proto=>47},
        :esp=>{:settings=>{}, :aliases=>["IPSEC-ESP"], :proto=>50},
        :ah=>{:settings=>{}, :aliases=>["IPSEC-AH"], :proto=>51},
        :skip=>{:settings=>{}, :aliases=>["SKIP"], :proto=>57},
        :"ipv6-icmp"=>{:settings=>{}, :aliases=>["IPv6-ICMP"], :proto=>58},
        :"ipv6-nonxt"=>{:settings=>{}, :aliases=>["IPv6-NoNxt"], :proto=>59},
        :"ipv6-opts"=>{:settings=>{}, :aliases=>["IPv6-Opts"], :proto=>60},
        :rspf=>{:settings=>{}, :aliases=>["RSPF", "CPHB"], :proto=>73},
        :vmtp=>{:settings=>{}, :aliases=>["VMTP"], :proto=>81},
        :eigrp=>{:settings=>{}, :aliases=>["EIGRP"], :proto=>88},
        :ospf=>{:settings=>{}, :aliases=>["OSPFIGP"], :proto=>89},
        :"ax.25"=>{:settings=>{}, :aliases=>["AX.25"], :proto=>93},
        :ipip=>{:settings=>{}, :aliases=>["IPIP"], :proto=>94},
        :etherip=>{:settings=>{}, :aliases=>["ETHERIP"], :proto=>97},
        :encap=>{:settings=>{}, :aliases=>["ENCAP"], :proto=>98},
        :pim=>{:settings=>{}, :aliases=>["PIM"], :proto=>103},
        :ipcomp=>{:settings=>{}, :aliases=>["IPCOMP"], :proto=>108},
        :vrrp=>{:settings=>{}, :aliases=>["VRRP"], :proto=>112},
        :l2tp=>{:settings=>{}, :aliases=>["L2TP"], :proto=>115},
        :isis=>{:settings=>{}, :aliases=>["ISIS"], :proto=>124},
        :sctp=>{:settings=>{}, :aliases=>["SCTP"], :proto=>132},
        :fc=>{:settings=>{}, :aliases=>["FC"], :proto=>133},
        :"mobility-header"=>{:settings=>{}, :aliases=>["Mobility-Header"], :proto=>135},
        :udplite=>{:settings=>{}, :aliases=>["UDPLite"], :proto=>136},
        :"mpls-in-ip"=>{:settings=>{}, :aliases=>["MPLS-in-IP"], :proto=>137},
        :manet=>{:settings=>{}, :aliases=>[], :proto=>138},
        :hip=>{:settings=>{}, :aliases=>["HIP"], :proto=>139},
        :shim6=>{:settings=>{}, :aliases=>["Shim6"], :proto=>140},
        :wesp=>{:settings=>{}, :aliases=>["WESP"], :proto=>141},
        :rohc=>{:settings=>{}, :aliases=>["ROHC"], :proto=>142}
        }
      #
      @details[:network][:protocols] = protocols
      #        if @details[:platform] == :windows
      #          # TODO: find suitable alternative to Net::Proto.getprotoent (breaks under rbx)
      #        else
      #          raw_list = Net::Proto.getprotoent
      #          raw_list.to_enum.each do |entry|
      #            new_entry = {:settings => {}}
      #            proto_name = :unknown
      #            entry.each_pair do |key,item|
      #              if key.to_s.to_sym == :name
      #                if item.to_s.to_sym == :ip
      #                  proto_name = :ipv4
      #                else
      #                  proto_name = item.to_s.to_sym
      #                end
      #              else
      #                new_entry[(key)] = item
      #              end
      #            end
      #            if [:ipv4,:ipv6].include?(proto_name)
      #              new_entry[:settings][:tcp] = {}
      #              new_entry[:settings][:udp] = {}
      #            end
      #            @details[:network][:protocols][(proto_name)] = new_entry
      #            #
      #          end
      #        end
      # Read in Sysctl-style keys and set @details data.
      get_system_data(detail_mapping())
      #
      #
      # File descriptor reservation and release support, reserving $stdin, $stdout, and $stderr, etc.
      # TODO: get a *complete* list of getconf variables *and their meanings* and incorporate them into sysctl-style path system.
      # See: http://www.lainoox.com/system-wide-config-getconf/
      # self["configuration.process.maximum_file_descriptors"]
      # LATER: add lsof to requirements list within installer.
      case @details[:platform]
      when :linux, :aix, :solaris, :bsd, :darwin
        # TODO: research -F option of lsof
        # See: http://geek00l.blogspot.com/2006/03/openbsd-fstat-vs-lsof.html
      end
      #
      case @details[:platform]
      when :bsd
        # See: fstat vs lsof : http://geek00l.blogspot.com/2006/03/openbsd-fstat-vs-lsof.html
        #
        # if EventMachine::kqueue?
          # ?
          # @details[:maximum_descriptors][:events] = 1000000
        # end
      when :linux
        # if EventMachine::epoll?
          # ?
          # @details[:maximum_descriptors][:events] = 1000000
        # end
      end
      # ###
      @valid_modes = {}
      # Internal Services to Port Usage mapping
      @details[:service_ports] = {
        :tcpmux=>{:aliases=>[], :clients=>[], :description=>"TCP port service multiplexer", :usage=>{:tcp=>[1]}},
        :echo=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[7], :udp=>[7], :ddp=>[4]}},
        :discard=>{:aliases=>["sink", "null"], :clients=>[], :description=>"", :usage=>{:tcp=>[9], :udp=>[9]}},
        :systat=>{:aliases=>["users"], :clients=>[], :description=>"", :usage=>{:tcp=>[11]}},
        :daytime=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[13], :udp=>[13]}},
        :netstat=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[15]}},
        :qotd=>{:aliases=>["quote"], :clients=>[], :description=>"", :usage=>{:tcp=>[17]}},
        :msp=>{:aliases=>[], :clients=>[], :description=>"message send protocol", :usage=>{:tcp=>[18], :udp=>[18]}},
        :chargen=>{:aliases=>["ttytst", "source"], :clients=>[], :description=>"", :usage=>{:tcp=>[19], :udp=>[19]}},
        :"ftp-data"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[20]}},
        :ftp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[21]}},
        :fsp=>{:aliases=>["fspd"], :clients=>[], :description=>"", :usage=>{:udp=>[21]}},
        :ssh=>{:aliases=>[], :clients=>[], :description=>"SSH Remote Login Protocol", :usage=>{:tcp=>[22], :udp=>[22]}},
        :telnet=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[23]}},
        :smtp=>{:aliases=>["mail"], :clients=>[], :description=>"", :usage=>{:tcp=>[25]}},
        :time=>{:aliases=>["timserver"], :clients=>[], :description=>"", :usage=>{:tcp=>[37], :udp=>[37]}},
        :rlp=>{:aliases=>["resource"], :clients=>[], :description=>"resource location", :usage=>{:udp=>[39]}},
        :nameserver=>{:aliases=>["name"], :clients=>[], :description=>"IEN 116", :usage=>{:tcp=>[42]}},
        :whois=>{:aliases=>["nicname"], :clients=>[], :description=>"", :usage=>{:tcp=>[43]}},
        :tacacs=>{:aliases=>[], :clients=>[], :description=>"Login Host Protocol (TACACS)", :usage=>{:tcp=>[49], :udp=>[49]}},
        :"re-mail-ck"=>{:aliases=>[], :clients=>[], :description=>"Remote Mail Checking Protocol", :usage=>{:tcp=>[50], :udp=>[50]}},
        :domain=>{:aliases=>[], :clients=>[], :description=>"name-domain server", :usage=>{:tcp=>[53], :udp=>[53]}},
        :mtp=>{:aliases=>[], :clients=>[], :description=>"deprecated", :usage=>{:tcp=>[57]}},
        :"tacacs-ds"=>{:aliases=>[], :clients=>[], :description=>"TACACS-Database Service", :usage=>{:tcp=>[65], :udp=>[65]}},
        :bootps=>{:aliases=>[], :clients=>[], :description=>"BOOTP server", :usage=>{:tcp=>[67], :udp=>[67]}},
        :bootpc=>{:aliases=>[], :clients=>[], :description=>"BOOTP client", :usage=>{:tcp=>[68], :udp=>[68]}},
        :tftp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:udp=>[69]}},
        :gopher=>{:aliases=>[], :clients=>[], :description=>"Internet Gopher", :usage=>{:tcp=>[70], :udp=>[70]}},
        :rje=>{:aliases=>["netrjs"], :clients=>[], :description=>"", :usage=>{:tcp=>[77]}},
        :finger=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[79]}},
        :www=>{:aliases=>["http"], :clients=>[], :description=>"WorldWideWeb HTTP", :usage=>{:tcp=>[80], :udp=>[80]}},
        :link=>{:aliases=>["ttylink"], :clients=>[], :description=>"", :usage=>{:tcp=>[87]}},
        :kerberos=>{:aliases=>["kerberos5", "krb5", "kerberos-sec"], :clients=>[], :description=>"Kerberos v5", :usage=>{:tcp=>[88], :udp=>[88]}},
        :supdup=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[95]}},
        :hostnames=>{:aliases=>["hostname"], :clients=>[], :description=>"usually from sri-nic", :usage=>{:tcp=>[101]}},
        :"iso-tsap"=>{:aliases=>["tsap"], :clients=>[], :description=>"part of ISODE", :usage=>{:tcp=>[102]}},
        :"acr-nema"=>{:aliases=>["dicom"], :clients=>[], :description=>"Digital Imag. & Comm. 300", :usage=>{:tcp=>[104], :udp=>[104]}},
        :"csnet-ns"=>{:aliases=>["cso-ns"], :clients=>[], :description=>"also used by CSO name server", :usage=>{:tcp=>[105], :udp=>[105]}},
        :rtelnet=>{:aliases=>[], :clients=>[], :description=>"Remote Telnet", :usage=>{:tcp=>[107], :udp=>[107]}},
        :pop2=>{:aliases=>["postoffice", "pop-2"], :clients=>[], :description=>"POP version 2", :usage=>{:tcp=>[109], :udp=>[109]}},
        :pop3=>{:aliases=>["pop-3"], :clients=>[], :description=>"POP version 3", :usage=>{:tcp=>[110], :udp=>[110]}},
        :sunrpc=>{:aliases=>["portmapper"], :clients=>[], :description=>"RPC 4.0 portmapper", :usage=>{:tcp=>[111], :udp=>[111]}},
        :auth=>{:aliases=>["authentication", "tap", "ident"], :clients=>[], :description=>"", :usage=>{:tcp=>[113]}},
        :sftp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[115]}},
        :"uucp-path"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[117]}},
        :nntp=>{:aliases=>["readnews", "untp"], :clients=>[], :description=>"USENET News Transfer Protocol", :usage=>{:tcp=>[119]}},
        :ntp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[123], :udp=>[123]}},
        :pwdgen=>{:aliases=>[], :clients=>[], :description=>"PWDGEN service", :usage=>{:tcp=>[129], :udp=>[129]}},
        :"loc-srv"=>{:aliases=>["epmap"], :clients=>[], :description=>"Location Service", :usage=>{:tcp=>[135], :udp=>[135]}},
        :"netbios-ns"=>{:aliases=>[], :clients=>[], :description=>"NETBIOS Name Service", :usage=>{:tcp=>[137], :udp=>[137]}},
        :"netbios-dgm"=>{:aliases=>[], :clients=>[], :description=>"NETBIOS Datagram Service", :usage=>{:tcp=>[138], :udp=>[138]}},
        :"netbios-ssn"=>{:aliases=>[], :clients=>[], :description=>"NETBIOS session service", :usage=>{:tcp=>[139], :udp=>[139]}},
        :imap2=>{:aliases=>["imap"], :clients=>[], :description=>"Interim Mail Access P 2 and 4", :usage=>{:tcp=>[143], :udp=>[143]}},
        :snmp=>{:aliases=>[], :clients=>[], :description=>"Simple Net Mgmt Protocol", :usage=>{:tcp=>[161], :udp=>[161]}},
        :"snmp-trap"=>{:aliases=>["snmptrap"], :clients=>[], :description=>"Traps for SNMP", :usage=>{:tcp=>[162], :udp=>[162]}},
        :"cmip-man"=>{:aliases=>[], :clients=>[], :description=>"ISO mgmt over IP (CMOT)", :usage=>{:tcp=>[163], :udp=>[163]}},
        :"cmip-agent"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[164], :udp=>[164]}},
        :mailq=>{:aliases=>[], :clients=>[], :description=>"Mailer transport queue for Zmailer", :usage=>{:tcp=>[174], :udp=>[174]}},
        :xdmcp=>{:aliases=>[], :clients=>[], :description=>"X Display Mgr. Control Proto", :usage=>{:tcp=>[177], :udp=>[177]}},
        :nextstep=>{:aliases=>["NeXTStep", "NextStep"], :clients=>[], :description=>"NeXTStep window", :usage=>{:tcp=>[178], :udp=>[178]}},
        :bgp=>{:aliases=>[], :clients=>[], :description=>"Border Gateway Protocol", :usage=>{:tcp=>[179], :udp=>[179]}},
        :prospero=>{:aliases=>[], :clients=>[], :description=>"Cliff Neuman's Prospero", :usage=>{:tcp=>[191], :udp=>[191]}},
        :irc=>{:aliases=>[], :clients=>[], :description=>"Internet Relay Chat", :usage=>{:tcp=>[194], :udp=>[194]}},
        :smux=>{:aliases=>[], :clients=>[], :description=>"SNMP Unix Multiplexer", :usage=>{:tcp=>[199], :udp=>[199]}},
        :"at-rtmp"=>{:aliases=>[], :clients=>[], :description=>"AppleTalk routing", :usage=>{:tcp=>[201], :udp=>[201]}},
        :"at-nbp"=>{:aliases=>[], :clients=>[], :description=>"AppleTalk name binding", :usage=>{:tcp=>[202], :udp=>[202]}},
        :"at-echo"=>{:aliases=>[], :clients=>[], :description=>"AppleTalk echo", :usage=>{:tcp=>[204], :udp=>[204]}},
        :"at-zis"=>{:aliases=>[], :clients=>[], :description=>"AppleTalk zone information", :usage=>{:tcp=>[206], :udp=>[206]}},
        :qmtp=>{:aliases=>[], :clients=>[], :description=>"Quick Mail Transfer Protocol", :usage=>{:tcp=>[209], :udp=>[209]}},
        :z3950=>{:aliases=>["wais"], :clients=>[], :description=>"NISO Z39.50 database", :usage=>{:tcp=>[210], :udp=>[210]}},
        :ipx=>{:aliases=>[], :clients=>[], :description=>"IPX", :usage=>{:tcp=>[213], :udp=>[213]}},
        :imap3=>{:aliases=>[], :clients=>[], :description=>"Interactive Mail Access", :usage=>{:tcp=>[220], :udp=>[220]}},
        :pawserv=>{:aliases=>[], :clients=>[], :description=>"Perf Analysis Workbench", :usage=>{:tcp=>[345], :udp=>[345]}},
        :zserv=>{:aliases=>[], :clients=>[], :description=>"Zebra server", :usage=>{:tcp=>[346], :udp=>[346]}},
        :fatserv=>{:aliases=>[], :clients=>[], :description=>"Fatmen Server", :usage=>{:tcp=>[347], :udp=>[347]}},
        :rpc2portmap=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[369], :udp=>[369]}},
        :codaauth2=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[370], :udp=>[370]}},
        :clearcase=>{:aliases=>["Clearcase"], :clients=>[], :description=>"", :usage=>{:tcp=>[371], :udp=>[371]}},
        :ulistserv=>{:aliases=>[], :clients=>[], :description=>"UNIX Listserv", :usage=>{:tcp=>[372], :udp=>[372]}},
        :ldap=>{:aliases=>[], :clients=>[], :description=>"Lightweight Directory Access Protocol", :usage=>{:tcp=>[389], :udp=>[389]}},
        :imsp=>{:aliases=>[], :clients=>[], :description=>"Interactive Mail Support Protocol", :usage=>{:tcp=>[406], :udp=>[406]}},
        :svrloc=>{:aliases=>[], :clients=>[], :description=>"Server Location", :usage=>{:tcp=>[427], :udp=>[427]}},
        :https=>{:aliases=>[], :clients=>[], :description=>"http protocol over TLS/SSL", :usage=>{:tcp=>[443], :udp=>[443]}},
        :snpp=>{:aliases=>[], :clients=>[], :description=>"Simple Network Paging Protocol", :usage=>{:tcp=>[444], :udp=>[444]}},
        :"microsoft-ds"=>{:aliases=>[], :clients=>[], :description=>"Microsoft Naked CIFS", :usage=>{:tcp=>[445], :udp=>[445]}},
        :kpasswd=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[464], :udp=>[464]}},
        :saft=>{:aliases=>[], :clients=>[], :description=>"Simple Asynchronous File Transfer", :usage=>{:tcp=>[487], :udp=>[487]}},
        :isakmp=>{:aliases=>[], :clients=>[], :description=>"IPsec - Internet Security Association", :usage=>{:tcp=>[500], :udp=>[500]}},
        :rtsp=>{:aliases=>[], :clients=>[], :description=>"Real Time Stream Control Protocol", :usage=>{:tcp=>[554], :udp=>[554]}},
        :nqs=>{:aliases=>[], :clients=>[], :description=>"Network Queuing system", :usage=>{:tcp=>[607], :udp=>[607]}},
        :"npmp-local"=>{:aliases=>["dqs313_qmaster"], :clients=>[], :description=>"npmp-local / DQS", :usage=>{:tcp=>[610], :udp=>[610]}},
        :"npmp-gui"=>{:aliases=>["dqs313_execd"], :clients=>[], :description=>"npmp-gui / DQS", :usage=>{:tcp=>[611], :udp=>[611]}},
        :"hmmp-ind"=>{:aliases=>["dqs313_intercell"], :clients=>[], :description=>"HMMP Indication / DQS", :usage=>{:tcp=>[612], :udp=>[612]}},
        :qmqp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[628], :udp=>[628]}},
        :ipp=>{:aliases=>[], :clients=>[], :description=>"Internet Printing Protocol", :usage=>{:tcp=>[631], :udp=>[631]}},
        :exec=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[512]}},
        :biff=>{:aliases=>["comsat"], :clients=>[], :description=>"", :usage=>{:udp=>[512]}},
        :login=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[513]}},
        :who=>{:aliases=>["whod"], :clients=>[], :description=>"", :usage=>{:udp=>[513]}},
        :shell=>{:aliases=>["cmd"], :clients=>[], :description=>"no passwords used", :usage=>{:tcp=>[514]}},
        :syslog=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:udp=>[514]}},
        :printer=>{:aliases=>["spooler"], :clients=>[], :description=>"line printer spooler", :usage=>{:tcp=>[515]}},
        :talk=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:udp=>[517]}},
        :ntalk=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:udp=>[518]}},
        :route=>{:aliases=>["router", "routed"], :clients=>[], :description=>"RIP", :usage=>{:udp=>[520]}},
        :timed=>{:aliases=>["timeserver"], :clients=>[], :description=>"", :usage=>{:udp=>[525]}},
        :tempo=>{:aliases=>["newdate"], :clients=>[], :description=>"", :usage=>{:tcp=>[526]}},
        :courier=>{:aliases=>["rpc"], :clients=>[], :description=>"", :usage=>{:tcp=>[530]}},
        :conference=>{:aliases=>["chat"], :clients=>[], :description=>"", :usage=>{:tcp=>[531]}},
        :netnews=>{:aliases=>["readnews"], :clients=>[], :description=>"", :usage=>{:tcp=>[532]}},
        :netwall=>{:aliases=>[], :clients=>[], :description=>"for emergency broadcasts", :usage=>{:udp=>[533]}},
        :gdomap=>{:aliases=>[], :clients=>[], :description=>"GNUstep distributed objects", :usage=>{:tcp=>[538], :udp=>[538]}},
        :uucp=>{:aliases=>["uucpd"], :clients=>[], :description=>"uucp daemon", :usage=>{:tcp=>[540]}},
        :klogin=>{:aliases=>[], :clients=>[], :description=>"Kerberized `rlogin' (v5)", :usage=>{:tcp=>[543]}},
        :kshell=>{:aliases=>["krcmd"], :clients=>[], :description=>"Kerberized `rsh' (v5)", :usage=>{:tcp=>[544]}},
        :"dhcpv6-client"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[546], :udp=>[546]}},
        :"dhcpv6-server"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[547], :udp=>[547]}},
        :afpovertcp=>{:aliases=>[], :clients=>[], :description=>"AFP over TCP", :usage=>{:tcp=>[548], :udp=>[548]}},
        :idfp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[549], :udp=>[549]}},
        :remotefs=>{:aliases=>["rfs_server", "rfs"], :clients=>[], :description=>"Brunhoff remote filesystem", :usage=>{:tcp=>[556]}},
        :nntps=>{:aliases=>["snntp"], :clients=>[], :description=>"NNTP over SSL", :usage=>{:tcp=>[563], :udp=>[563]}},
        :submission=>{:aliases=>[], :clients=>[], :description=>"Submission [RFC4409]", :usage=>{:tcp=>[587], :udp=>[587]}},
        :ldaps=>{:aliases=>[], :clients=>[], :description=>"LDAP over SSL", :usage=>{:tcp=>[636], :udp=>[636]}},
        :tinc=>{:aliases=>[], :clients=>[], :description=>"tinc control port", :usage=>{:tcp=>[655], :udp=>[655]}},
        :silc=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[706], :udp=>[706]}},
        :"kerberos-adm"=>{:aliases=>[], :clients=>[], :description=>"Kerberos `kadmin' (v5)", :usage=>{:tcp=>[749]}},
        :webster=>{:aliases=>[], :clients=>[], :description=>"Network dictionary", :usage=>{:tcp=>[765], :udp=>[765]}},
        :rsync=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[873], :udp=>[873]}},
        :"ftps-data"=>{:aliases=>[], :clients=>[], :description=>"FTP over SSL (data)", :usage=>{:tcp=>[989]}},
        :ftps=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[990]}},
        :telnets=>{:aliases=>[], :clients=>[], :description=>"Telnet over SSL", :usage=>{:tcp=>[992], :udp=>[992]}},
        :imaps=>{:aliases=>[], :clients=>[], :description=>"IMAP over SSL", :usage=>{:tcp=>[993], :udp=>[993]}},
        :ircs=>{:aliases=>[], :clients=>[], :description=>"IRC over SSL", :usage=>{:tcp=>[994], :udp=>[994]}},
        :pop3s=>{:aliases=>[], :clients=>[], :description=>"POP-3 over SSL", :usage=>{:tcp=>[995], :udp=>[995]}},
        :socks=>{:aliases=>[], :clients=>[], :description=>"socks proxy server", :usage=>{:tcp=>[1080], :udp=>[1080]}},
        :proofd=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1093], :udp=>[1093]}},
        :rootd=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1094], :udp=>[1094]}},
        :openvpn=>{:aliases=>["vpn"], :clients=>[], :description=>"", :usage=>{:tcp=>[1194], :udp=>[1194]}, :usage_preference => :udp},
        :rmiregistry=>{:aliases=>[], :clients=>[], :description=>"Java RMI Registry", :usage=>{:tcp=>[1099], :udp=>[1099]}},
        :kazaa=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1214], :udp=>[1214]}},
        :nessus=>{:aliases=>[], :clients=>[], :description=>"Nessus vulnerability", :usage=>{:tcp=>[1241], :udp=>[1241]}},
        :lotusnote=>{:aliases=>[], :clients=>[], :description=>"Lotus Note", :usage=>{:tcp=>[1352], :udp=>[1352]}},
        :"ms-sql-s"=>{:aliases=>[], :clients=>[], :description=>"Microsoft SQL Server", :usage=>{:tcp=>[1433], :udp=>[1433]}},
        :"ms-sql-m"=>{:aliases=>[], :clients=>[], :description=>"Microsoft SQL Monitor", :usage=>{:tcp=>[1434], :udp=>[1434]}},
        :ingreslock=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1524], :udp=>[1524]}},
        :"prospero-np"=>{:aliases=>[], :clients=>[], :description=>"Prospero non-privileged", :usage=>{:tcp=>[1525], :udp=>[1525]}},
        :datametrics=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1645], :udp=>[1645]}},
        :"sa-msg-port"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1646], :udp=>[1646]}},
        :kermit=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1649], :udp=>[1649]}},
        :l2f=>{:aliases=>["l2tp"], :clients=>[], :description=>"", :usage=>{:tcp=>[1701], :udp=>[1701]}},
        :radius=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[1812], :udp=>[1812]}},
        :"radius-acct"=>{:aliases=>[], :clients=>[], :description=>"Radius Accounting", :usage=>{:tcp=>[1813], :udp=>[1813]}},
        :msnp=>{:aliases=>[], :clients=>[], :description=>"MSN Messenger", :usage=>{:tcp=>[1863], :udp=>[1863]}},
        :"unix-status"=>{:aliases=>[], :clients=>[], :description=>"remstats unix-status server", :usage=>{:tcp=>[1957]}},
        :"log-server"=>{:aliases=>[], :clients=>[], :description=>"remstats log server", :usage=>{:tcp=>[1958]}},
        :remoteping=>{:aliases=>[], :clients=>[], :description=>"remstats remoteping server", :usage=>{:tcp=>[1959]}},
        :"cisco-sccp"=>{:aliases=>[], :clients=>[], :description=>"Cisco SCCP", :usage=>{:tcp=>[2000], :udp=>[2000]}},
        :search=>{:aliases=>["ndtp"], :clients=>[], :description=>"", :usage=>{:tcp=>[2010]}},
        :pipe_server=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[2010]}},
        :nfs=>{:aliases=>[], :clients=>[], :description=>"Network File System", :usage=>{:tcp=>[2049], :udp=>[2049]}},
        :gnunet=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[2086], :udp=>[2086]}},
        :"rtcm-sc104"=>{:aliases=>[], :clients=>[], :description=>"RTCM SC-104 IANA 1/29/99", :usage=>{:tcp=>[2101], :udp=>[2101]}},
        :gsigatekeeper=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[2119], :udp=>[2119]}},
        :gris=>{:aliases=>[], :clients=>[], :description=>"Grid Resource Information Server", :usage=>{:tcp=>[2135], :udp=>[2135]}},
        :cvspserver=>{:aliases=>[], :clients=>[], :description=>"CVS client/server operations", :usage=>{:tcp=>[2401], :udp=>[2401]}},
        :venus=>{:aliases=>[], :clients=>[], :description=>"codacon port", :usage=>{:tcp=>[2430], :udp=>[2430]}},
        :"venus-se"=>{:aliases=>[], :clients=>[], :description=>"tcp side effects", :usage=>{:tcp=>[2431], :udp=>[2431]}},
        :codasrv=>{:aliases=>[], :clients=>[], :description=>"not used", :usage=>{:tcp=>[2432], :udp=>[2432]}},
        :"codasrv-se"=>{:aliases=>[], :clients=>[], :description=>"tcp side effects", :usage=>{:tcp=>[2433], :udp=>[2433]}},
        :mon=>{:aliases=>[], :clients=>[], :description=>"MON traps", :usage=>{:tcp=>[2583], :udp=>[2583]}},
        :dict=>{:aliases=>[], :clients=>[], :description=>"Dictionary server", :usage=>{:tcp=>[2628], :udp=>[2628]}},
        :gsiftp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[2811], :udp=>[2811]}},
        :gpsd=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[2947], :udp=>[2947]}},
        :gds_db=>{:aliases=>[], :clients=>[], :description=>"InterBase server", :usage=>{:tcp=>[3050], :udp=>[3050]}},
        :icpv2=>{:aliases=>["icp"], :clients=>[], :description=>"Internet Cache Protocol", :usage=>{:tcp=>[3130], :udp=>[3130]}},
        :mysql=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[3306], :udp=>[3306]}},
        :nut=>{:aliases=>[], :clients=>[], :description=>"Network UPS Tools", :usage=>{:tcp=>[3493], :udp=>[3493]}},
        :distcc=>{:aliases=>[], :clients=>[], :description=>"distributed compiler", :usage=>{:tcp=>[3632], :udp=>[3632]}},
        :daap=>{:aliases=>[], :clients=>[], :description=>"Digital Audio Access Protocol", :usage=>{:tcp=>[3689], :udp=>[3689]}},
        :svn=>{:aliases=>["subversion"], :clients=>[], :description=>"Subversion protocol", :usage=>{:tcp=>[3690], :udp=>[3690]}},
        :suucp=>{:aliases=>[], :clients=>[], :description=>"UUCP over SSL", :usage=>{:tcp=>[4031], :udp=>[4031]}},
        :sysrqd=>{:aliases=>[], :clients=>[], :description=>"sysrq daemon", :usage=>{:tcp=>[4094], :udp=>[4094]}},
        :sieve=>{:aliases=>[], :clients=>[], :description=>"ManageSieve Protocol", :usage=>{:tcp=>[4190]}},
        :epmd=>{:aliases=>[], :clients=>[], :description=>"Erlang Port Mapper Daemon", :usage=>{:tcp=>[4369], :udp=>[4369]}},
        :remctl=>{:aliases=>[], :clients=>[], :description=>"Remote Authenticated Command Service", :usage=>{:tcp=>[4373], :udp=>[4373]}},
        :iax=>{:aliases=>[], :clients=>[], :description=>"Inter-Asterisk eXchange", :usage=>{:tcp=>[4569], :udp=>[4569]}},
        :mtn=>{:aliases=>[], :clients=>[], :description=>"monotone Netsync Protocol", :usage=>{:tcp=>[4691], :udp=>[4691]}},
        :"radmin-port"=>{:aliases=>[], :clients=>[], :description=>"RAdmin Port", :usage=>{:tcp=>[4899], :udp=>[4899]}},
        :rfe=>{:aliases=>[], :clients=>[], :description=>"Radio Free Ethernet", :usage=>{:udp=>[5002], :tcp=>[5002]}},
        :mmcc=>{:aliases=>[], :clients=>[], :description=>"multimedia conference control tool (Yahoo IM)", :usage=>{:tcp=>[5050], :udp=>[5050]}},
        :sip=>{:aliases=>[], :clients=>[], :description=>"Session Initiation Protocol", :usage=>{:tcp=>[5060], :udp=>[5060]}},
        :"sip-tls"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[5061], :udp=>[5061]}},
        :aol=>{:aliases=>[], :clients=>[], :description=>"AIM", :usage=>{:tcp=>[5190], :udp=>[5190]}},
        :"xmpp-client"=>{:aliases=>[], :clients=>[], :description=>"Jabber Client Connection", :usage=>{:tcp=>[5222], :udp=>[5222]}},
        :"xmpp-server"=>{:aliases=>[], :clients=>[], :description=>"Jabber Server Connection", :usage=>{:tcp=>[5269], :udp=>[5269]}},
        :cfengine=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[5308], :udp=>[5308]}},
        :mdns=>{:aliases=>[], :clients=>[], :description=>"Multicast DNS", :usage=>{:tcp=>[5353], :udp=>[5353]}},
        :postgresql=>{:aliases=>[], :clients=>[], :description=>"PostgreSQL Database", :usage=>{:tcp=>[5432], :udp=>[5432]}},
        :freeciv=>{:aliases=>["rptp"], :clients=>[], :description=>"Freeciv gameplay", :usage=>{:tcp=>[5556], :udp=>[5556]}},
        :amqp=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[5672], :udp=>[5672], :sctp=>[5672]}},
        :ggz=>{:aliases=>[], :clients=>[], :description=>"GGZ Gaming Zone", :usage=>{:tcp=>[5688], :udp=>[5688]}},
        :x11=>{:aliases=>["x11-0"], :clients=>[], :description=>"X Window System", :usage=>{:tcp=>[6000], :udp=>[6000]}},
        :"x11-1"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6001], :udp=>[6001]}},
        :"x11-2"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6002], :udp=>[6002]}},
        :"x11-3"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6003], :udp=>[6003]}},
        :"x11-4"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6004], :udp=>[6004]}},
        :"x11-5"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6005], :udp=>[6005]}},
        :"x11-6"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6006], :udp=>[6006]}},
        :"x11-7"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[6007], :udp=>[6007]}},
        :"gnutella-svc"=>{:aliases=>[], :clients=>[], :description=>"gnutella", :usage=>{:tcp=>[6346], :udp=>[6346]}},
        :"gnutella-rtr"=>{:aliases=>[], :clients=>[], :description=>"gnutella", :usage=>{:tcp=>[6347], :udp=>[6347]}},
        :sge_qmaster=>{:aliases=>[], :clients=>[], :description=>"Grid Engine Qmaster Service", :usage=>{:tcp=>[6444], :udp=>[6444]}},
        :sge_execd=>{:aliases=>[], :clients=>[], :description=>"Grid Engine Execution Service", :usage=>{:tcp=>[6445], :udp=>[6445]}},
        :"mysql-proxy"=>{:aliases=>[], :clients=>[], :description=>"MySQL Proxy", :usage=>{:tcp=>[6446], :udp=>[6446]}},
        :"afs3-fileserver" => {:aliases => ["bbs"], :clients => [], :description => "file server itself", :usage => {:tcp => [7000], :udp => [7000]}},
        :"afs3-callback"=>{:aliases=>[], :clients=>[], :description=>"callbacks to cache managers", :usage=>{:tcp=>[7001], :udp=>[7001]}},
        :"afs3-prserver"=>{:aliases=>[], :clients=>[], :description=>"users & groups database", :usage=>{:tcp=>[7002], :udp=>[7002]}},
        :"afs3-vlserver"=>{:aliases=>[], :clients=>[], :description=>"volume location database", :usage=>{:tcp=>[7003], :udp=>[7003]}},
        :"afs3-kaserver"=>{:aliases=>[], :clients=>[], :description=>"AFS/Kerberos authentication", :usage=>{:tcp=>[7004], :udp=>[7004]}},
        :"afs3-volser"=>{:aliases=>[], :clients=>[], :description=>"volume managment server", :usage=>{:tcp=>[7005], :udp=>[7005]}},
        :"afs3-errors"=>{:aliases=>[], :clients=>[], :description=>"error interpretation service", :usage=>{:tcp=>[7006], :udp=>[7006]}},
        :"afs3-bos"=>{:aliases=>[], :clients=>[], :description=>"basic overseer process", :usage=>{:tcp=>[7007], :udp=>[7007]}},
        :"afs3-update"=>{:aliases=>[], :clients=>[], :description=>"server-to-server updater", :usage=>{:tcp=>[7008], :udp=>[7008]}},
        :"afs3-rmtsys"=>{:aliases=>[], :clients=>[], :description=>"remote cache manager service", :usage=>{:tcp=>[7009], :udp=>[7009]}},
        :"font-service"=>{:aliases=>[], :clients=>[], :description=>"X Font Service", :usage=>{:tcp=>[7100], :udp=>[7100]}},
        :"http-alt"=>{:aliases=>[], :clients=>[], :description=>"WWW caching service", :usage=>{:tcp=>[8080], :udp=>[8080]}},
        :"bacula-dir"=>{:aliases=>[], :clients=>[], :description=>"Bacula Director", :usage=>{:tcp=>[9101], :udp=>[9101]}},
        :"bacula-fd"=>{:aliases=>[], :clients=>[], :description=>"Bacula File Daemon", :usage=>{:tcp=>[9102], :udp=>[9102]}},
        :"bacula-sd"=>{:aliases=>[], :clients=>[], :description=>"Bacula Storage Daemon", :usage=>{:tcp=>[9103], :udp=>[9103]}},
        :xmms2=>{:aliases=>[], :clients=>[], :description=>"Cross-platform Music Multiplexing System", :usage=>{:tcp=>[9667], :udp=>[9667]}},
        :nbd=>{:aliases=>[], :clients=>[], :description=>"Linux Network Block Device", :usage=>{:tcp=>[10809]}},
        :"zabbix-agent"=>{:aliases=>[], :clients=>[], :description=>"Zabbix Agent", :usage=>{:tcp=>[10050], :udp=>[10050]}},
        :"zabbix-trapper"=>{:aliases=>[], :clients=>[], :description=>"Zabbix Trapper", :usage=>{:tcp=>[10051], :udp=>[10051]}},
        :amanda=>{:aliases=>[], :clients=>[], :description=>"amanda backup services", :usage=>{:tcp=>[10080], :udp=>[10080]}},
        :hkp=>{:aliases=>[], :clients=>[], :description=>"OpenPGP HTTP Keyserver", :usage=>{:tcp=>[11371], :udp=>[11371]}},
        :bprd=>{:aliases=>[], :clients=>[], :description=>"VERITAS NetBackup", :usage=>{:tcp=>[13720], :udp=>[13720]}},
        :bpdbm=>{:aliases=>[], :clients=>[], :description=>"VERITAS NetBackup", :usage=>{:tcp=>[13721], :udp=>[13721]}},
        :"bpjava-msvc"=>{:aliases=>[], :clients=>[], :description=>"BP Java MSVC Protocol", :usage=>{:tcp=>[13722], :udp=>[13722]}},
        :vnetd=>{:aliases=>[], :clients=>[], :description=>"Veritas Network Utility", :usage=>{:tcp=>[13724], :udp=>[13724]}},
        :bpcd=>{:aliases=>[], :clients=>[], :description=>"VERITAS NetBackup", :usage=>{:tcp=>[13782], :udp=>[13782]}},
        :vopied=>{:aliases=>[], :clients=>[], :description=>"VERITAS NetBackup", :usage=>{:tcp=>[13783], :udp=>[13783]}},
        :dcap=>{:aliases=>[], :clients=>[], :description=>"dCache Access Protocol", :usage=>{:tcp=>[22125]}},
        :gsidcap=>{:aliases=>[], :clients=>[], :description=>"GSI dCache Access Protocol", :usage=>{:tcp=>[22128]}},
        :wnn6=>{:aliases=>[], :clients=>[], :description=>"wnn6", :usage=>{:tcp=>[22273], :udp=>[22273]}},
        :rtmp=>{:aliases=>[], :clients=>[], :description=>"Routing Table Maintenance Protocol", :usage=>{:ddp=>[1]}},
        :nbp=>{:aliases=>[], :clients=>[], :description=>"Name Binding Protocol", :usage=>{:ddp=>[2]}},
        :zip=>{:aliases=>[], :clients=>[], :description=>"Zone Information Protocol", :usage=>{:ddp=>[6]}},
        :kerberos4=>{:aliases=>["kerberos-iv", "kdc"], :clients=>[], :description=>"Kerberos (server)", :usage=>{:udp=>[750], :tcp=>[750]}},
        :kerberos_master=>{:aliases=>[], :clients=>[], :description=>"Kerberos authentication", :usage=>{:udp=>[751], :tcp=>[751]}},
        :passwd_server=>{:aliases=>[], :clients=>[], :description=>"Kerberos passwd server", :usage=>{:udp=>[752]}},
        :krb_prop=>{:aliases=>["krb5_prop", "hprop"], :clients=>[], :description=>"Kerberos slave propagation", :usage=>{:tcp=>[754]}},
        :krbupdate=>{:aliases=>["kreg"], :clients=>[], :description=>"Kerberos registration", :usage=>{:tcp=>[760]}},
        :swat=>{:aliases=>[], :clients=>[], :description=>"swat", :usage=>{:tcp=>[901]}},
        :kpop=>{:aliases=>[], :clients=>[], :description=>"Pop with Kerberos", :usage=>{:tcp=>[1109]}},
        :knetd=>{:aliases=>[], :clients=>[], :description=>"Kerberos de-multiplexor", :usage=>{:tcp=>[2053]}},
        :"zephyr-srv"=>{:aliases=>[], :clients=>[], :description=>"Zephyr server", :usage=>{:udp=>[2102]}},
        :"zephyr-clt"=>{:aliases=>[], :clients=>[], :description=>"Zephyr serv-hm connection", :usage=>{:udp=>[2103]}},
        :"zephyr-hm"=>{:aliases=>[], :clients=>[], :description=>"Zephyr hostmanager", :usage=>{:udp=>[2104]}},
        :eklogin=>{:aliases=>[], :clients=>[], :description=>"Kerberos encrypted rlogin", :usage=>{:tcp=>[2105]}},
        :kx=>{:aliases=>[], :clients=>[], :description=>"X over Kerberos", :usage=>{:tcp=>[2111]}},
        :iprop=>{:aliases=>[], :clients=>[], :description=>"incremental propagation", :usage=>{:tcp=>[2121]}},
        :supfilesrv=>{:aliases=>[], :clients=>[], :description=>"SUP server", :usage=>{:tcp=>[871]}},
        :supfiledbg=>{:aliases=>[], :clients=>[], :description=>"SUP debugging", :usage=>{:tcp=>[1127]}},
        :linuxconf=>{:aliases=>[], :clients=>[], :description=>"LinuxConf", :usage=>{:tcp=>[98]}},
        :poppassd=>{:aliases=>[], :clients=>[], :description=>"Eudora", :usage=>{:tcp=>[106], :udp=>[106]}},
        :ssmtp=>{:aliases=>["smtps"], :clients=>[], :description=>"SMTP over SSL", :usage=>{:tcp=>[465]}},
        :moira_db=>{:aliases=>[], :clients=>[], :description=>"Moira database", :usage=>{:tcp=>[775]}},
        :moira_update=>{:aliases=>[], :clients=>[], :description=>"Moira update protocol", :usage=>{:tcp=>[777]}},
        :moira_ureg=>{:aliases=>[], :clients=>[], :description=>"Moira user registration", :usage=>{:udp=>[779]}},
        :spamd=>{:aliases=>[], :clients=>[], :description=>"spamassassin daemon", :usage=>{:tcp=>[783]}},
        :omirr=>{:aliases=>["omirrd"], :clients=>[], :description=>"online mirror", :usage=>{:tcp=>[808], :udp=>[808]}},
        :customs=>{:aliases=>[], :clients=>[], :description=>"pmake customs server", :usage=>{:tcp=>[1001], :udp=>[1001]}},
        :skkserv=>{:aliases=>[], :clients=>[], :description=>"skk jisho server port", :usage=>{:tcp=>[1178]}},
        :predict=>{:aliases=>[], :clients=>[], :description=>"predict -- satellite tracking", :usage=>{:udp=>[1210]}},
        :rmtcfg=>{:aliases=>[], :clients=>[], :description=>"Gracilis Packeten remote config server", :usage=>{:tcp=>[1236]}},
        :wipld=>{:aliases=>[], :clients=>[], :description=>"Wipl network monitor", :usage=>{:tcp=>[1300]}},
        :xtel=>{:aliases=>[], :clients=>[], :description=>"french minitel", :usage=>{:tcp=>[1313]}},
        :xtelw=>{:aliases=>[], :clients=>[], :description=>"french minitel", :usage=>{:tcp=>[1314]}},
        :support=>{:aliases=>[], :clients=>[], :description=>"GNATS", :usage=>{:tcp=>[1529]}},
        :cfinger=>{:aliases=>[], :clients=>[], :description=>"GNU Finger", :usage=>{:tcp=>[2003]}},
        :frox=>{:aliases=>[], :clients=>[], :description=>"frox: caching ftp proxy", :usage=>{:tcp=>[2121]}},
        :ninstall=>{:aliases=>[], :clients=>[], :description=>"ninstall service", :usage=>{:tcp=>[2150], :udp=>[2150]}},
        :zebrasrv=>{:aliases=>[], :clients=>[], :description=>"zebra service", :usage=>{:tcp=>[2600]}},
        :zebra=>{:aliases=>[], :clients=>[], :description=>"zebra vty", :usage=>{:tcp=>[2601]}},
        :ripd=>{:aliases=>[], :clients=>[], :description=>"ripd vty (zebra)", :usage=>{:tcp=>[2602]}},
        :ripngd=>{:aliases=>[], :clients=>[], :description=>"ripngd vty (zebra)", :usage=>{:tcp=>[2603]}},
        :ospfd=>{:aliases=>[], :clients=>[], :description=>"ospfd vty (zebra)", :usage=>{:tcp=>[2604]}},
        :bgpd=>{:aliases=>[], :clients=>[], :description=>"bgpd vty (zebra)", :usage=>{:tcp=>[2605]}},
        :ospf6d=>{:aliases=>[], :clients=>[], :description=>"ospf6d vty (zebra)", :usage=>{:tcp=>[2606]}},
        :ospfapi=>{:aliases=>[], :clients=>[], :description=>"OSPF-API", :usage=>{:tcp=>[2607]}},
        :isisd=>{:aliases=>[], :clients=>[], :description=>"ISISd vty (zebra)", :usage=>{:tcp=>[2608]}},
        :afbackup=>{:aliases=>[], :clients=>[], :description=>"Afbackup system", :usage=>{:tcp=>[2988], :udp=>[2988]}},
        :afmbackup=>{:aliases=>[], :clients=>[], :description=>"Afmbackup system", :usage=>{:tcp=>[2989], :udp=>[2989]}},
        :xtell=>{:aliases=>[], :clients=>[], :description=>"xtell server", :usage=>{:tcp=>[4224]}},
        :fax=>{:aliases=>[], :clients=>[], :description=>"FAX transmission service (old)", :usage=>{:tcp=>[4557]}},
        :hylafax=>{:aliases=>[], :clients=>[], :description=>"HylaFAX client-server protocol (new)", :usage=>{:tcp=>[4559]}},
        :distmp3=>{:aliases=>[], :clients=>[], :description=>"distmp3host daemon", :usage=>{:tcp=>[4600]}},
        :munin=>{:aliases=>["lrrd"], :clients=>[], :description=>"Munin", :usage=>{:tcp=>[4949]}},
        :"enbd-cstatd"=>{:aliases=>[], :clients=>[], :description=>"ENBD client statd", :usage=>{:tcp=>[5051]}},
        :"enbd-sstatd"=>{:aliases=>[], :clients=>[], :description=>"ENBD server statd", :usage=>{:tcp=>[5052]}},
        :pcrd=>{:aliases=>[], :clients=>[], :description=>"PCR-1000 Daemon", :usage=>{:tcp=>[5151]}},
        :noclog=>{:aliases=>[], :clients=>[], :description=>"noclogd with TCP (nocol)", :usage=>{:tcp=>[5354], :udp=>[5354]}},
        :hostmon=>{:aliases=>[], :clients=>[], :description=>"hostmon uses TCP (nocol)", :usage=>{:tcp=>[5355], :udp=>[5355]}},
        :rplay=>{:aliases=>[], :clients=>[], :description=>"RPlay audio service", :usage=>{:udp=>[5555]}},
        :nrpe=>{:aliases=>[], :clients=>[], :description=>"Nagios Remote Plugin Executor", :usage=>{:tcp=>[5666]}},
        :nsca=>{:aliases=>[], :clients=>[], :description=>"Nagios Agent - NSCA", :usage=>{:tcp=>[5667]}},
        :mrtd=>{:aliases=>[], :clients=>[], :description=>"MRT Routing Daemon", :usage=>{:tcp=>[5674]}},
        :bgpsim=>{:aliases=>[], :clients=>[], :description=>"MRT Routing Simulator", :usage=>{:tcp=>[5675]}},
        :canna=>{:aliases=>[], :clients=>[], :description=>"cannaserver", :usage=>{:tcp=>[5680]}},
        :"sane-port"=>{:aliases=>[], :clients=>[], :description=>"SANE network scanner daemon", :usage=>{:tcp=>[6566]}},
        :ircd=>{:aliases=>[], :clients=>[], :description=>"Internet Relay Chat", :usage=>{:tcp=>[6667]}},
        :"zope-ftp"=>{:aliases=>[], :clients=>[], :description=>"zope management by ftp", :usage=>{:tcp=>[8021]}},
        :tproxy=>{:aliases=>[], :clients=>[], :description=>"Transparent Proxy", :usage=>{:tcp=>[8081]}},
        :omniorb=>{:aliases=>[], :clients=>[], :description=>"OmniORB", :usage=>{:tcp=>[8088], :udp=>[8088]}},
        :xinetd=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[9098]}},
        :mandelspawn=>{:aliases=>[], :clients=>[], :description=>"network mandelbrot", :usage=>{:udp=>[9359]}},
        :git=>{:aliases=>[], :clients=>[], :description=>"Git Version Control System", :usage=>{:tcp=>[9418]}},
        :zope=>{:aliases=>[], :clients=>[], :description=>"zope server", :usage=>{:tcp=>[9673]}},
        :webmin=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:tcp=>[10000]}},
        :kamanda=>{:aliases=>[], :clients=>[], :description=>"amanda backup services (Kerberos)", :usage=>{:tcp=>[10081], :udp=>[10081]}},
        :amandaidx=>{:aliases=>[], :clients=>[], :description=>"amanda backup services", :usage=>{:tcp=>[10082]}},
        :amidxtape=>{:aliases=>[], :clients=>[], :description=>"amanda backup services", :usage=>{:tcp=>[10083]}},
        :smsqp=>{:aliases=>[], :clients=>[], :description=>"Alamin SMS gateway", :usage=>{:tcp=>[11201], :udp=>[11201]}},
        :xpilot=>{:aliases=>[], :clients=>[], :description=>"XPilot Contact Port", :usage=>{:tcp=>[15345], :udp=>[15345]}},
        :"sgi-cmsd"=>{:aliases=>[], :clients=>[], :description=>"Cluster membership services daemon", :usage=>{:udp=>[17001]}},
        :"sgi-crsd"=>{:aliases=>[], :clients=>[], :description=>"", :usage=>{:udp=>[17002]}},
        :"sgi-gcd"=>{:aliases=>[], :clients=>[], :description=>"SGI Group membership daemon", :usage=>{:udp=>[17003]}},
        :"sgi-cad"=>{:aliases=>[], :clients=>[], :description=>"Cluster Admin daemon", :usage=>{:tcp=>[17004]}},
        :isdnlog=>{:aliases=>[], :clients=>[], :description=>"isdn logging system", :usage=>{:tcp=>[20011], :udp=>[20011]}},
        :vboxd=>{:aliases=>[], :clients=>[], :description=>"voice box system", :usage=>{:tcp=>[20012], :udp=>[20012]}},
        :binkp=>{:aliases=>[], :clients=>[], :description=>"binkp fidonet protocol", :usage=>{:tcp=>[24554]}},
        :asp=>{:aliases=>[], :clients=>[], :description=>"Address Search Protocol", :usage=>{:tcp=>[27374], :udp=>[27374]}},
        :csync2=>{:aliases=>[], :clients=>[], :description=>"cluster synchronization tool", :usage=>{:tcp=>[30865]}},
        :dircproxy=>{:aliases=>[], :clients=>[], :description=>"Detachable IRC Proxy", :usage=>{:tcp=>[57000]}},
        :tfido=>{:aliases=>[], :clients=>[], :description=>"fidonet EMSI over telnet", :usage=>{:tcp=>[60177]}},
        :fido=>{:aliases=>[], :clients=>[], :description=>"fidonet EMSI over TCP", :usage=>{:tcp=>[60179]}}
      }
      #
      #
      # ### end of SYSTEM detail initialization
    end

### Public Instance Methods

[](the_path="") click to toggle source

    # File lib/gxg/gxg_entities.rb, line 973
    def [](the_path="")
      # Public interface for accessing system keyed values.
      # access cached or system-read values on /proc (sysctl-style) keys. (frankly missing from BSD, etc)
      result = nil
      reference = detail_mapping()
      #
      reference.to_enum.each do |mapping|
        if mapping[:key] == the_path
          @thread_safety.synchronize {
            result = @details.get_at_path(mapping[:path]).clone
          }
          break
        end
      end
      unless result
        # attempt to fetch the data from the system somehow.
        result = get_system_data(the_path)
        unless result.keys.size > 0
          result = nil
        end
      end
      #
      result
    end

architecture() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 998
    def architecture()
      @thread_safety.synchronize {
        {:architecture => @details[:architecture], :processors => @details[:processors]}.clone
      }
    end

cpuload() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1042
    def cpuload
      # this or load_average ??
      average = Sys::CPU.load_avg
      { :minute1 => average[0], :minute5 => average[1], :minute15 => average[2] }
    end

current_user() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1324
    def current_user()
      Sys::Admin.get_user(Sys::Admin.get_login)
    end

engine() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1016
    def engine()
      # ??? just info ??? GxG::Engine::profile()
      ::GxG::Engine
    end

environment() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1010
    def environment()
      @thread_safety.synchronize {
        {:environment => @details[:environment], :version => @details[:environment_version], :variant => @details[:environment_variant]}.clone
      }
    end

import_services_file() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1963
    def import_services_file()
      #
      current_system_list = self.services_file()
      if current_system_list.size >0
        current_system_list.to_enum(:each).each do |the_entry|
          self.service_ports_register(the_entry.keys()[0],the_entry[(the_entry.keys()[0])])
        end
        true
      else
        false
      end
      #
    end

load_average() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1027
    def load_average()
      # this or cpuload ??
      this_platform = @details[:platform]
      case this_platform
      when :linux
        result = (`uptime`.split(":")[-1].chomp.split(","))
        result.to_enum(:each_index).each do |indexer|
          result[(indexer)] = result[(indexer)].to_f
        end
      else
        result = []
      end
      result
    end

maximum_buffer_size() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1065
    def maximum_buffer_size()
      self.memory_limits()[:buffers]
    end

memory() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1069
    def memory()
      result = {}
      this_platform = nil
      @thread_safety.synchronize { this_platform = @details[:platform] }
      case this_platform
        # TODO: GxG::SYSTEM.memory : research free mem discovery for Winderz and BSD
      when :windows
        # No known way to get this info. MEM is dosbox only style memory counting. :P
        # Might have to bind to a C or C++ lib for this kind of data (PITA)
        # FORNOW: just pretend upper theoretical limit on a process is all you have (sucks)
        mem_limit = ::GxG::SYSTEM.memory_limits()[:process].max
        result[:actual] = {:total => mem_limit, :used => 0, :free => mem_limit, :shared => 0, :buffers => 0, :cached => 0}
        result[:buffers] = {:used => 0, :free => 0}
        result[:virtual] = {:total => 0, :used => 0, :free => 0}
      when :bsd, :darwin, :macos
        # Inspired by: http://www.cyberciti.biz/faq/freebsd-command-to-get-ram-information/ by Ralf S. Engelschall
        # ported to Ruby:
        env = self.environment()
        case env[:environment]
        when :freebsd, :dragonfly, :pcbsd
          # TODO: GxG::SYSTEM.memory() : test under freebsd, dragonfly and pcbsd
          page_size = (`sysctl hw.pagesize`.to_s.split(":")[1].numeric_values()[:integer] || 0)
          mem_phys = (`sysctl hw.physmem`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_all = (`sysctl vm.stats.vm.v_page_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_wire = (`sysctl vm.stats.vm.v_wire_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_active = (`sysctl vm.stats.vm.v_active_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_inactive = (`sysctl vm.stats.vm.v_inactive_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_cache = (`sysctl vm.stats.vm.v_cache_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_free = (`sysctl vm.stats.vm.v_free_count`.to_s.split(":")[1].numeric_values()[:integer] || 0) * page_size
          mem_vm_total = (`sysctl vm.swap_total`.to_s.split(":")[1].numeric_values()[:integer] || 0)
          mem_vm_used = (`pstat -s`.to_s.split(" ")[2].numeric_values()[:integer] || 0)
        when :netbsd
          # TODO: GxG::SYSTEM.memory() : test under netbsd
          page_size = 0
          mem_phys = 0
          mem_all = 0
          mem_wire = 0
          mem_active = 0
          mem_inactive = 0
          mem_cache = 0
          mem_free = 0
          mem_vm_total = 0
          mem_vm_used = 0
          #
          raw_data = `vmstat -s`
          raw_data.to_enum(:each_line).each do |the_line|
            if the_line.include?("bytes per page")
              page_size = (the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0)
              break
            end
          end
          if page_size > 0
            raw_data.to_enum(:each_line).each do |the_line|
              if the_line.include?("pages managed")
                mem_phys = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
                mem_all = mem_phys
              end
              if the_line.include?("pages wired")
                mem_wire = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
              if the_line.include?("pages active")
                mem_active = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
              if the_line.include?("pages inactive")
                mem_inactive = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
              if the_line.include?("pages free")
                mem_free = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
              if the_line.include?("swap pages in use")
                mem_vm_used = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
              if the_line.split(" ")[(1..-1)].join(" ") == "swap pages"
                mem_vm_total = ((the_line.split(" ")[0].to_s.numeric_values()[:integer] || 0) * page_size)
              end
            end
          end
        when :darwin, :macos
          # TODO: GxG::SYSTEM.memory() : test under darwin
          raw_data = `top -l 1`
          page_size = (`sysctl hw.pagesize`.to_s.split(":")[1].numeric_values()[:integer] || 0)
          # gives a byte-count, not a page count : hw.physmem
          mem_phys = (`sysctl hw.physmem`.to_s.split(":")[1].numeric_values()[:integer] || 0)
          mem_all = mem_phys
          # virtual memory usage:
          raw_data = (`sysctl vm.swapusage`.to_s.split(":")[1].split(" "))
          mem_vm_total = ((raw_data[5].to_s.numeric_values()[:float] || 0.0) * (1024**2)).to_i
          mem_vm_used = ((raw_data[2].to_s.numeric_values()[:float] || 0.0) * (1024**2)).to_i
          #SharedLibs: num =  146, resident = 22.9M code, 3.40M data, 8.36M LinkEdit
          #MemRegions: num =  7213, resident =  344M + 4.92M private, 22.5M shared
          #PhysMem:  59.1M wired,  285M active,  138M inactive,  483M used, 28.3M free
          raw_data.to_enum(:each_line).each do |the_line|
            if the_line.include?("PhysMem:")
              data = the_line.split(":")[1].to_s.split(",")
              data.to_enum(:each).each do |the_param|
                numeric_string = the_param.split(" ")[0]
                if numeric_string.include?(".")
                  numeric_string.gsub!("M","")
                else
                  numeric_string.gsub!("M",".0")
                end
                case the_param.split(" ")[1]
                when /wired/
                  mem_wire = ((numeric_string.numeric_values()[:float] || 0.0) * (1024**2)).to_i
                when /active/
                  mem_active = ((numeric_string.numeric_values()[:float] || 0.0) * (1024**2)).to_i
                when /inactive/
                  mem_inactive = ((numeric_string.numeric_values()[:float] || 0.0) * (1024**2)).to_i
                when /free/
                  mem_free = ((numeric_string.numeric_values()[:float] || 0.0) * (1024**2)).to_i
                end
              end
              break
            end
          end
        else
          # default BSD behavior ???  Seems like everyone does their own special thing.
        end
        #
        chip_size = 1
        chip_guess = ((mem_phys / 8) - 1)
        while (chip_guess != 0)
          chip_guess >>= 1
          chip_size <<= 1
        end
        mem_hw = (((mem_phys / chip_size).to_i + 1) * chip_size)
        #
        mem_gap_vm = (mem_all - (mem_wire + mem_active + mem_inactive + mem_cache + mem_free))
        mem_gap_sys = (mem_phys - mem_all)
        mem_gap_hw = (mem_hw - mem_phys)
        #
        mem_available = (mem_inactive + mem_cache + mem_free)
        mem_used = (mem_hw - mem_available)
        # format result:
        result[:actual] = {:total => mem_hw, :used => mem_used, :free => mem_available, :shared => 0, :buffers => 0, :cached => 0}
        result[:buffers] = {:used => 0, :free => 0}
        result[:virtual] = {:total => mem_vm_total, :used => mem_vm_used, :free => (mem_vm_total - mem_vm_used)}
        #
      when :linux, :solaris
        # total       used       free     shared    buffers     cached
        raw_text = `free -b`
        raw_text.to_enum(:each_line).each do |text_line|
          if text_line.include?("Mem:")
            stats = text_line.split(" ")
            result[:actual] = {:total => stats[1].to_i, :used => stats[2].to_i, :free => stats[3].to_i, :shared => stats[4].to_i, :buffers => stats[5].to_i, :cached => stats[6].to_i}
          end
          if text_line.include?("-/+ buffers/cache:")
            stats = text_line.split(" ")
            result[:buffers] = {:used => stats[2].to_i, :free => stats[3].to_i}
          end
          if text_line.include?("Swap:")
            stats = text_line.split(" ")
            result[:virtual] = {:total => stats[1].to_i, :used => stats[2].to_i, :free => stats[3].to_i}
          end
        end
      end
      result.process! do |entry,selector,container|
        if entry.is_a?(::String)
          item = entry.numeric_values()
          if item.is_a?(::Hash)
            if item[:integer]
              container[(selector)] = item[:integer].to_i
            end
            if item[:float]
              container[(selector)] = item[:float].to_f
            end
          end
          if item.is_a?(::Array)
            item.each do |the_data|
              if the_data.is_a?(::Hash)
                if the_data[:integer]
                  container[(selector)] = the_data[:integer].to_i
                end
                if the_data[:float]
                  container[(selector)] = the_data[:float].to_f
                end
              end
              if the_data.is_a?(::Array)
                data = the_data[0]
                if data.is_a?(::Hash)
                  if data[:integer]
                    container[(selector)] = data[:integer].to_i
                  end
                  if data[:float]
                    container[(selector)] = data[:float].to_f
                  end
                  break
                end
              end
            end
          end
        end
        nil
      end
      result[:total] = {:total => (result[:actual][:total].to_i + result[:virtual][:total].to_i), :used => (result[:actual][:used].to_i + result[:virtual][:used].to_i), :free => (result[:actual][:free].to_i + result[:virtual][:free].to_i)}
      result
    end

memory_limits() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1056
    def memory_limits()
      # See: http://linux-mm.org/LinuxMM
      # http://linux.die.net/man/2/mlock
      # https://answers.launchpad.net/graphite/+question/191807
      #
      @thread_safety.synchronize {
        @details[:memory_limits].clone
      }
    end

network() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1021
    def network()
      @thread_safety.synchronize {
        @details[:network].clone
      }
    end

network_next_port(the_address="0.0.0.0", honor_conventions=true) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1591
    def network_next_port(the_address="0.0.0.0", honor_conventions=true)
      # finds next available port on given interface, by default respecting common port usage conventions.
      if the_address.is_a?(::Addrinfo)
        the_address = the_address.ip_address()
      end
      if the_address == "*" || the_address == nil
        the_address = "0.0.0.0"
      end
      unless the_address.is_a?(::String)
        raise ArgumentError, "address needs to be specified as a String, you provided #{the_address.class}"
      end
      #
      if honor_conventions
        commonly_available = (49152..65535)
      else
        commonly_available = (1..65535)
      end
      #
      found = nil
      currently_used_ports = []
      current = self.network_status()
      current[:internet].to_enum(:each).each do |entry|
        if entry[:local_address].ip_address() == the_address
          currently_used_ports << entry[:local_address].ip_port()
        end
        if entry[:foreign_address].ip_address() == the_address
          currently_used_ports << entry[:foreign_address].ip_port()
        end
      end
      #
      commonly_available.to_enum(:each).each do |the_port|
        unless currently_used_ports.include?(the_port)
          found = the_port
          break
        end
      end
      #
      found
    end

network_port_used?(the_port=0, the_address="0.0.0.0") click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1546
    def network_port_used?(the_port=0, the_address="0.0.0.0")
      if the_port.is_a?(::Addrinfo)
        the_address = the_port.ip_address()
        the_port = the_port.ip_port()
      end
      if the_address == "*" || the_address == nil
        the_address = "0.0.0.0"
      end
      unless the_address.is_a?(::String)
        raise ArgumentError, "address needs to be specified as a String, you provided #{the_address.class}"
      end
      if the_port == "*" || the_port == nil
        the_port = 0
      else
        if the_port.is_any?(::String, ::Numeric)
          the_port = the_port.to_i
        else
          raise ArgumentError, "port needs to be specified by an Integer or a String of an Integer or asterisk character, you provided #{the_port.class}"
        end
      end
      current = {:internet => [], :local => []}
      if the_port == 0
        found = true
      else
        found = false
        current = self.network_status()
      end
      #
      unless found
        current[:internet].to_enum(:each).each do |entry|
          if ((entry[:local_address].ip_address() == the_address && entry[:local_address].ip_port() == the_port) || (entry[:foreign_address].ip_address() == the_address && entry[:foreign_address].ip_port() == the_port))
            found = true
            break
          end
        end
      end
      unless found
        current[:local].to_enum(:each).each do |entry|
          # pending further Research and hefty work-arounds within self.network_status().
        end
      end
      #
      found
    end

network_status() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1328
    def network_status()
      # LATER: find out how to get the PID for AF_UNIX output of bsd-netstat -f unix
      # goal: lsof given a path, find the PID associated
      # lsof -Rt -t path (have to have read permissions)
      # OK, I give up (F-U bsd guys for not having a PID field in netstat unix output :P )
      # no unix socket info until I can figure a hooley-hoop set to jump through on this -- F'n Dorks!
      data = []
      local_data = []
      case ::GxG::SYSTEM.platform()[:platform]
      when :bsd
        predata = []
        raw_data = `netstat -an`
        raw_data.to_enum(:each_line).each do |the_line|
          ["tcp4 ", "tcp6 ", "udp4 ", "udp6 "].to_enum(:each).each do |entry|
            if the_line.include?(entry)
              predata << the_line.split(" ")
              break
            end
          end
          #
        end
        predata.to_enum(:each).each do |the_entry|
          new_entry = {}
          addressing = nil
          case the_entry[0].downcase
          when "tcp4", "tcp"
            addressing = {:family => ::Socket::AF_INET, :protocol => :tcp}
          when "tcp6"
            addressing = {:family => ::Socket::AF_INET6, :protocol => :tcp6}
          when "udp4", "udp"
            addressing = {:family => ::Socket::AF_INET, :protocol => :udp}
          when "udp6"
            addressing = {:family => ::Socket::AF_INET6, :protocol => :udp6}
          end
          if addressing
            new_entry[:protocol] = addressing[:protocol]
            if addressing[:family] == ::Socket::AF_INET6
              chunks = the_entry[3].split(".")
              unless chunks[1] == "*"
                chunks[1] = chunks[1].to_i
              end
            else
              if the_entry[3].include?("*")
                chunks = the_entry[3].split(".")
                if chunks[0] == "*"
                  chunks = ["0.0.0.0",(the_entry[3].split(".").last)]
                else
                  chunks = [(the_entry[3].split(".")[0..3].join(".")),(the_entry[3].split(".")[4])]
                end
                unless chunks[1] == "*"
                  chunks[1] = chunks[1].to_i
                end
              else
                chunks = [(the_entry[3].split(".")[0..3].join(".")),(the_entry[3].split(".")[4].to_i)]
              end
            end
            # bug fix:
            if chunks[1] == "*"
              chunks[1] = 0
            end
            # ##
            if addressing[:protocol] == :udp || addressing[:protocol] == :udp6
              new_entry[:local_address] = Addrinfo.udp(chunks[0],chunks[1])
            else
              new_entry[:local_address] = Addrinfo.tcp(chunks[0],chunks[1])
            end
            #
            if addressing[:family] == ::Socket::AF_INET6
              chunks = the_entry[4].split(".")
              unless chunks[1] == "*"
                chunks[1] = chunks[1].to_i
              end
            else
              if the_entry[4].include?("*")
                chunks = the_entry[4].split(".")
                if chunks[0] == "*"
                  chunks = ["0.0.0.0",(the_entry[4].split(".").last)]
                else
                  chunks = [(the_entry[4].split(".")[0..3].join(".")),(the_entry[4].split(".")[4])]
                end
                unless chunks[1] == "*"
                  chunks[1] = chunks[1].to_i
                end
              else
                chunks = [(the_entry[4].split(".")[0..3].join(".")),(the_entry[4].split(".")[4].to_i)]
              end
            end
            # bug fix:
            if chunks[1] == "*"
              chunks[1] = 0
            end
            # ##
            if addressing[:protocol] == :udp || addressing[:protocol] == :udp6
              new_entry[:foreign_address] = Addrinfo.udp(chunks[0],chunks[1])
            else
              new_entry[:foreign_address] = Addrinfo.tcp(chunks[0],chunks[1])
            end
            #
            if the_entry[5].to_s.size > 0
              new_entry[:status] = the_entry[5].to_sym
            else
              new_entry[:status] = nil
            end
            #
            data << new_entry
          end
          #
        end
      when :linux
        predata = []
        raw_data = `netstat -an`
        raw_data.to_enum(:each_line).each do |the_line|
          ["tcp ", "tcp6 ", "udp ", "udp6 "].to_enum(:each).each do |entry|
            if the_line.include?(entry)
              predata << the_line.split(" ")
              break
            end
          end
          #
        end
        predata.to_enum(:each).each do |the_entry|
          the_error = nil
          new_entry = {}
          addressing = nil
          case the_entry[0].downcase
          when "tcp"
            addressing = {:family => ::Socket::AF_INET, :protocol => :tcp}
          when "tcp6"
            addressing = {:family => ::Socket::AF_INET6, :protocol => :tcp6}
          when "udp"
            addressing = {:family => ::Socket::AF_INET, :protocol => :udp}
          when "udp6"
            addressing = {:family => ::Socket::AF_INET6, :protocol => :udp6}
          end
          if addressing
            new_entry[:protocol] = addressing[:protocol]
            if addressing[:family] == ::Socket::AF_INET6
              chunks = the_entry[3].split(":")
              unless chunks[-1] == "*"
                chunks[-1] = chunks[-1].to_i
              end
              chunks = [(chunks[0..-2]).join(":"),(chunks.last)]
            else
              # Odd bug work-around
              addr = the_entry[3].split(":")[0]
              port = the_entry[3].split(":")[1]
              unless port == "*"
                port = port.to_i
              end
              chunks = [(addr.split(":")[0]),(port)]
            end
            # bug fix:
            if chunks[1] == "*"
              chunks[1] = 0
            end
            #
            begin
              if addressing[:protocol] == :udp || addressing[:protocol] == :udp6
                new_entry[:local_address] = Addrinfo.udp(chunks[0],chunks[1])
              else
                new_entry[:local_address] = Addrinfo.tcp(chunks[0],chunks[1])
              end
            rescue Exception => the_error
            end
            # ##
            if addressing[:family] == ::Socket::AF_INET6
              # IPV6
              chunks = the_entry[4].split(":")
              unless chunks[-1] == "*"
                chunks[-1] = chunks[-1].to_i
              end
              chunks = [(chunks[0..-2]).join(":"),(chunks.last)]
            else
              # IPV4
              # Odd bug work-around
              addr = the_entry[4].split(":")[0]
              port = the_entry[4].split(":")[1]
              unless port == "*"
                port = port.to_i
              end
              chunks = [(addr.split(":")[0]),(port)]
              # puts "Got: #{chunks.inspect}"
            end
            #              if chunks[1].is_a?(::String)
            #                if chunks[1].numeric_values(:integer)
            #                  chunks[1] = chunks[1].numeric_values(:integer)[:integer]
            #                end
            #              end
            # bug fix:
            if chunks[1] == "*"
              chunks[1] = 0
            end
            #
            begin
              if addressing[:protocol] == :udp || addressing[:protocol] == :udp6
                new_entry[:foreign_address] = Addrinfo.udp(chunks[0],chunks[1])
              else
                new_entry[:foreign_address] = Addrinfo.tcp(chunks[0],chunks[1])
              end
            rescue Exception => the_error
            end
            # ##
            if the_entry[5].to_s.size > 0
              new_entry[:status] = the_entry[5].to_sym
            else
              new_entry[:status] = nil
            end
            #
            unless the_error
              data << new_entry
            end
            #
          end
        end
      end
      {:internet => data, :local => local_data}
    end

platform() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1004
    def platform()
      @thread_safety.synchronize {
        {:platform => @details[:platform], :version => @details[:platform_version], :configuration => @details[:platform_configuration]}.clone
      }
    end

processes(params={}) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1267
    def processes(params={})
      results = []
      columns = [:cmdline, :cwd, :environ, :exe, :fd, :root, :pid, :comm, :state, :ppid, :pgrp, :session, :tty_nr, :tpgid,
        :flags, :minflt, :cminflt, :majflt, :cmajflt, :utime, :stime, :cutime, :cstime, :priority, :nice, :itrealvalue, :starttime,
        :vsize, :rss, :rlim, :startcode, :endcode, :startstack, :kstkesp, :kstkeip, :signal, :blocked, :sigignore, :sigcatch, :wchan,
        :nswap, :cnswap, :exit_signal, :processor, :rt_priority, :policy, :name, :uid, :euid, :gid, :egid, :pctcpu, :pctmem]
      include_columns = []
      if params[:columns].respond_to?(:each)
        params[:columns].to_enum.each do |entry|
          if columns.include?(entry.to_s.to_sym)
            include_columns << entry.to_s.to_sym
          end
        end
      else
        include_columns = columns
      end
      params.delete(:columns)
      #
      search_for = {}
      if params.respond_to?(:each_pair)
        params.each_pair do |key,entry|
          if columns.include?(key.to_s.to_sym)
            search_for[(key.to_s.to_sym)] = entry
          end
        end
      end
      #
      if (params[:pid])
        raw_data = (Sys::ProcTable.ps(params[:pid]) || [])
      else
        raw_data = (Sys::ProcTable.ps() || [])
      end
      raw_data.to_enum.each do |entry|
        new_entry = {}
        process = true
        if search_for.keys.size > 0
          search_for.each_pair do |search_key,search_value|
            unless (entry[(search_key)] == search_value)
              process = false
            end
          end
        end
        if process
          entry.each_pair do |key,item|
            if include_columns.include?(key.to_s.to_sym)
              new_entry[(key.to_sym)] = item
            end
          end
        end
        if new_entry.keys.size > 0
          results << new_entry
        end
      end
      #
      results
    end

service_ports() click to toggle source

Services general port usage reference data

    # File lib/gxg/gxg_entities.rb, line 1631
    def service_ports()
      @details[:service_ports]
    end

service_ports_register(service, entry={}) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1752
    def service_ports_register(service, entry={})
      unless service.to_s.size > 0
        raise ArgumentError, "you must specify a service symbol (i.e. :www ...), you provided #{service.inspect}"
      end
      unless service.is_a?(::Symbol)
        service = service.to_s.to_sym
      end
      unless entry.is_a?(::Hash)
        entry = {}
      end
      unless entry[:aliases].is_a?(::Array)
        entry[:aliases] = []
      end
      unless entry[:clients].is_a?(::Array)
        entry[:clients] = []
      end
      unless entry[:description].is_a?(::String)
        entry[:description] = ""
      end
      unless entry[:usage].is_a?(::Hash)
        entry[:usage] = {}
      end
      result = false
      #
      if @details[:service_ports][(service)]
        entry[:aliases].to_enum(:each).each do |the_alias|
          unless @details[:service_ports][(service)][:aliases].include?(the_alias)
            @details[:service_ports][(service)][:aliases] << the_alias.to_s
          end
        end
        entry[:clients].to_enum(:each).each do |the_client|
          unless @details[:service_ports][(service)][:clients].include?(the_client.to_s)
            @details[:service_ports][(service)][:clients] << the_client.to_s
          end
        end
        entry[:usage].keys.to_enum(:each).each do |the_protocol|
          if @details[:service_ports][(service)][:usage].keys.include?(the_protocol)
            entry[:usage][(the_protocol)].to_enum(:each).each do |the_entry_port|
              included = false
              @details[:service_ports][(service)][:usage][(the_protocol)].each do |the_result_port|
                if the_entry_port.is_a?(::Range)
                  if the_result_port.is_a?(::Range)
                    if (the_result_port.include?(the_entry_port.first) && the_result_port.include?(the_entry_port.last))
                      included = true
                      break
                    end
                  else
                    if the_entry_port.include?(the_result_port)
                      included = true
                      break
                    end
                  end
                else
                  if the_result_port.is_a?(::Range)
                    if the_result_port.include?(the_entry_port)
                      included = true
                      break
                    end
                  else
                    if the_result_port == the_entry_port
                      included = true
                      break
                    end
                  end
                end
              end
              unless included
                @details[:service_ports][(service)][:usage][(the_protocol)] << the_entry_port
              end
            end
          else
            @details[:service_ports][(service)][:usage][(the_protocol)] = entry[:usage][(the_protocol)]
          end
          #
        end
        #
      else
        @details[:service_ports][(service.to_sym)] = entry
        result = true
      end
      #
      result
    end

service_ports_register_alias(service,alias_name) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1635
    def service_ports_register_alias(service,alias_name)
      result = false
      if @details[:service_ports][(service.to_sym)]
        if alias_name.to_s.size > 0
          unless @details[:service_ports][(service.to_sym)][:aliases].include?(alias_name.to_s)
            @details[:service_ports][(service.to_sym)][:aliases] << alias_name.to_s
            result = true
          end
        end
      end
      result
    end

service_ports_register_client(service,client_scheme) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1662
    def service_ports_register_client(service,client_scheme)
      result = false
      if @details[:service_ports][(service.to_sym)]
        if client_scheme.to_s.size > 0
          unless @details[:service_ports][(service.to_sym)][:clients].include?(client_scheme)
            @details[:service_ports][(service.to_sym)][:clients] << client_scheme.to_s
            result = true
          end
        end
      end
      result
    end

service_ports_register_usage(service,the_protocol,the_entry_port) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1707
    def service_ports_register_usage(service,the_protocol,the_entry_port)
      # the_entry_port can be an Integer or a Range
      result = false
      if @details[:service_ports][(service.to_sym)]
        if @details[:service_ports][(service)][:usage].keys.include?(the_protocol)
          included = false
          @details[:service_ports][(service)][:usage][(the_protocol)].to_enum(:each).each do |the_result_port|
            if the_entry_port.is_a?(::Range)
              if the_result_port.is_a?(::Range)
                if (the_result_port.include?(the_entry_port.first) && the_result_port.include?(the_entry_port.last))
                  included = true
                  break
                end
              else
                if the_entry_port.include?(the_result_port)
                  included = true
                  break
                end
              end
            else
              if the_result_port.is_a?(::Range)
                if the_result_port.include?(the_entry_port)
                  included = true
                  break
                end
              else
                if the_result_port == the_entry_port
                  included = true
                  break
                end
              end
            end
          end
          unless included
            @details[:service_ports][(service)][:usage][(the_protocol)] << the_entry_port
          end
        else
          @details[:service_ports][(service)][:usage][(the_protocol)] = the_entry_port
        end
        result = true
        #
      end
      result
    end

service_ports_remove_alias(service,alias_name) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1648
    def service_ports_remove_alias(service,alias_name)
      result = false
      if @details[:service_ports][(service.to_sym)]
        if @details[:service_ports][(service.to_sym)][:aliases].include?(alias_name.to_s)
          position = @details[:service_ports][(service.to_sym)][:aliases].index(alias_name.to_s)
          if position
            @details[:service_ports][(service.to_sym)][:aliases].delete_at(position)
            result = true
          end
        end
      end
      result
    end

service_ports_remove_client(service,client_scheme) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1675
    def service_ports_remove_client(service,client_scheme)
      result = false
      if @details[:service_ports][(service.to_sym)]
        if @details[:service_ports][(service.to_sym)][:clients].include?(client_scheme.to_s)
          position = @details[:service_ports][(service.to_sym)][:clients].index(client_scheme.to_s)
          if position
            @details[:service_ports][(service.to_sym)][:clients].delete_at(position)
            result = true
          end
        end
      end
      result
    end

service_ports_search(criteria={}) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1836
    def service_ports_search(criteria={})
      # search by client-scheme, and/or protocol and port-number/range.
      result = {}
      #
      @details[:service_ports].keys.to_enum(:each).each do |service|
        if (criteria[:scheme].to_s.to_sym == service || (@details[:service_ports][(service)][:aliases].include?(criteria[:scheme].to_s)) || (@details[:service_ports][(service)][:clients].include?(criteria[:scheme].to_s)))
          result[(service)] = @details[:service_ports][(service)].clone
        end
        unless result[(service)]
          the_protocol = criteria[:protocol]
          the_entry_port = criteria[:port]
          if (the_entry_port.is_any?(::Numeric, ::Range) && [:tcp, :udp, :icmp, :snmp].include?(the_protocol))
            if @details[:service_ports][(service)][:usage][(the_protocol)].is_a?(::Array)
              included = false
              @details[:service_ports][(service)][:usage][(the_protocol)].to_enum(:each).each do |the_result_port|
                if the_entry_port.is_a?(::Range)
                  if the_result_port.is_a?(::Range)
                    if (the_result_port.include?(the_entry_port.first) && the_result_port.include?(the_entry_port.last))
                      included = true
                      break
                    end
                  else
                    if the_entry_port.include?(the_result_port)
                      included = true
                      break
                    end
                  end
                else
                  if the_result_port.is_a?(::Range)
                    if the_result_port.include?(the_entry_port)
                      included = true
                      break
                    end
                  else
                    if the_result_port == the_entry_port
                      included = true
                      break
                    end
                  end
                end
              end
              if included
                result[(service)] = @details[:service_ports][(service)].clone
              end
              #
            end
          end
        end
      end
      #
      result
    end

service_ports_usage_preference(service,preference=nil) click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1689
    def service_ports_usage_preference(service,preference=nil)
      result = false
      if @details[:service_ports][(service.to_sym)]
        if preference
          if [:tcp, :udp, :icmp, :snmp].include?(preference)
            if @details[:service_ports][(service.to_sym)][:usage][(preference)]
              @details[:service_ports][(service.to_sym)][:usage_preference] = preference
              result = true
            end
          end
        else
          @details[:service_ports][(service.to_sym)].delete(:usage_preference)
          result = true
        end
      end
      result
    end

services_file() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1888
    def services_file()
      # "www" => {:aliases => ["http"], :clients => ["web"], :description => "", :usage => {:tcp => [(0..23),80], :udp => [80]}}
      #
      result = []
      raw_data = []
      case ::GxG::SYSTEM.platform()[:platform]
      when :windows
        # not possible like on linux/bsd ??
      when :linux, :bsd
        the_file = "/etc/services"
        begin
          file_handle = GxG::IO::File.new(the_file, ::IO::RDONLY)
          raw_data = file_handle.readlines()
          file_handle.close
        rescue Exception
          # give up on this
        end
        if raw_data.size > 0
          #
          raw_data.to_enum(:each).each do |the_line|
            if the_line.split("#")[0]
              service = ""
              entry = {:aliases => [], :clients => [], :description => "", :usage => {}}
              #
              raw_entry = the_line.split("#")[0].split("\t")
              if raw_entry[0].to_s.size > 0
                service = raw_entry[0].to_sym
              else
                service = :unknown
              end
              if raw_entry[1].to_s.split("/").size == 2
                if raw_entry[1].split("/")[0].to_s.size > 0
                  entry[:usage][(raw_entry[1].split("/")[1].gsub("\n","").to_sym)] = [ raw_entry[1].split("/")[0].to_i ]
                end
              else
                if raw_entry[2].to_s.split("/").size == 2
                  entry[:usage][(raw_entry[2].split("/")[1].gsub("\n","").to_sym)] = [ raw_entry[2].split("/")[0].to_i ]
                end
              end
              if raw_entry[3].to_s.size > 0
                raw_entry[3].split(" ").to_enum(:each).each do |the_alias|
                  entry[:aliases] << the_alias
                end
              end
              if (raw_entry.size - 1) > 3
                (4..(raw_entry.size - 1)).each do |the_index|
                  if raw_entry[(the_index)].to_s.size > 0
                    raw_entry[(the_index)].split(" ").to_enum(:each).each do |the_alias|
                      if the_alias.size > 0
                        unless entry[:aliases].include?(the_alias)
                          entry[:aliases] << the_alias
                        end
                      end
                    end
                  end
                end
              end
              if the_line.split("#")[1]
                entry[:description] = the_line.split("#")[1].split(" ").join(" ")
              end
              #
              if entry[:usage].keys.size > 0
                new_entry = {}
                new_entry[(service.to_sym)] = entry
                result << new_entry
              end
              #
            end
          end
        end
        #
      end
      result
    end

valid_modes() click to toggle source

    # File lib/gxg/gxg_entities.rb, line 1048
    def valid_modes()
      result = {}
      result.merge(GxG::IO::IO::valid_modes())
      @thread_safety.synchronize {
        result.merge(@valid_modes)
      }
      result
    end