Method code for $daemon.parse_port()

[Turn on line numbering]
arg str;
var m, host, port, ip;

if ((m = str.regexp("^([^:]+):(.*)$"))) {
    [host, port] = m;
    host = host.trim();
    port = port.trim();
    if (host) {
        ip = $dns.ip(host);
        if (ip == "-1")
            throw(~parse, "Unable to resolv hostname: " + host);
        host = ip;
    }
} else {
    port = str;
    host = "";
}
if (!port.is_numeric())
    throw(~parse, "Invalid port: " + port);
port = toint(port);
if (port <= 0 || port > 65535)
    throw(~parse, "Invalid port " + port + " (out of range, must be 0 .. 65535)");
if (host)
    return [port, host];
else
    return [port];

// Created 22-Aug-1995 as a part of ColdCore, see: @help Credit

Tlon