#include <glib.h>
#include <gio/gio.h>

// gcc -o network-address network-address.c `pkg-config --cflags --libs glib-2.0 gio-2.0`

int main()
{
  GSocketConnectable *connectable;
  guint16 port;
  guint16 expected_port;

  g_type_init ();

  connectable = g_network_address_parse_uri ("http://www.facebook.com/", 0, NULL);
  port = g_network_address_get_port (G_NETWORK_ADDRESS (connectable));
  expected_port = 80;
  g_print ("port: %d expected_port=%d\n", port, expected_port);

  connectable = g_network_address_parse_uri ("http://www.facebook.com:8080/", 0, NULL);
  port = g_network_address_get_port (G_NETWORK_ADDRESS (connectable));
  expected_port = 8080;
  g_print ("port: %d expected_port=%d\n", port, expected_port);

  connectable = g_network_address_parse_uri ("https://www.twitter.com/", 0, NULL);
  port = g_network_address_get_port (G_NETWORK_ADDRESS (connectable));
  expected_port = 443;
  g_print ("port: %d expected_port=%d\n", port, expected_port);

  connectable = g_network_address_parse_uri ("https://www.twitter.com:8282/", 0, NULL);
  port = g_network_address_get_port (G_NETWORK_ADDRESS (connectable));
  expected_port = 8282;
  g_print ("port: %d expected_port=%d\n", port, expected_port);

  return 0;
}

