Added program to send command to daemon.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Thu, 17 Oct 2013 11:17:47 +0000 (08:17 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Thu, 17 Oct 2013 11:17:47 +0000 (08:17 -0300)
Makefile.am
f2fcmd.c [new file with mode: 0644]

index 6ed461a..6e77a5e 100644 (file)
@@ -1,4 +1,7 @@
-bin_PROGRAMS = f2fchat
+bin_PROGRAMS = f2fchat f2fcmd
+
 f2fchat_SOURCES = f2fchat.c friend.c message.c
 f2fchat_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS)
 f2fchat_LDFLAGS = $(GLIB_LIBS) $(GIO_LIBS)
+
+f2fcmd_SOURCES = f2fcmd.c
diff --git a/f2fcmd.c b/f2fcmd.c
new file mode 100644 (file)
index 0000000..174cbfb
--- /dev/null
+++ b/f2fcmd.c
@@ -0,0 +1,54 @@
+/*
+ *  Copyright (C) 2013  Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
+int main(int argc, char **argv)
+{
+       int s;
+       struct sockaddr_in sa;
+       int r;
+       if (argc < 2) {
+               fprintf(stderr, "Missing message argument.\n");
+               exit(1);
+       }
+       s = socket(PF_INET, SOCK_DGRAM, 0);
+       if (s < 0) {
+               fprintf(stderr, "Error creating socket: %s.\n", strerror(errno));
+               exit(1);
+       }
+       sa.sin_family = AF_INET;
+       sa.sin_port = htons(17078);
+       sa.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+       r = sendto(s, argv[1], strlen(argv[1]), 0, (struct sockaddr *) &sa, sizeof(sa));
+       if (r < 0) { 
+               fprintf(stderr, "Error sending message: %s\n", strerror(errno));
+               close(s);
+               exit(1);
+       }
+       close(s);
+       return 0;
+}