aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Ghigonis <laurent@p1sec.com>2013-10-13 18:54:26 +0200
committerLaurent Ghigonis <laurent@p1sec.com>2013-10-13 18:54:26 +0200
commita9d826e96b54c0699a81c35564b2cd0b53fc514f (patch)
treeec05dfd815ff1811c5a3102a9b8e8610d92c4a23
parentadd todo.txt (diff)
downloadglouglou-a9d826e96b54c0699a81c35564b2cd0b53fc514f.tar.xz
glouglou-a9d826e96b54c0699a81c35564b2cd0b53fc514f.zip
add dummy probe
-rw-r--r--v3/ggprobe_dummy/Makefile20
-rw-r--r--v3/ggprobe_dummy/ggprobe_dummy.c143
2 files changed, 163 insertions, 0 deletions
diff --git a/v3/ggprobe_dummy/Makefile b/v3/ggprobe_dummy/Makefile
new file mode 100644
index 0000000..ca081bd
--- /dev/null
+++ b/v3/ggprobe_dummy/Makefile
@@ -0,0 +1,20 @@
+PROG = ggprobe_dummy
+SOURCES = ggprobe_dummy.c
+OBJECTS = $(SOURCES:.c=.o)
+CFLAGS+=-Wall -g
+LDFLAGS=-levent -ldnet -lglouglou -lsendbuf -ldl -lhiredis
+
+PREFIX=/usr/local
+BINDIR=$(PREFIX)/sbin
+
+all:
+ make $(OBJECTS)
+ $(CC) $(OBJECTS) -o $(PROG) $(LDFLAGS)
+
+install: $(PROG)
+ @echo "installation of $(PROG)"
+ mkdir -p $(BINDIR)
+ install -m 0755 $(PROG) $(BINDIR)
+
+clean:
+ rm -f $(PROG) $(OBJECTS) *~
diff --git a/v3/ggprobe_dummy/ggprobe_dummy.c b/v3/ggprobe_dummy/ggprobe_dummy.c
new file mode 100644
index 0000000..585e8e0
--- /dev/null
+++ b/v3/ggprobe_dummy/ggprobe_dummy.c
@@ -0,0 +1,143 @@
+#include <stdlib.h>
+#include <signal.h>
+#include <unistd.h>
+#include <err.h>
+#include <string.h>
+
+#include <event.h>
+#include <libglouglou.h>
+
+#include <libglouglou/ext/ggpkt_mod_0_internal.h>
+
+int _test_connected;
+int _test_receive_response;
+
+#if defined(__OPENBSD__)
+void __dead
+#else
+void
+#endif
+usage(void)
+{
+ // XXX extern char *__progname;
+
+ fprintf(stderr, "usage: [-hv] glougloud_ip glougloud_port [notice_msg]\n");
+ exit(1);
+}
+
+int
+handle_conn(struct gg_client *prb)
+{
+ _test_connected = 1;
+ return 0;
+}
+
+int
+handle_pkt(struct gg_client *prb, struct ggpkt *pkt)
+{
+ struct ggpkt_mod_0_internal *body;
+
+ body = ggpkt_mod_0_internal_decode(pkt);
+ if (body->type == GGPKT_MOD_0_INTERNAL_PING_RES)
+ _test_receive_response = 1;
+ else
+ printf("Warning: received msg != GGPKT_MOD_0_INTERNAL_PING_RES !\n");
+
+ _test_receive_response = 1;
+ return 0;
+}
+
+int
+main(int argc, char **argv)
+{
+ int *register_module_ids = [ GGPKT_MOD_0_INTERNAL_ID, -1 ];
+ struct event_base *evb;
+ struct gg_client *cli;
+ struct ggpkt *pkt;
+ char *notice_msg;
+ int notice_len;
+ int loglevel;
+ struct addr ip;
+ int port;
+ int res;
+ int op;
+
+ _test_connected = 0;
+ _test_receive_response = 0;
+
+ notice_msg = NULL;
+ notice_len = 0;
+ loglevel = 0;
+ while ((op = getopt(argc, argv, "hN:t:v")) != -1) {
+ switch (op) {
+ case 'h':
+ usage();
+ /* NOTREACHED */
+ case 'v':
+ loglevel++;
+ break;
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc < 2 || argc > 3)
+ usage();
+
+ addr_aton(argv[0], &ip);
+ port = atoi(argv[1]);
+ if (argc == 3) {
+ notice_msg = strdup(argv[2]);
+ notice_len = strlen(notice_msg);
+ }
+
+ evb = event_base_new();
+
+ cli = gg_client_connect(evb, &ip, port, register_modules,
+ handle_conn, handle_pkt);
+ if (!cli) {
+ printf("Error: could not connect ! (gg_client_connect failed)\n");
+ return 2;
+ }
+
+ pkt = ggpkt_mod_0_internal_ping()
+ if (!pkt) {
+ printf("Error: could not create PING packet !\n");
+ return 10;
+ }
+ res = gg_client_send(cli, pkt);
+ if (res < 0) {
+ printf("Error: could not send PING !\n");
+ return 11;
+ }
+
+ if (notice_msg) {
+ pkt = ggpkt_mod_0_internal_notice(notice_len, notice_msg);
+ if (!pkt) {
+ printf("Error: could not create NOTICE packet !\n");
+ return 10;
+ }
+ res = gg_client_send(cli, pkt);
+ if (res < 0) {
+ printf("Error: could not send NOTICE !\n");
+ return 11;
+ }
+ }
+
+ event_base_dispatch(evb);
+
+ gg_client_disconnect(cli);
+
+ if (_test_connected == 0) {
+ printf("Error: could not connect ! (test_connected == 0)\n");
+ return 1;
+ }
+ if (_test_receive_response == 0) {
+ printf("Error: did not receive response !");
+ return 15;
+ }
+
+ return 0;
+}