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 */
10 #include <sys/socket.h>
13 static gchar* sockpath;
14 static gchar* command;
16 static GOptionEntry entries[] =
18 { "socket", 's', 0, G_OPTION_ARG_STRING, &sockpath, "Path to the uzbl socket", NULL },
19 { "command", 'c', 0, G_OPTION_ARG_STRING, &command, "The uzbl command to execute", NULL },
20 { NULL, 0, 0, 0, NULL, NULL, NULL }
24 main(int argc, char* argv[]) {
26 GOptionContext* context = g_option_context_new ("- utility for controlling and interacting with uzbl through its socket file"); /* TODO: get stuff back from uzbl */
27 g_option_context_add_main_entries (context, entries, NULL);
28 g_option_context_add_group (context, gtk_get_option_group (TRUE));
29 g_option_context_parse (context, &argc, &argv, &error);
32 if (sockpath && command) {
34 struct sockaddr_un remote;
37 if ((s = socket (AF_UNIX, SOCK_STREAM, 0)) == -1) {
42 remote.sun_family = AF_UNIX;
43 strcpy (remote.sun_path, (char *) sockpath);
44 len = strlen (remote.sun_path) + sizeof (remote.sun_family);
46 if (connect (s, (struct sockaddr *) &remote, len) == -1) {
51 if ((send (s, command, strlen (command), 0) == -1) ||
52 (send (s, "\n", 1, 0) == -1)) {
57 while ((len = recv (s, &tmp, 1, 0))) {
67 fprintf(stderr, "Usage: uzblctrl -s /path/to/socket -c \"command\"");
71 /* vi: set et ts=4: */