summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-27 16:35:28 (UTC)
committer mjm <mjm>2002-12-27 16:35:28 (UTC)
commit3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf (patch) (unidiff)
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) (ignore 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 @@
2 2
3INCLUDES = 3OBJ = wl_proto.o wl_sock.o wl_log.o cardmode.o sniff.o
4LIBRARIES = 4CPP = g++
5LIBOBJ = proto.o sock.o log.o cardmode.o sniff.o 5CPPFLAGS = -Wall -pedantic -g -DDEBUG
6CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG
7 6
8 static:libwellenreiter.a 7 static:libwellenreiter.a
9libwellenreiter.a: $(LIBOBJ) 8libwellenreiter.a: $(OBJ)
10 ar -cr libwellenreiter.a $(LIBOBJ) 9 ar -cr libwellenreiter.a $(OBJ)
11 10
12 shared:libwellenreiter.so 11 shared:libwellenreiter.so
13libwellenreiter.so: $(LIBOBJ) 12libwellenreiter.so: $(OBJ)
14 $(CXX) -shared -o libwellenreiter.so $(LIBOBJ) 13 $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ)
15 14
@@ -17 +16,2 @@ clean:
17 rm -f *.o *.a *.so *~ 16 rm -f *.o *.a *.so *~
17
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 @@
7#include "cardmode.hh" 7#include "cardmode.hh"
8#include "log.hh" 8#include "wl_log.hh"
9 9
@@ -14,3 +14,2 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
14 FILE *CISCO_CONFIG_FILE; 14 FILE *CISCO_CONFIG_FILE;
15 pcap_t *handle = (pcap_t*)orighandle;
16 15
@@ -35,3 +34,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
35 /* bring the sniffer into rfmon mode */ 34 /* bring the sniffer into rfmon mode */
36 snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); 35 snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device);
37 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) 36 if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL)
@@ -49,3 +48,3 @@ int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype)
49 char wlanngcmd[62]; 48 char wlanngcmd[62];
50 snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); 49 snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device);
51 if (system(wlanngcmd) != 0) 50 if (system(wlanngcmd) != 0)
@@ -70,3 +69,3 @@ int card_set_promisc_up (const char *device)
70 69
71 snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); 70 snprintf(ifconfigcmd, sizeof(ifconfigcmd) - 1, SBIN_PATH, device);
72 retval = system(ifconfigcmd); 71 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 @@
12#include <netinet/in.h> 12#include <netinet/in.h>
13
14extern "C"
15{
16#include <net/bpf.h> 13#include <net/bpf.h>
17#include <pcap.h> 14#include <pcap.h>
18}
19 15
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 @@
1/*
2 * Communication protocol
3 *
4 * $Id$
5 */
6
7#include "proto.hh"
8#include "sock.hh"
9#include "log.hh"
10
11/* Send found network to GUI */
12int send_network_found (const char *guihost, int guiport, void *structure)
13{
14 wl_network_t *ptr;
15 char buffer[2048];
16 char temp[5];
17
18 ptr = (wl_network_t *)structure;
19
20 memset(buffer, 0, 2048);
21
22 /* Type = Found new net */
23 memcpy(buffer, "01", 2);
24
25 /* Set Net-type */
26 memset(temp, 0, sizeof(temp));
27 snprintf(temp, 2, "%d", ptr->net_type);
28 memcpy(buffer + 2, temp, 1);
29
30 /* Set channel */
31 memset(temp, 0, sizeof(temp));
32
33 if(ptr->channel < 10)
34 snprintf(temp, 3, "0%d", ptr->channel);
35 else
36 snprintf(temp, 3, "%d", ptr->channel);
37
38 memcpy(buffer + 3, temp, 2);
39
40 /* Set WEP y/n */
41 memset(temp, 0, sizeof(temp));
42 snprintf(temp, 2, "%d", ptr->wep);
43 memcpy(buffer + 5, temp, 1);
44
45 /* Set MAC address */
46 memcpy(buffer + 6, ptr->mac, 17);
47
48 /* Set lenght of ssid */
49 memset(temp, 0, sizeof(temp));
50
51 if(ptr->ssid_len > 99)
52 snprintf(temp, 4, "%d", ptr->ssid_len);
53 else if(ptr->ssid_len < 10)
54 snprintf(temp, 4, "00%d", ptr->ssid_len);
55 else
56 snprintf(temp, 4, "0%d", ptr->ssid_len);
57
58 memcpy(buffer + 23, temp, 3);
59
60 /* Set ssid */
61 memcpy(buffer + 26, ptr->bssid, ptr->ssid_len);
62
63 /* Send prepared buffer to GUI */
64#ifdef DEBUG
65 wl_loginfo("Sending network to GUI: '%s'", buffer);
66#endif
67
68 sendcomm(guihost, guiport, buffer);
69
70 return 1;
71}
72
73/* Fill buffer into structur */
74int get_network_found (void *structure, const char *buffer)
75{
76 wl_network_t *ptr;
77 char temp[512];
78
79 ptr = (wl_network_t *)structure;
80
81 /* Get net type */
82 memset(temp, 0, sizeof(temp));
83 memcpy(temp, buffer + 2, 1);
84 ptr->net_type = atoi(temp);
85
86 /* Get channel */
87 memset(temp, 0, sizeof(temp));
88 memcpy(temp, buffer + 3, 2);
89 ptr->channel = atoi(temp);
90
91 /* Set WEP y/n */
92 memset(temp, 0, sizeof(temp));
93 memcpy(temp, buffer + 5, 1);
94 ptr->wep = atoi(temp);
95
96 /* Set MAC address */
97 memcpy(ptr->mac, buffer + 6, 17);
98 ptr->mac[17]='\0';
99
100 /* Set lenght of ssid */
101 memset(temp, 0, sizeof(temp));
102 memcpy(temp, buffer + 23, 3);
103 ptr->ssid_len = atoi(temp);
104
105 /* Set ssid */
106 memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1);
107
108 return 1;
109}
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 @@
9#include "extract.hh" 9#include "extract.hh"
10#include "log.hh" 10#include "wl_log.hh"
11#include "proto.hh" 11#include "wl_proto.hh"
12 12
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 @@
14#include <arpa/inet.h> 14#include <arpa/inet.h>
15
16extern "C"
17{
18#include <net/bpf.h> 15#include <net/bpf.h>
19#include <pcap.h> 16#include <pcap.h>
20}
21 17
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 @@
6 6
7#include "log.hh" 7#include "wl_log.hh"
8 8
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 @@
1/*
2 * Communication protocol
3 *
4 * $Id$
5 */
6
7#include "wl_proto.hh"
8#include "wl_log.hh"
9#include "wl_sock.hh"
10
11/* Adds a field to the buffer */
12int add_field(char *buffer, char *string, int len)
13{
14 char newlen[5];
15
16 /* 3 Byte = Length */
17 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len);
18 memcpy(buffer, newlen, 3);
19
20 /* Length bytes = Value */
21 memcpy(buffer + 3, string, atoi(newlen));
22
23 /* Return length of attached field */
24 return (atoi(newlen) + 3);
25}
26
27int get_field(const char *buffer, char *out)
28{
29 char len[5];
30
31 /* Get length of value */
32 memcpy(len, buffer, 3);
33
34 /* Copy buffer to out pointer */
35 memset(out, 0, atoi(len) + 1);
36 memcpy(out, buffer + 3, atoi(len));
37
38 return atoi(len) + 3;
39}
40
41/* Send found network to GUI */
42int send_network_found (const char *guihost, int guiport, void *structure)
43{
44 wl_network_t *ptr;
45 char buffer[2048];
46 char temp[128];
47 int retval=0, len=0;
48
49 memset(temp, 0, sizeof(temp));
50
51 ptr = (wl_network_t *)structure;
52
53 /* Type = Found new net (without length field) */
54 memset(temp, 0, sizeof(temp));
55 snprintf(temp, sizeof(temp), "%.2d", NETFOUND);
56 memcpy(buffer, temp, 2);
57 len += 2;
58
59 /* Set Net-type */
60 memset(temp, 0, sizeof(temp));
61 snprintf(temp, sizeof(temp), "%d", ptr->net_type);
62 retval = add_field(buffer + len, temp, 1);
63 len += retval;
64
65 /* Set channel */
66 memset(temp, 0, sizeof(temp));
67 snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
68 retval = add_field(buffer + len, temp, 2);
69 len += retval;
70
71 /* Set WEP y/n */
72 memset(temp, 0, sizeof(temp));
73 snprintf(temp, sizeof(temp), "%d", ptr->wep);
74 retval = add_field(buffer + len, temp, 1);
75 len += retval;
76
77 /* Set Mac */
78 retval = add_field(buffer + len, (char *)ptr->mac, 17);
79 len += retval;
80
81 /* Set ssid */
82 retval = add_field(buffer + len, (char *)ptr->bssid, ptr->ssid_len);
83
84 /* Send prepared buffer to GUI */
85#ifdef DEBUG
86 wl_loginfo("Sending network to GUI: '%s'", buffer);
87#endif
88
89 wl_send(guihost, guiport, buffer);
90
91 return 1;
92}
93
94/* Fill buffer into structur */
95int get_network_found (void *structure, const char *buffer)
96{
97 wl_network_t *ptr;
98 char temp[512];
99 int retval=0, len=0;
100
101 ptr = (wl_network_t *)structure;
102
103 /* packet type already determined */
104 len += 2;
105
106 /* Get net type */
107 memset(temp, 0, sizeof(temp));
108 retval = get_field(buffer + len, temp);
109 len += retval;
110 ptr->net_type = atoi(temp);
111
112 /* Get channel */
113 memset(temp, 0, sizeof(temp));
114 retval = get_field(buffer + len, temp);
115 len += retval;
116 ptr->channel = atoi(temp);
117
118 /* Set WEP y/n */
119 memset(temp, 0, sizeof(temp));
120 retval = get_field(buffer + len, temp);
121 len += retval;
122 ptr->wep = atoi(temp);
123
124 /* Set MAC address */
125 retval = get_field(buffer + len, ptr->mac);
126 len += retval;
127
128 /* Set BSSID */
129 retval = get_field(buffer + len, ptr->bssid);
130
131 return 1;
132}
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 @@
2 2
3#ifndef PROTO_HH 3#ifndef WLPROTO_HH
4#define PROTO_HH 4#define WLPROTO_HH
5 5
@@ -27,2 +27,2 @@ typedef struct {
27 27
28#endif /* PROTO_HH */ 28#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 @@
6 6
7#include "sock.hh" 7#include "wl_sock.hh"
8#include "log.hh" 8#include "wl_log.hh"
9 9
10/* Setup UDP Socket for incoming commands */ 10/* Setup UDP Socket for incoming commands */
11int commsock(const char *host, int port) 11int wl_setupsock(const char *host, int port)
12{ 12{
@@ -37,3 +37,3 @@ int commsock(const char *host, int port)
37/* Send a string to commsock */ 37/* Send a string to commsock */
38int sendcomm(const char *host, int port, const char *string, ...) 38int wl_send(const char *host, int port, const char *string, ...)
39{ 39{
@@ -65,3 +65,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
65 close(sock); 65 close(sock);
66 return 0; 66 return -1;
67 } 67 }
@@ -71,3 +71,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
71 71
72 return 1; 72 return 0;
73} 73}
@@ -75,3 +75,3 @@ int sendcomm(const char *host, int port, const char *string, ...)
75/* Check for new messages on commsock */ 75/* Check for new messages on commsock */
76int recvcomm(int *sock, char *out, int maxlen) 76int wl_recv(int *sock, char *out, int maxlen)
77{ 77{
@@ -79,11 +79,9 @@ int recvcomm(int *sock, char *out, int maxlen)
79 socklen_t len=sizeof(struct sockaddr); 79 socklen_t len=sizeof(struct sockaddr);
80 char buffer[128], retval[3]; 80 char retval[3];
81
82 memset(buffer, 0, sizeof(buffer));
83 if(recvfrom(*sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0)
84 return -1;
85 81
86 memset(out, 0, maxlen); 82 memset(out, 0, maxlen);
87 memcpy(out, buffer, maxlen - 1); 83 if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0)
84 return -1;
88 85
86 /* Get packet type and return it */
89 memset(retval, 0, sizeof(retval)); 87 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 @@
15 15
16int commsock(const char *, int); 16int wl_setupsock(const char *, int);
17int sendcomm(const char *, int, const char *, ...); 17int wl_send(const char *, int, const char *, ...);
18int recvcomm(int *, char *, int); 18int wl_recv(int *, char *, int);
19 19