1 /* -*- c-basic-offset: 4; -*- */
2 /* Socket code more or less completely copied from here: http://www.ecst.csuchico.edu/~beej/guide/ipc/usock.html */
6 #include <gdk/gdkkeysyms.h>
7 #include <webkit/webkit.h>
12 #include <sys/types.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
21 static gchar* sockpath;
22 static gchar* command;
24 static GOptionEntry entries[] =
26 { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Socket path of the client uzbl", NULL },
27 { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL },
28 { NULL, 0, 0, 0, NULL, NULL, NULL }
32 main(int argc, char* argv[]) {
34 GOptionContext* context = g_option_context_new ("- some stuff here maybe someday");
35 g_option_context_add_main_entries (context, entries, NULL);
36 g_option_context_add_group (context, gtk_get_option_group (TRUE));
37 g_option_context_parse (context, &argc, &argv, &error);
40 if (sockpath && command) {
42 struct sockaddr_un remote;
44 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) {
49 remote.sun_family = AF_UNIX;
50 strcpy (remote.sun_path, (char *) sockpath);
51 len = strlen (remote.sun_path) + sizeof (remote.sun_family);
53 if (connect (s, (struct sockaddr *) &remote, len) == -1) {
58 if (send (s, command, strlen (command), 0) == -1) {
67 printf ("You need to specify the -s and -c parameters for uzblctrl to do anything of use.\n");
68 printf ("Usage: uzblctrl -s /path/to/socket -c \"command\"\n");
72 /* vi: set et ts=4: */