]> git.sur5r.net Git - ngadmin/commitdiff
Enable spy support
authordarkcoven <admin@darkcoven.tk>
Fri, 27 Sep 2013 22:56:07 +0000 (00:56 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 27 Sep 2013 22:56:07 +0000 (00:56 +0200)
.gitignore
Makefile.am
configure.ac
dump/Makefile [deleted file]
dump/dump.c [deleted file]
spy/Makefile.am [new file with mode: 0644]
spy/man/Makefile.am [new file with mode: 0644]
spy/src/Makefile.am [new file with mode: 0644]
spy/src/spy.c [new file with mode: 0644]

index 0ad50c49de498fb7ecd212e401e06249f8bb5ab2..bffc0ff05df741b3f87713a3ebc19a4a99cc3b7c 100644 (file)
@@ -6,7 +6,7 @@
 *.a
 *.la
 admin
-ngdump
+ngspy
 lib/doc/
 raw/doc/
 *.m4
index efaba3e87b0edb352bab50bd9c2124169a9c59e8..3146684b7213ede2c85166bf36a4aa3046c22c37 100644 (file)
@@ -3,7 +3,7 @@ ACLOCAL_AMFLAGS = -I .
 
 SUBDIRS = raw lib cli
 
-#if ENABLE_SPY
-#SUBDIRS += dump
-#endif
+if ENABLE_SPY
+SUBDIRS += spy
+endif
 
index ed7bdaf23ecc9f9033119da803cd6a2478b8ad9a..0987be3b0476ba78991ab354b8ad4fff2c2e3425 100644 (file)
@@ -27,6 +27,13 @@ AC_ARG_ENABLE(doc,
        [AS_HELP_STRING([--enable-doc], [enable documentation generation [default=no]])],
        [enable_doc=yes], [enable_doc=no])
 
+# enable/disable build of NgSpy
+AC_ARG_ENABLE(spy,
+       [AS_HELP_STRING([--enable-spy], [enable NgSpy [default=no]])],
+       [enable_spy=yes], [enable_spy=no])
+AM_CONDITIONAL(ENABLE_SPY, test x$enable_spy = xyes)
+
+
 
 if test "x${enable_doc}" = xyes; then
        AC_CHECK_PROGS([DOXYGEN], [doxygen])
@@ -92,6 +99,15 @@ AC_CONFIG_FILES([
        cli/src/Makefile
 ])
 
+AM_COND_IF([ENABLE_SPY], [
+       AC_CONFIG_FILES([
+                       spy/Makefile
+                       spy/man/Makefile
+                       spy/src/Makefile
+               ])
+])
+
+
 AC_OUTPUT
 
 
@@ -101,6 +117,7 @@ Prefix.............: ${prefix}
 Debug..............: ${enable_debug}
 Compiler...........: ${CC} ${CFLAGS} ${CPPFLAGS}
 Readline suppport..: ${with_readline}
+Spy................: ${enable_spy}
 "
 
 
diff --git a/dump/Makefile b/dump/Makefile
deleted file mode 100644 (file)
index 9d347c1..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-
-CC=gcc
-CFLAGS=-I../raw/include/ -W -Wall -Wextra -Os
-LDFLAGS=-L../raw -lrawnsdp
-EXEC=ngdump
-
-SRC=$(wildcard *.c)
-OBJ=$(SRC:.c=.o)
-
-
-ifeq ($(DEBUG), yes)
-CFLAGS+=-g
-LDFLAGS+=-g
-else
-CFLAGS+=-fomit-frame-pointer
-LDFLAGS+=-s
-endif
-
-
-$(EXEC): $(OBJ)
-       $(CC) $^ -o $@ $(LDFLAGS)
-
-%.o: %.c
-       $(CC) -c $^ -o $@ $(CFLAGS)
-
-
-clean:
-       @rm -f *.o
-
-mrproper: clean
-       @rm -f $(EXEC)
-
-
-
diff --git a/dump/dump.c b/dump/dump.c
deleted file mode 100644 (file)
index df374ee..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-
-#include <stdio.h>
-#include <unistd.h>
-#include <arpa/inet.h>
-
-#include <protocol.h>
-#include <attr.h>
-
-
-int main (void)
-{
-       char buffer[1500];
-       struct ng_packet np;
-       int err = 0, s, len;
-       struct sockaddr_in local, remote;
-       socklen_t slen = sizeof(struct sockaddr_in);
-       unsigned char error;
-       unsigned short attr_error;
-       List *attr;
-       ListNode *ln;
-       struct attr *at;
-       
-       
-       s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-       if (s < 0) {
-               perror("socket");
-               err = 1;
-               goto end;
-       };
-       
-       
-       memset(&local, 0, sizeof(struct sockaddr_in));
-       local.sin_family = AF_INET;
-       local.sin_addr.s_addr = htonl(INADDR_ANY);
-       local.sin_port = htons(SWITCH_PORT);
-       
-       if (bind(s, (struct sockaddr*)&local, sizeof(struct sockaddr_in)) < 0) {
-               perror("bind");
-               err = 2;
-               goto end;
-       }
-       
-       while (1) {
-               
-               len = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr*)&remote, &slen);
-               if (len < 0) {
-                       perror("recvfrom");
-                       err = 3;
-                       goto end;
-               }
-               
-               printf("---------------------------------\n");
-               
-               np.buffer = buffer;
-               np.maxlen = len;
-               initNgPacket(&np);
-               
-               attr = createEmptyList();
-               
-               if (ntohs(remote.sin_port) != CLIENT_PORT ||
-                   len < (int)sizeof(struct ng_header) ||
-                   !validateNgHeader(np.nh, 0, NULL, NULL, 0) ||
-                   extractPacketAttributes(&np, attr, 0) < 0) {
-                       printf("wrong packet\n");
-                       goto end;
-               }
-               
-               printf("received %d attribute(s)\n", attr->count);
-               
-               for (ln = attr->first; ln != NULL; ln = ln->next) {
-                       at = ln->data;
-                       printf("received attribute code = %04X, length = %d\n", at->attr, at->size);
-               }
-               
-               destroyList(attr, (void(*)(void*))freeAttr);
-               
-               printf("---------------------------------\n\n");
-       }
-       
-       close(s);
-       
-end:
-       return err;
-}
-
diff --git a/spy/Makefile.am b/spy/Makefile.am
new file mode 100644 (file)
index 0000000..1c0c975
--- /dev/null
@@ -0,0 +1,3 @@
+
+SUBDIRS = man src
+
diff --git a/spy/man/Makefile.am b/spy/man/Makefile.am
new file mode 100644 (file)
index 0000000..b28b04f
--- /dev/null
@@ -0,0 +1,3 @@
+
+
+
diff --git a/spy/src/Makefile.am b/spy/src/Makefile.am
new file mode 100644 (file)
index 0000000..9a61a82
--- /dev/null
@@ -0,0 +1,7 @@
+
+bin_PROGRAMS = ngspy
+
+ngspy_SOURCES = spy.c
+ngspy_CPPFLAGS = -I$(top_srcdir)/raw/include/
+ngspy_LDADD = $(top_builddir)/raw/src/librawnsdp.la
+
diff --git a/spy/src/spy.c b/spy/src/spy.c
new file mode 100644 (file)
index 0000000..df374ee
--- /dev/null
@@ -0,0 +1,85 @@
+
+#include <stdio.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+
+#include <protocol.h>
+#include <attr.h>
+
+
+int main (void)
+{
+       char buffer[1500];
+       struct ng_packet np;
+       int err = 0, s, len;
+       struct sockaddr_in local, remote;
+       socklen_t slen = sizeof(struct sockaddr_in);
+       unsigned char error;
+       unsigned short attr_error;
+       List *attr;
+       ListNode *ln;
+       struct attr *at;
+       
+       
+       s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+       if (s < 0) {
+               perror("socket");
+               err = 1;
+               goto end;
+       };
+       
+       
+       memset(&local, 0, sizeof(struct sockaddr_in));
+       local.sin_family = AF_INET;
+       local.sin_addr.s_addr = htonl(INADDR_ANY);
+       local.sin_port = htons(SWITCH_PORT);
+       
+       if (bind(s, (struct sockaddr*)&local, sizeof(struct sockaddr_in)) < 0) {
+               perror("bind");
+               err = 2;
+               goto end;
+       }
+       
+       while (1) {
+               
+               len = recvfrom(s, buffer, sizeof(buffer), 0, (struct sockaddr*)&remote, &slen);
+               if (len < 0) {
+                       perror("recvfrom");
+                       err = 3;
+                       goto end;
+               }
+               
+               printf("---------------------------------\n");
+               
+               np.buffer = buffer;
+               np.maxlen = len;
+               initNgPacket(&np);
+               
+               attr = createEmptyList();
+               
+               if (ntohs(remote.sin_port) != CLIENT_PORT ||
+                   len < (int)sizeof(struct ng_header) ||
+                   !validateNgHeader(np.nh, 0, NULL, NULL, 0) ||
+                   extractPacketAttributes(&np, attr, 0) < 0) {
+                       printf("wrong packet\n");
+                       goto end;
+               }
+               
+               printf("received %d attribute(s)\n", attr->count);
+               
+               for (ln = attr->first; ln != NULL; ln = ln->next) {
+                       at = ln->data;
+                       printf("received attribute code = %04X, length = %d\n", at->attr, at->size);
+               }
+               
+               destroyList(attr, (void(*)(void*))freeAttr);
+               
+               printf("---------------------------------\n\n");
+       }
+       
+       close(s);
+       
+end:
+       return err;
+}
+