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 @@ # $Id$ -OBJ = wl_proto.o wl_sock.o wl_log.o cardmode.o sniff.o +OBJ = wl_proto.o wl_sock.o wl_log.o wl_conf.o cardmode.o sniff.o CPP = g++ CPPFLAGS = -Wall -pedantic -g -DDEBUG static: libwellenreiter.a libwellenreiter.a: $(OBJ) ar -cr libwellenreiter.a $(OBJ) shared: libwellenreiter.so libwellenreiter.so: $(OBJ) $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ) clean: rm -f *.o *.a *.so *~ 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 @@ +/* + * Configfile operations for wellenreiter + * + * $Id$ + */ + +#include "wl_conf.hh" +#include "wl_log.hh" +#include "wl_types.hh" + +/* Check whether configfile exists and is readable */ +int wl_checkcfg(void) +{ + FILE *wl_config; + + if((wl_config = fopen(WL_CONFFILE, "r")) == NULL) + { + wl_logerr("Cannot open configfile: %s", strerror(errno)); + return 0; + } + else + { + fclose(wl_config); + return 1; + } + +} + +/* Get value for given token from config file */ +int wl_cfgvalue(const char *token, char *out, int maxlen) +{ + FILE *wl_config; + char *ptr, *ptr2; + char confbuf[WL_CONFBUFF]; + + if(token == NULL) + return -1; + + if((wl_config = fopen(WL_CONFFILE, "r")) == NULL) + { + wl_logerr("Cannot open configfile: %s", strerror(errno)); + return -1; + } + + /* Clear buffers */ + memset(out, 0, maxlen); + memset(confbuf, 0, sizeof(confbuf)); + + while((fgets(confbuf, sizeof(confbuf) - 1, wl_config)) != NULL) + { + + /* Ignore comments */ + if(confbuf[0] == '#') continue; + + /* Search for token, if found check whether next character + * is a '=' or a ' ' + */ + if(strstr(confbuf, token) != NULL && + (confbuf[strlen(token)] == '=' || confbuf[strlen(token)] == ' ')) + { + + /* Get value between quotes */ + if((ptr = strstr(confbuf, "\"")) == NULL) + break; + ++ptr; + if((ptr2 = strstr(ptr, "\"")) == NULL) + break; + ptr2[0] = '\0'; + + memcpy(out, ptr, maxlen - 1); + break; + + } + memset(confbuf, 0, sizeof(confbuf)); + } + + fclose(wl_config); + + return (out[0] == '\0' ? 0 : 1); +} + 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 @@ +/* $Id$ */ + +#ifndef WLCONF_HH +#define WLCONF_HH + +#include <string.h> +#include <errno.h> + +int wl_checkcfg(void); +int wl_cfgvalue(const char *, char *, int); + +#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 @@ /* * Communication protocol * * $Id$ */ #include "wl_types.hh" #include "wl_proto.hh" #include "wl_log.hh" #include "wl_sock.hh" /* Adds a field to the buffer */ int add_field(char *buffer, const char *string, int len) { char newlen[5]; /* 3 Byte = Length */ + memset(newlen, 0, sizeof(newlen)); 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, int maxlen) { char len[5]; /* Get length of value */ + memset(len, 0, sizeof(len)); memcpy(len, buffer, 3); /* Copy buffer to out pointer */ memset(out, 0, maxlen); - if(atoi(len) > maxlen -1) memcpy(out, buffer + 3, maxlen - 1); else memcpy(out, buffer + 3, atoi(len)); /* Return length of whole field (including 3 byte length) */ return (atoi(len) + 3); } /* Send found network to UI */ int send_network_found (const char *guihost, int guiport, void *structure) { wl_network_t *ptr; char buffer[2048], temp[5]; unsigned int len = 0; ptr = (wl_network_t *)structure; + memcpy(buffer, 0, sizeof(buffer)); + /* Type = Found new net (without length field) */ memset(temp, 0, sizeof(temp)); snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); memcpy(buffer, temp, 2); len += 2; /* Set Net-type */ memset(temp, 0, sizeof(temp)); snprintf(temp, sizeof(temp), "%d", ptr->net_type); len += add_field(buffer + len, temp, 1); /* Set channel */ memset(temp, 0, sizeof(temp)); snprintf(temp, sizeof(temp), "%.2d", ptr->channel); len += add_field(buffer + len, temp, 2); /* Set WEP y/n */ memset(temp, 0, sizeof(temp)); snprintf(temp, sizeof(temp), "%d", ptr->wep); len += add_field(buffer + len, temp, 1); /* Set Mac */ len += add_field(buffer + len, ptr->mac, 17); 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 @@ /* * Global bufffer size and type definitions * * $Id$ * */ #ifndef WL_TYPES_HH #define WL_TYPES_HH /* Type definitions, to be continued */ #define WL_NETFOUND 01 #define WL_NETLOST 02 #define WL_STARTSNIFF 98 #define WL_STOPSNIFF 99 +/* Socket specific */ #define WL_SOCKBUF 512 /* Buffer for wl_send and wl_recv calls */ +/* Protocol specific */ /* WL network structure */ typedef struct { int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ int ssid_len; /* Length of SSID */ int channel; /* Channel */ int wep; /* 1 = WEP enabled ; 0 = disabled */ char mac[64]; /* MAC address of Accesspoint */ char bssid[128]; /* BSSID of Net */ } wl_network_t; +/* Config specific */ +#define WL_CONFFILE "sample.conf" +#define WL_CONFBUFF 128 + #endif /* WL_TYPES_HH */ |