summaryrefslogtreecommitdiff
authormjm <mjm>2003-01-05 11:18:27 (UTC)
committer mjm <mjm>2003-01-05 11:18:27 (UTC)
commit3eecce3109b543a5abd6a36a420fa3f53cc23023 (patch) (unidiff)
tree5e92d6ec8a4ebc58822bed5de48706ed51a7ebd0
parent4f45c61a4e778a8124ae362dd5339b329b171441 (diff)
downloadopie-3eecce3109b543a5abd6a36a420fa3f53cc23023.zip
opie-3eecce3109b543a5abd6a36a420fa3f53cc23023.tar.gz
opie-3eecce3109b543a5abd6a36a420fa3f53cc23023.tar.bz2
general code cleanup, wrote configfileparser, ...
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/Makefile2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_conf.cc81
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_conf.hh12
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc5
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh6
5 files changed, 104 insertions, 2 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/Makefile b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
index 51b5ff3..6663c8a 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/Makefile
+++ b/noncore/net/wellenreiter/libwellenreiter/source/Makefile
@@ -1,17 +1,17 @@
1# $Id$ 1# $Id$
2 2
3OBJ = wl_proto.o wl_sock.o wl_log.o cardmode.o sniff.o 3OBJ = wl_proto.o wl_sock.o wl_log.o wl_conf.o cardmode.o sniff.o
4CPP = g++ 4CPP = g++
5CPPFLAGS = -Wall -pedantic -g -DDEBUG 5CPPFLAGS = -Wall -pedantic -g -DDEBUG
6 6
7 static:libwellenreiter.a 7 static:libwellenreiter.a
8libwellenreiter.a: $(OBJ) 8libwellenreiter.a: $(OBJ)
9 ar -cr libwellenreiter.a $(OBJ) 9 ar -cr libwellenreiter.a $(OBJ)
10 10
11 shared:libwellenreiter.so 11 shared:libwellenreiter.so
12libwellenreiter.so: $(OBJ) 12libwellenreiter.so: $(OBJ)
13 $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ) 13 $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ)
14 14
15clean: 15clean:
16 rm -f *.o *.a *.so *~ 16 rm -f *.o *.a *.so *~
17 17
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.cc
new file mode 100644
index 0000000..ba56754
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.cc
@@ -0,0 +1,81 @@
1/*
2 * Configfile operations for wellenreiter
3 *
4 * $Id$
5 */
6
7#include "wl_conf.hh"
8#include "wl_log.hh"
9#include "wl_types.hh"
10
11/* Check whether configfile exists and is readable */
12int wl_checkcfg(void)
13{
14 FILE *wl_config;
15
16 if((wl_config = fopen(WL_CONFFILE, "r")) == NULL)
17 {
18 wl_logerr("Cannot open configfile: %s", strerror(errno));
19 return 0;
20 }
21 else
22 {
23 fclose(wl_config);
24 return 1;
25 }
26
27}
28
29/* Get value for given token from config file */
30int wl_cfgvalue(const char *token, char *out, int maxlen)
31{
32 FILE *wl_config;
33 char *ptr, *ptr2;
34 char confbuf[WL_CONFBUFF];
35
36 if(token == NULL)
37 return -1;
38
39 if((wl_config = fopen(WL_CONFFILE, "r")) == NULL)
40 {
41 wl_logerr("Cannot open configfile: %s", strerror(errno));
42 return -1;
43 }
44
45 /* Clear buffers */
46 memset(out, 0, maxlen);
47 memset(confbuf, 0, sizeof(confbuf));
48
49 while((fgets(confbuf, sizeof(confbuf) - 1, wl_config)) != NULL)
50 {
51
52 /* Ignore comments */
53 if(confbuf[0] == '#') continue;
54
55 /* Search for token, if found check whether next character
56 * is a '=' or a ' '
57 */
58 if(strstr(confbuf, token) != NULL &&
59 (confbuf[strlen(token)] == '=' || confbuf[strlen(token)] == ' '))
60 {
61
62 /* Get value between quotes */
63 if((ptr = strstr(confbuf, "\"")) == NULL)
64 break;
65 ++ptr;
66 if((ptr2 = strstr(ptr, "\"")) == NULL)
67 break;
68 ptr2[0] = '\0';
69
70 memcpy(out, ptr, maxlen - 1);
71 break;
72
73 }
74 memset(confbuf, 0, sizeof(confbuf));
75 }
76
77 fclose(wl_config);
78
79 return (out[0] == '\0' ? 0 : 1);
80}
81
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.hh
new file mode 100644
index 0000000..4061440
--- a/dev/null
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_conf.hh
@@ -0,0 +1,12 @@
1/* $Id$ */
2
3#ifndef WLCONF_HH
4#define WLCONF_HH
5
6#include <string.h>
7#include <errno.h>
8
9int wl_checkcfg(void);
10int wl_cfgvalue(const char *, char *, int);
11
12#endif /* WLCONF_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
index 664ba92..67dfc02 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -1,79 +1,82 @@
1/* 1/*
2 * Communication protocol 2 * Communication protocol
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "wl_types.hh" 7#include "wl_types.hh"
8#include "wl_proto.hh" 8#include "wl_proto.hh"
9#include "wl_log.hh" 9#include "wl_log.hh"
10#include "wl_sock.hh" 10#include "wl_sock.hh"
11 11
12/* Adds a field to the buffer */ 12/* Adds a field to the buffer */
13int add_field(char *buffer, const char *string, int len) 13int add_field(char *buffer, const char *string, int len)
14{ 14{
15 char newlen[5]; 15 char newlen[5];
16 16
17 /* 3 Byte = Length */ 17 /* 3 Byte = Length */
18 memset(newlen, 0, sizeof(newlen));
18 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); 19 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len);
19 memcpy(buffer, newlen, 3); 20 memcpy(buffer, newlen, 3);
20 21
21 /* Length bytes = Value */ 22 /* Length bytes = Value */
22 memcpy(buffer + 3, string, atoi(newlen)); 23 memcpy(buffer + 3, string, atoi(newlen));
23 24
24 /* Return length of attached field */ 25 /* Return length of attached field */
25 return (atoi(newlen) + 3); 26 return (atoi(newlen) + 3);
26} 27}
27 28
28int get_field(const char *buffer, char *out, int maxlen) 29int get_field(const char *buffer, char *out, int maxlen)
29{ 30{
30 char len[5]; 31 char len[5];
31 32
32 /* Get length of value */ 33 /* Get length of value */
34 memset(len, 0, sizeof(len));
33 memcpy(len, buffer, 3); 35 memcpy(len, buffer, 3);
34 36
35 /* Copy buffer to out pointer */ 37 /* Copy buffer to out pointer */
36 memset(out, 0, maxlen); 38 memset(out, 0, maxlen);
37
38 if(atoi(len) > maxlen -1) 39 if(atoi(len) > maxlen -1)
39 memcpy(out, buffer + 3, maxlen - 1); 40 memcpy(out, buffer + 3, maxlen - 1);
40 else 41 else
41 memcpy(out, buffer + 3, atoi(len)); 42 memcpy(out, buffer + 3, atoi(len));
42 43
43 /* Return length of whole field (including 3 byte length) */ 44 /* Return length of whole field (including 3 byte length) */
44 return (atoi(len) + 3); 45 return (atoi(len) + 3);
45} 46}
46 47
47/* Send found network to UI */ 48/* Send found network to UI */
48int send_network_found (const char *guihost, int guiport, void *structure) 49int send_network_found (const char *guihost, int guiport, void *structure)
49{ 50{
50 wl_network_t *ptr; 51 wl_network_t *ptr;
51 char buffer[2048], temp[5]; 52 char buffer[2048], temp[5];
52 unsigned int len = 0; 53 unsigned int len = 0;
53 54
54 ptr = (wl_network_t *)structure; 55 ptr = (wl_network_t *)structure;
55 56
57 memcpy(buffer, 0, sizeof(buffer));
58
56 /* Type = Found new net (without length field) */ 59 /* Type = Found new net (without length field) */
57 memset(temp, 0, sizeof(temp)); 60 memset(temp, 0, sizeof(temp));
58 snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); 61 snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND);
59 memcpy(buffer, temp, 2); 62 memcpy(buffer, temp, 2);
60 len += 2; 63 len += 2;
61 64
62 /* Set Net-type */ 65 /* Set Net-type */
63 memset(temp, 0, sizeof(temp)); 66 memset(temp, 0, sizeof(temp));
64 snprintf(temp, sizeof(temp), "%d", ptr->net_type); 67 snprintf(temp, sizeof(temp), "%d", ptr->net_type);
65 len += add_field(buffer + len, temp, 1); 68 len += add_field(buffer + len, temp, 1);
66 69
67 /* Set channel */ 70 /* Set channel */
68 memset(temp, 0, sizeof(temp)); 71 memset(temp, 0, sizeof(temp));
69 snprintf(temp, sizeof(temp), "%.2d", ptr->channel); 72 snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
70 len += add_field(buffer + len, temp, 2); 73 len += add_field(buffer + len, temp, 2);
71 74
72 /* Set WEP y/n */ 75 /* Set WEP y/n */
73 memset(temp, 0, sizeof(temp)); 76 memset(temp, 0, sizeof(temp));
74 snprintf(temp, sizeof(temp), "%d", ptr->wep); 77 snprintf(temp, sizeof(temp), "%d", ptr->wep);
75 len += add_field(buffer + len, temp, 1); 78 len += add_field(buffer + len, temp, 1);
76 79
77 /* Set Mac */ 80 /* Set Mac */
78 len += add_field(buffer + len, ptr->mac, 17); 81 len += add_field(buffer + len, ptr->mac, 17);
79 82
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh
index a5ca281..f12d65e 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_types.hh
@@ -1,31 +1,37 @@
1/* 1/*
2 * Global bufffer size and type definitions 2 * Global bufffer size and type definitions
3 * 3 *
4 * $Id$ 4 * $Id$
5 * 5 *
6 */ 6 */
7 7
8#ifndef WL_TYPES_HH 8#ifndef WL_TYPES_HH
9#define WL_TYPES_HH 9#define WL_TYPES_HH
10 10
11/* Type definitions, to be continued */ 11/* Type definitions, to be continued */
12#define WL_NETFOUND 01 12#define WL_NETFOUND 01
13#define WL_NETLOST 02 13#define WL_NETLOST 02
14#define WL_STARTSNIFF 98 14#define WL_STARTSNIFF 98
15#define WL_STOPSNIFF 99 15#define WL_STOPSNIFF 99
16 16
17/* Socket specific */
17#define WL_SOCKBUF 512 /* Buffer for wl_send and wl_recv calls */ 18#define WL_SOCKBUF 512 /* Buffer for wl_send and wl_recv calls */
18 19
20/* Protocol specific */
19 21
20/* WL network structure */ 22/* WL network structure */
21typedef struct { 23typedef struct {
22 int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ 24 int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */
23 int ssid_len; /* Length of SSID */ 25 int ssid_len; /* Length of SSID */
24 int channel; /* Channel */ 26 int channel; /* Channel */
25 int wep; /* 1 = WEP enabled ; 0 = disabled */ 27 int wep; /* 1 = WEP enabled ; 0 = disabled */
26 char mac[64]; /* MAC address of Accesspoint */ 28 char mac[64]; /* MAC address of Accesspoint */
27 char bssid[128]; /* BSSID of Net */ 29 char bssid[128]; /* BSSID of Net */
28} wl_network_t; 30} wl_network_t;
29 31
32/* Config specific */
33#define WL_CONFFILE "sample.conf"
34#define WL_CONFBUFF 128
35
30#endif /* WL_TYPES_HH */ 36#endif /* WL_TYPES_HH */
31 37