Project

net-proto

0.0
No release in over 3 years
The net-proto library provides an interface for get protocol information by name or by number. It can also iterate over the list of protocol entries defined on your system.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.9

Runtime

~> 1.0
 Project Readme

Ruby

Description

The net-proto package provides a way to get protocol information.

This is a wrapper for the getprotobyname, getprotobynumber and the getprotoent C functions.

Installation

gem install net-proto

Adding the trusted cert

gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/net-proto/main/certs/djberg96_pub.pem)

Prerequisites

  • ffi 1.0.0 or later.

Synopsis

require 'net/proto' # or 'net-proto'

# Using generic method
Net::Proto.get_protocol(1)      # => 'icmp'
Net::Proto.get_protocol('icmp') # => 1

# Using type specific methods
Net::Proto.getprotobynumber(6)   # => 'tcp'
Net::Proto.getprotobyname('tcp') # => 6

# Iterating over all protocols
Net::Proto.getprotoent do |ent|
  p ent
end

Why should I use this?

Ruby has a predefined set of constants in socket.c in the general form of IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable because it's easy to define your own protocols (I set 'echo' to 7, for example), or to modify/delete entries in /etc/protocols.

Further Documentation

See the 'netproto.rdoc' file under the 'doc' directory for more details. There is also an example under the 'examples' directory.