Method code for $daemon.parse_port()

[Turn off line numbering]
  1: arg str;
  2: var m, host, port, ip;
  3: 
  4: if ((m = str.regexp("^([^:]+):(.*)$"))) {
  5:     [host, port] = m;
  6:     host = host.trim();
  7:     port = port.trim();
  8:     if (host) {
  9:         ip = $dns.ip(host);
 10:         if (ip == "-1")
 11:             throw(~parse, "Unable to resolv hostname: " + host);
 12:         host = ip;
 13:     }
 14: } else {
 15:     port = str;
 16:     host = "";
 17: }
 18: if (!port.is_numeric())
 19:     throw(~parse, "Invalid port: " + port);
 20: port = toint(port);
 21: if (port <= 0 || port > 65535)
 22:     throw(~parse, "Invalid port " + port + " (out of range, must be 0 .. 65535)");
 23: if (host)
 24:     return [port, host];
 25: else
 26:     return [port];

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

Tlon