From: Thadeu Lima de Souza Cascardo Date: Thu, 17 Oct 2013 11:17:47 +0000 (-0300) Subject: Added program to send command to daemon. X-Git-Url: http://git.cascardo.info/?p=cascardo%2Ff2fchat.git;a=commitdiff_plain;h=f665f8e4be13337c14af2061ef6f2c8d6cb4288f Added program to send command to daemon. --- diff --git a/Makefile.am b/Makefile.am index 6ed461a..6e77a5e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..174cbfb --- /dev/null +++ b/f2fcmd.c @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2013 Thadeu Lima de Souza Cascardo + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +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; +}