8.35 Common Internet Routines

8.35.1 IP Address Handling

8.35.1.1 is_inetaddr

include std/net/common.e
namespace common
public function is_inetaddr(sequence address)

Checks if x is an IP address in the form (#.#.#.#[:#])

Parameters:
  1. address : the address to check
Returns:

An integer, 1 if x is an inetaddr, 0 if it is not

Comments:

Some ip validation algorithms do not allow 0.0.0.0. We do here because many times you will want to bind to 0.0.0.0. However, you cannot connect to 0.0.0.0 of course.

With sockets, normally binding to 0.0.0.0 means bind to all interfaces that the computer has.

8.35.1.2 parse_ip_address

include std/net/common.e
namespace common
public function parse_ip_address(sequence address, integer port = - 1)

Converts a text "address:port" into {"address", port} format.

Parameters:
  1. address : ip address to connect, optionally with :PORT at the end
  2. port : optional, if not specified you may include :PORT in the address parameter otherwise the default port 80 is used.
Comments:

If port is supplied, it overrides any ":PORT" value in the input address.

Returns:

A sequence, of two elements: "address" and integer port number.

Example 1:
addr = parse_ip_address("11.1.1.1") --> {"11.1.1.1", 80} -- default port
addr = parse_ip_address("11.1.1.1:110") --> {"11.1.1.1", 110}
addr = parse_ip_address("11.1.1.1", 345) --> {"11.1.1.1", 345}

8.35.2 URL Parsing

8.35.2.1 URL_ENTIRE

include std/net/common.e
namespace common
public constant URL_ENTIRE

8.35.2.2 URL_PROTOCOL

include std/net/common.e
namespace common
public constant URL_PROTOCOL

8.35.2.3 URL_HTTP_DOMAIN

include std/net/common.e
namespace common
public constant URL_HTTP_DOMAIN

8.35.2.4 URL_HTTP_PATH

include std/net/common.e
namespace common
public constant URL_HTTP_PATH

8.35.2.5 URL_HTTP_QUERY

include std/net/common.e
namespace common
public constant URL_HTTP_QUERY

8.35.2.6 URL_MAIL_ADDRESS

include std/net/common.e
namespace common
public constant URL_MAIL_ADDRESS

8.35.2.7 URL_MAIL_USER

include std/net/common.e
namespace common
public constant URL_MAIL_USER

8.35.2.8 URL_MAIL_DOMAIN

include std/net/common.e
namespace common
public constant URL_MAIL_DOMAIN

8.35.2.9 URL_MAIL_QUERY

include std/net/common.e
namespace common
public constant URL_MAIL_QUERY

8.35.2.10 parse_url

include std/net/common.e
namespace common
public function parse_url(sequence url)

Parse a common URL. Currently supported URLs are http(s), ftp(s), gopher(s) and mailto.

Parameters:
  1. url : url to be parsed
Returns:

A sequence, containing the URL details. You should use the URL_ constants to access the values of the returned sequence. You should first check the protocol (URL_PROTOCOL) that was returned as the data contained in the return value can be of different lengths.

On a parse error, -1 will be returned.

Example 1:
object url_data = parse_url("http://john.com/index.html?name=jeff")
-- url_data = {
--     "http://john.com/index.html?name=jeff", -- URL_ENTIRE
--     "http",          -- URL_PROTOCOL
--     "john.com",      -- URL_DOMAIN
--     "/index.html",   -- URL_PATH
--     "?name=jeff"     -- URL_QUERY
-- }

url_data = parse_url("mailto:john@mail.doe.com?subject=Hello%20John%20Doe")
-- url_data = {
--   "mailto:john@mail.doe.com?subject=Hello%20John%20Doe",
--   "mailto",
--   "john@mail.doe.com",
--   "john",
--   "mail.doe.com",
--   "?subject=Hello%20John%20Doe"
-- }