Function: erc-normalize-port
erc-normalize-port is a byte-compiled function defined in erc.el.gz.
Signature
(erc-normalize-port PORT)
Documentation
Normalize known PORT specifications to an integer.
Expect PORT to be an integer, a string, or a symbol to coerce into a standardized form for the express purpose of equality comparisons. If PORT is an IANA recognized service, return its numeric mapping. Do the same for a few traditional but nonstandard names. Return nil in pathological cases.
Source Code
;; Defined in /usr/src/emacs/lisp/erc/erc.el.gz
(defun erc-normalize-port (port)
"Normalize known PORT specifications to an integer.
Expect PORT to be an integer, a string, or a symbol to coerce into a
standardized form for the express purpose of equality comparisons. If
PORT is an IANA recognized service, return its numeric mapping. Do the
same for a few traditional but nonstandard names. Return nil in
pathological cases."
;; These were updated somewhat in 2022 to reflect modern standards
;; and practices. See also:
;;
;; https://datatracker.ietf.org/doc/html/rfc7194#section-1
;; https://www.iana.org/assignments/service-names-port-numbers
(cond
((symbolp port)
(and port (erc-normalize-port (symbol-name port))))
((stringp port)
(let ((port-nr (string-to-number port)))
(cond
((> port-nr 0)
port-nr)
((string-equal port "irc")
194)
((string-equal port "ircs")
994)
((string-equal port "ircu") 6665)
((string-equal port "ircu-2") 6666)
((string-equal port "ircu-3") 6667)
((string-equal port "ircu-4") 6668)
((string-equal port "ircu-5") 6669)
((string-equal port "ircd") ; nonstandard (irc-serv is 529)
6667)
((string-equal port "ircs-u") 6697)
((string-equal port "ircd-dalnet")
7000)
((string-empty-p port) nil)
(t
0))))
((numberp port)
port)
(t
nil)))