module Miniss

Overview

Displays a list of open listening sockets. It is a minimal alternative to ss or netstat.

Defined in:

miniss.cr
miniss/addr.cr
miniss/constants.cr

Constant Summary

TCP_STATES = {"00" => "UNKNOWN", "FF" => "UNKNOWN", "01" => "ESTABLISHED", "02" => "SYN_SENT", "03" => "SYN_RECV", "04" => "FIN_WAIT1", "05" => "FIN_WAIT2", "06" => "TIME_WAIT", "07" => "CLOSE", "08" => "CLOSE_WAIT", "09" => "LAST_ACK", "0A" => "LISTEN", "0B" => "CLOSING", "0C" => "NEW_SYN_RECV"}

TCP states code mapping.

Used in Miniss::Socket#parse_line.

NOTE Parsed from /usr/src/linux/include/net/tcp_states.h. I made the choice not to use the same words as ss (https://github.com/sivasankariit/iproute2/blob/1179ab033c31d2c67f406be5bcd5e4c0685855fe/misc/ss.c#L400-L413).

UDP_STATES = TCP_STATES

UDP "states" (UDP is stateless) code mapping.

Used in Miniss::Socket#parse_line.

NOTE sk_state in /usr/src/linux/include/net/udp.h is always ESTABLISHED or CLOSE (ss shows UNCONN for unconnected).

VERSION = "0.0.2"

miniss version.

NOTE see all versions available on the release page.

Class Method Summary

Class Method Detail

def self.decode_addr(addr : String, ipv : UInt8) : String #

Returns the decoded IPv4 address + port from hexadecimal format (low nibble) to the dotted decimal format. Returns the decoded IPv6 address + port from hexadecimal format (low nibble) to the double-dotted hexadecimal format.

Example:

Miniss.decode_addr("3500007F:0035", 4_u8)                         # => "127.0.0.53:53"
Miniss.decode_addr("000080FE00000000FF005450B6AD1DFE:0222", 6_u8) # => "[fe80::5054:ff:fe1d:adb6]:546"
Miniss.decode_addr("00000000000000000000000000000000:14E9", 6_u8) # => "[::]:5353"