def valid_port(port)
      port_number = port.to_s.to_i(10) if /\A[0-9]+\z/ =~ port.to_s
      port_number if (1...2**16).cover? port_number
    end
def valid_port(port)
      port_number = port.to_s.to_i(10) if /\A[0-9]+\z/ =~ port.to_s
      port_number if (1...2**16).cover? port_number
    end
Sanitizes a TCP/IP port number.

 @param port [#to_i, #to_s] the port number to sanitize
 @return [Integer, nil] the sanitized value or +nil+ on error