summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-27 16:35:28 (UTC)
committer mjm <mjm>2002-12-27 16:35:28 (UTC)
commit3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf (patch) (side-by-side diff)
tree180016a8feae9e40c3e6b8be62b518bdf8ef18fc
parente6aaae74f39e3aed4dc3c186c56f92cef8c7da09 (diff)
downloadopie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.zip
opie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.tar.gz
opie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.tar.bz2
cleanup, new protocol, renaming of some functions, GUI has to update!
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/Makefile16
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc9
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh4
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/proto.cc109
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.cc4
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.hh4
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_log.cc (renamed from noncore/net/wellenreiter/libwellenreiter/source/log.cc)2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_log.hh (renamed from noncore/net/wellenreiter/libwellenreiter/source/log.hh)0
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc132
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh (renamed from noncore/net/wellenreiter/libwellenreiter/source/proto.hh)6
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc (renamed from noncore/net/wellenreiter/libwellenreiter/source/sock.cc)24
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh (renamed from noncore/net/wellenreiter/libwellenreiter/source/sock.hh)6
12 files changed, 164 insertions, 152 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/Makefile b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
index 3670d96..51b5ff3 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/Makefile
+++ b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
@@ -2,14 +2,13 @@
-INCLUDES =
-LIBRARIES =
-LIBOBJ = proto.o sock.o log.o cardmode.o sniff.o
-CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG
+OBJ = wl_proto.o wl_sock.o wl_log.o cardmode.o sniff.o
+CPP = g++
+CPPFLAGS = -Wall -pedantic -g -DDEBUG
static: libwellenreiter.a
-libwellenreiter.a: $(LIBOBJ)
- ar -cr libwellenreiter.a $(LIBOBJ)
+libwellenreiter.a: $(OBJ)
+ ar -cr libwellenreiter.a $(OBJ)
shared: libwellenreiter.so
-libwellenreiter.so: $(LIBOBJ)
- $(CXX) -shared -o libwellenreiter.so $(LIBOBJ)
+libwellenreiter.so: $(OBJ)
+ $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ)
@@ -17 +16,2 @@ clean:
rm -f *.o *.a *.so *~
+
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
index 3aaa4a7..c29f4d0 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc
@@ -7,3 +7,3 @@
#include "cardmode.hh"
-#include "log.hh"
+#include "wl_log.hh"
@@ -14,3 +14,2 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
FILE *CISCO_CONFIG_FILE;
- pcap_t *handle = (pcap_t*)orighandle;
@@ -35,3 +34,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
/* bring the sniffer into rfmon mode */
- snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device);
+ snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device);
if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
@@ -49,3 +48,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
char wlanngcmd[62];
- snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
+ snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
if (system(wlanngcmd) != 0)
@@ -70,3 +69,3 @@ int card_set_promisc_up (const char *device)
- snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device);
+ snprintf(ifconfigcmd, sizeof(ifconfigcmd) - 1, SBIN_PATH, device);
retval = system(ifconfigcmd);
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
index b85b7b7..6ec5b95 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh
@@ -12,8 +12,4 @@
#include <netinet/in.h>
-
-extern "C"
-{
#include <net/bpf.h>
#include <pcap.h>
-}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc
deleted file mode 100644
index a1228e4..0000000
--- a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc
+++ b/dev/null
@@ -1,109 +0,0 @@
-/*
- * Communication protocol
- *
- * $Id$
- */
-
-#include "proto.hh"
-#include "sock.hh"
-#include "log.hh"
-
-/* Send found network to GUI */
-int send_network_found (const char *guihost, int guiport, void *structure)
-{
- wl_network_t *ptr;
- char buffer[2048];
- char temp[5];
-
- ptr = (wl_network_t *)structure;
-
- memset(buffer, 0, 2048);
-
- /* Type = Found new net */
- memcpy(buffer, "01", 2);
-
- /* Set Net-type */
- memset(temp, 0, sizeof(temp));
- snprintf(temp, 2, "%d", ptr->net_type);
- memcpy(buffer + 2, temp, 1);
-
- /* Set channel */
- memset(temp, 0, sizeof(temp));
-
- if(ptr->channel < 10)
- snprintf(temp, 3, "0%d", ptr->channel);
- else
- snprintf(temp, 3, "%d", ptr->channel);
-
- memcpy(buffer + 3, temp, 2);
-
- /* Set WEP y/n */
- memset(temp, 0, sizeof(temp));
- snprintf(temp, 2, "%d", ptr->wep);
- memcpy(buffer + 5, temp, 1);
-
- /* Set MAC address */
- memcpy(buffer + 6, ptr->mac, 17);
-
- /* Set lenght of ssid */
- memset(temp, 0, sizeof(temp));
-
- if(ptr->ssid_len > 99)
- snprintf(temp, 4, "%d", ptr->ssid_len);
- else if(ptr->ssid_len < 10)
- snprintf(temp, 4, "00%d", ptr->ssid_len);
- else
- snprintf(temp, 4, "0%d", ptr->ssid_len);
-
- memcpy(buffer + 23, temp, 3);
-
- /* Set ssid */
- memcpy(buffer + 26, ptr->bssid, ptr->ssid_len);
-
- /* Send prepared buffer to GUI */
-#ifdef DEBUG
- wl_loginfo("Sending network to GUI: '%s'", buffer);
-#endif
-
- sendcomm(guihost, guiport, buffer);
-
- return 1;
-}
-
-/* Fill buffer into structur */
-int get_network_found (void *structure, const char *buffer)
-{
- wl_network_t *ptr;
- char temp[512];
-
- ptr = (wl_network_t *)structure;
-
- /* Get net type */
- memset(temp, 0, sizeof(temp));
- memcpy(temp, buffer + 2, 1);
- ptr->net_type = atoi(temp);
-
- /* Get channel */
- memset(temp, 0, sizeof(temp));
- memcpy(temp, buffer + 3, 2);
- ptr->channel = atoi(temp);
-
- /* Set WEP y/n */
- memset(temp, 0, sizeof(temp));
- memcpy(temp, buffer + 5, 1);
- ptr->wep = atoi(temp);
-
- /* Set MAC address */
- memcpy(ptr->mac, buffer + 6, 17);
- ptr->mac[17]='\0';
-
- /* Set lenght of ssid */
- memset(temp, 0, sizeof(temp));
- memcpy(temp, buffer + 23, 3);
- ptr->ssid_len = atoi(temp);
-
- /* Set ssid */
- memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1);
-
- return 1;
-}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
index c703052..e2169ca 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc
@@ -9,4 +9,4 @@
#include "extract.hh"
-#include "log.hh"
-#include "proto.hh"
+#include "wl_log.hh"
+#include "wl_proto.hh"
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
index c7108ac..713b383 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh
@@ -14,8 +14,4 @@
#include <arpa/inet.h>
-
-extern "C"
-{
#include <net/bpf.h>
#include <pcap.h>
-}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.cc
index af7f909..7adaba8 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/log.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.cc
@@ -6,3 +6,3 @@
-#include "log.hh"
+#include "wl_log.hh"
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.hh
index 8f6e543..8f6e543 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/log.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.hh
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
new file mode 100644
index 0000000..f15523f
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -0,0 +1,132 @@
+/*
+ * Communication protocol
+ *
+ * $Id$
+ */
+
+#include "wl_proto.hh"
+#include "wl_log.hh"
+#include "wl_sock.hh"
+
+/* Adds a field to the buffer */
+int add_field(char *buffer, char *string, int len)
+{
+ char newlen[5];
+
+ /* 3 Byte = Length */
+ snprintf(newlen, sizeof(newlen) - 1, "%.3d", len);
+ memcpy(buffer, newlen, 3);
+
+ /* Length bytes = Value */
+ memcpy(buffer + 3, string, atoi(newlen));
+
+ /* Return length of attached field */
+ return (atoi(newlen) + 3);
+}
+
+int get_field(const char *buffer, char *out)
+{
+ char len[5];
+
+ /* Get length of value */
+ memcpy(len, buffer, 3);
+
+ /* Copy buffer to out pointer */
+ memset(out, 0, atoi(len) + 1);
+ memcpy(out, buffer + 3, atoi(len));
+
+ return atoi(len) + 3;
+}
+
+/* Send found network to GUI */
+int send_network_found (const char *guihost, int guiport, void *structure)
+{
+ wl_network_t *ptr;
+ char buffer[2048];
+ char temp[128];
+ int retval=0, len=0;
+
+ memset(temp, 0, sizeof(temp));
+
+ ptr = (wl_network_t *)structure;
+
+ /* Type = Found new net (without length field) */
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), "%.2d", NETFOUND);
+ memcpy(buffer, temp, 2);
+ len += 2;
+
+ /* Set Net-type */
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), "%d", ptr->net_type);
+ retval = add_field(buffer + len, temp, 1);
+ len += retval;
+
+ /* Set channel */
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
+ retval = add_field(buffer + len, temp, 2);
+ len += retval;
+
+ /* Set WEP y/n */
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp), "%d", ptr->wep);
+ retval = add_field(buffer + len, temp, 1);
+ len += retval;
+
+ /* Set Mac */
+ retval = add_field(buffer + len, (char *)ptr->mac, 17);
+ len += retval;
+
+ /* Set ssid */
+ retval = add_field(buffer + len, (char *)ptr->bssid, ptr->ssid_len);
+
+ /* Send prepared buffer to GUI */
+#ifdef DEBUG
+ wl_loginfo("Sending network to GUI: '%s'", buffer);
+#endif
+
+ wl_send(guihost, guiport, buffer);
+
+ return 1;
+}
+
+/* Fill buffer into structur */
+int get_network_found (void *structure, const char *buffer)
+{
+ wl_network_t *ptr;
+ char temp[512];
+ int retval=0, len=0;
+
+ ptr = (wl_network_t *)structure;
+
+ /* packet type already determined */
+ len += 2;
+
+ /* Get net type */
+ memset(temp, 0, sizeof(temp));
+ retval = get_field(buffer + len, temp);
+ len += retval;
+ ptr->net_type = atoi(temp);
+
+ /* Get channel */
+ memset(temp, 0, sizeof(temp));
+ retval = get_field(buffer + len, temp);
+ len += retval;
+ ptr->channel = atoi(temp);
+
+ /* Set WEP y/n */
+ memset(temp, 0, sizeof(temp));
+ retval = get_field(buffer + len, temp);
+ len += retval;
+ ptr->wep = atoi(temp);
+
+ /* Set MAC address */
+ retval = get_field(buffer + len, ptr->mac);
+ len += retval;
+
+ /* Set BSSID */
+ retval = get_field(buffer + len, ptr->bssid);
+
+ return 1;
+}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
index e3e9f50..f755589 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/proto.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
@@ -2,4 +2,4 @@
-#ifndef PROTO_HH
-#define PROTO_HH
+#ifndef WLPROTO_HH
+#define WLPROTO_HH
@@ -27,2 +27,2 @@ typedef struct {
-#endif /* PROTO_HH */
+#endif /* WLPROTO_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
index 90fc20a..5714afb 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
@@ -6,7 +6,7 @@
-#include "sock.hh"
-#include "log.hh"
+#include "wl_sock.hh"
+#include "wl_log.hh"
/* Setup UDP Socket for incoming commands */
-int commsock(const char *host, int port)
+int wl_setupsock(const char *host, int port)
{
@@ -37,3 +37,3 @@ int commsock(const char *host, int port)
/* Send a string to commsock */
-int sendcomm(const char *host, int port, const char *string, ...)
+int wl_send(const char *host, int port, const char *string, ...)
{
@@ -65,3 +65,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
close(sock);
- return 0;
+ return -1;
}
@@ -71,3 +71,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
- return 1;
+ return 0;
}
@@ -75,3 +75,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
/* Check for new messages on commsock */
-int recvcomm(int *sock, char *out, int maxlen)
+int wl_recv(int *sock, char *out, int maxlen)
{
@@ -79,11 +79,9 @@ int recvcomm(int *sock, char *out, int maxlen)
socklen_t len=sizeof(struct sockaddr);
- char buffer[128], retval[3];
-
- memset(buffer, 0, sizeof(buffer));
- if(recvfrom(*sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0)
- return -1;
+ char retval[3];
memset(out, 0, maxlen);
- memcpy(out, buffer, maxlen - 1);
+ if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0)
+ return -1;
+ /* Get packet type and return it */
memset(retval, 0, sizeof(retval));
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh
index 611e335..6ddbaef 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh
@@ -15,5 +15,5 @@
-int commsock(const char *, int);
-int sendcomm(const char *, int, const char *, ...);
-int recvcomm(int *, char *, int);
+int wl_setupsock(const char *, int);
+int wl_send(const char *, int, const char *, ...);
+int wl_recv(int *, char *, int);