0

I'm trying to use the Gnome glib/gio C library to create a client program to connect to a server via IPv6. My server box has a link local IPv6 address:

inet6 addr: fe80::2d0:c9ff:feda:99e0/64 Scope:Link

So, I to access it, I have to tell the client software which interface to use (eth0 in this case). So the following works (using port 1500):

nc -6 fe80::2d0:c9ff:feda:99e0%eth0 1500

In glib, using the %eth0 notation violates the URI notation:

(process:31159): GLib-GIO-WARNING **: Invalid URI 'none://[fe80:0:0:0:2d0:c9ff:feda:99e0%eth0]:1500'

I've looked in the code and it clearly expects to see the percent escape notation (i.e. the characters '%25') but I can't seem to get the format correct:

** (process:5741): ERROR **: Invalid URI 'none://[fe80:0:0:0:2d0:c9ff:feda:99e0%25eth0]1500'

So, anyone know how to specify the interface?

EDIT: Here's the code

// gchar test[255] = "fe80:0:0:0:2d0:c9ff:feda:99e0%eth0";
// gchar test[255] = "fe80:0:0:0:2d0:c9ff:feda:99e0\%eth0";
// gchar test[255] = "fe80:0:0:0:2d0:c9ff:feda:99e0\x25eth0";
// gchar test[255] = "fe80:0:0:0:2d0:c9ff:feda:99e0\%%25eth0";
gchar test[255] = "[fe80:0:0:0:2d0:c9ff:feda:99e0\%%eth0]";

connection = g_socket_client_connect_to_uri (client,
                                           test,
                                           1500,
                                           NULL,
                                           &error);

EDIT 2: Complete code (with MichaelHampton's input):

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

int
main (int argc, char *argv[])
{
   /* initialize glib */
  g_type_init ();

  GError * error = NULL;

  /* create a new connection */
  GSocketConnection * connection = NULL;
  GSocketClient * client = g_socket_client_new();

    connection = g_socket_client_connect_to_host (client,
                                                  (gchar*)"fe80::5054:ff:fe1f:6b6c\%br0",
                                                   1500, /* your port goes here */
                                                   NULL,
                                                   &error);

  /* don't forget to check for errors */
  if (error != NULL)
  {
      g_error (error->message);
  }
  else
  {
      g_print ("Connection successful!\n");
  }

  return 0;
}
mjohnson
  • 33
  • 1
  • 6

1 Answers1

0

Ah, you're calling the wrong function. You should be using g_socket_client_connect_to_host to connect directly to a host and port.

Here is a working example:

 connection = g_socket_client_connect_to_host (client,
                                              (gchar*)"fe80::5054:ff:fe1f:6b6c\%br0",
                                               1500, /* your port goes here */
                                               NULL,
                                               &error);

The complete example code, which it looked like you were using, was in the related question: GIO socket-server / -client example

Community
  • 1
  • 1
Michael Hampton
  • 9,737
  • 4
  • 55
  • 96
  • Yes that is the example I was basing this code from. I should have included the link. So this actually works for you? I get: `(process:9392): GLib-GIO-WARNING **: Invalid URI 'none://[fe80::5054:ff:fe1f:6b6c%br0]:1500'` `(process:9392): GLib-GIO-CRITICAL **: g_proxy_resolver_lookup: assertion `uri != NULL' failed` `** (process:9392): ERROR **: Unknown error on connect` – mjohnson Jan 06 '14 at 17:43
  • I'm afraid I copied your code verbatim. The reason I originally switched to the *_to_uri function call is because that's what the *_to_host function calls. I just cut out the middle man. Interesting that it works for you and not me. I've tried this on Ubuntu 12.04 and Debian Wheezy. May I ask what system you're using? – mjohnson Jan 06 '14 at 19:22
  • I'm running on Fedora 20. I generally stay away from Debian/Ubuntu for a variety of reasons. – Michael Hampton Jan 06 '14 at 19:29
  • Tried your code on a box running Fedora 19. I get the same error: Invalid URI 'none://[fe80::5054:ff:fe1f:6b6c%br0]:1500 – mjohnson Jan 06 '14 at 20:28