From 353aefa427b0153fe1db25781771bf1c52fab4d6 Mon Sep 17 00:00:00 2001 From: Barrucadu Date: Wed, 29 Apr 2009 19:01:48 +0100 Subject: Replaced FIFO interface with socket. --- uzblctrl.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 uzblctrl.c (limited to 'uzblctrl.c') diff --git a/uzblctrl.c b/uzblctrl.c new file mode 100644 index 0000000..5415247 --- /dev/null +++ b/uzblctrl.c @@ -0,0 +1,63 @@ +/* Socket code more or less completely copied from here: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static gchar* sockpath; +static gchar* command; + +static GOptionEntry entries[] = +{ + { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Socket path of the client uzbl", NULL }, + { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL }, + { NULL, 0, 0, 0, NULL, NULL, NULL } +}; + +int +main(int argc, char* argv[]) { + GError *error = NULL; + GOptionContext* context = g_option_context_new ("- some stuff here maybe someday"); + g_option_context_add_main_entries (context, entries, NULL); + g_option_context_add_group (context, gtk_get_option_group (TRUE)); + g_option_context_parse (context, &argc, &argv, &error); + + int s, len; + struct sockaddr_un remote; + + if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) { + perror ("socket"); + exit (1); + } + + remote.sun_family = AF_UNIX; + strcpy (remote.sun_path, (char *) sockpath); + len = strlen (remote.sun_path) + sizeof (remote.sun_family); + + if (connect (s, (struct sockaddr *) &remote, len) == -1) { + perror ("connect"); + exit (1); + } + + if (send (s, command, strlen (command), 0) == -1) { + perror ("send"); + exit (1); + } + + close(s); + + return 0; +} -- cgit v1.2.3