5 files changed, 45 insertions, 41 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index e516177..6e512c4 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc @@ -7,12 +7,16 @@ #include "sniff.hh" #include "ieee802_11.hh" #include "extract.hh" #include "wl_log.hh" +#include "wl_types.hh" #include "wl_proto.hh" /* Main function, checks packets */ -void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) +void process_packets(const struct pcap_pkthdr *pkthdr, + const unsigned char *packet, + char *guihost, + int guiport) { unsigned int caplen = pkthdr->caplen; unsigned int length = pkthdr->len; u_int16_t fc; @@ -94,27 +98,26 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack return; } /* Here should be the infos to the gui issued */ - if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) - { - wl_loginfo("Found an access point"); - wl_net.net_type=1; - } + if (pinfoptr->cap_ESS == 1 && pinfoptr->cap_IBSS ==0) + { + wl_loginfo("Found an access point"); + wl_net.net_type=1; + } else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) - { - wl_loginfo("Found an ad-hoc network"); - wl_net.net_type=2; - } - - memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); + { + wl_loginfo("Found an ad-hoc network"); + wl_net.net_type=2; + } if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) wl_loginfo("Net is a non-broadcasting network"); else wl_loginfo("SSID is: %s", pinfoptr->ssid); wl_loginfo("SSID is: %s", pinfoptr->ssid); + memset(wl_net.bssid, 0, sizeof(wl_net.bssid)); memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); wl_net.ssid_len=pinfoptr->ssid_len; @@ -236,9 +239,10 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) case E_SSID: memcpy(&(pbody.ssid),p+offset,2); offset += 2; if (pbody.ssid.length > 0) { - memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; + memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); + offset += pbody.ssid.length; pbody.ssid.ssid[pbody.ssid.length]='\0'; if (strcmp((char *)pbody.ssid.ssid,"")==0) memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); else @@ -250,29 +254,35 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) case E_CHALLENGE: memcpy(&(pbody.challenge),p+offset,2); offset += 2; if (pbody.challenge.length > 0) { - memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; + memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); + offset += pbody.challenge.length; pbody.challenge.text[pbody.challenge.length]='\0'; } break; case E_RATES: memcpy(&(pbody.rates),p+offset,2); offset += 2; if (pbody.rates.length > 0) { - memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; + memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); + offset += pbody.rates.length; } break; case E_DS: - memcpy(&(pbody.ds),p+offset,3); offset +=3; + memcpy(&(pbody.ds),p+offset,3); + offset +=3; ppinfo->channel = pbody.ds.channel; break; case E_CF: - memcpy(&(pbody.cf),p+offset,8); offset +=8; + memcpy(&(pbody.cf),p+offset,8); + offset +=8; break; case E_TIM: - memcpy(&(pbody.tim),p+offset,2); offset +=2; - memcpy(&(pbody.tim.count),p+offset,3); offset +=3; + memcpy(&(pbody.tim),p+offset,2); + offset +=2; + memcpy(&(pbody.tim.count),p+offset,3); + offset +=3; if ((pbody.tim.length -3) > 0) { memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); offset += pbody.tim.length -3; diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc index 0630d04..664ba92 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc @@ -3,8 +3,9 @@ * * $Id$ */ +#include "wl_types.hh" #include "wl_proto.hh" #include "wl_log.hh" #include "wl_sock.hh" @@ -33,9 +34,9 @@ int get_field(const char *buffer, char *out, int maxlen) /* Copy buffer to out pointer */ memset(out, 0, maxlen); - if(atoi(len)-3 > maxlen -1) + if(atoi(len) > maxlen -1) memcpy(out, buffer + 3, maxlen - 1); else memcpy(out, buffer + 3, atoi(len)); @@ -53,9 +54,9 @@ int send_network_found (const char *guihost, int guiport, void *structure) ptr = (wl_network_t *)structure; /* Type = Found new net (without length field) */ memset(temp, 0, sizeof(temp)); - snprintf(temp, sizeof(temp), "%.2d", NETFOUND); + snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); memcpy(buffer, temp, 2); len += 2; /* Set Net-type */ @@ -97,9 +98,9 @@ int get_network_found (void *structure, const char *buffer) char temp[5]; unsigned int len = 0; ptr = (wl_network_t *)structure; - + /* packet type already determined, skip check */ len += 2; /* Get net type (accesspoint || ad-hoc || ...) */ diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh index f645f58..46ef8e5 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh @@ -17,14 +17,5 @@ int add_field(char *, const char *, int); int get_field(const char *, char *, int); int send_network_found (const char *, int, void *); int get_network_found (void *, const char *); -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; - #endif /* WLPROTO_HH */ diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc index db6b7b8..6e26cb8 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc @@ -7,11 +7,10 @@ #include "wl_sock.hh" #include "wl_log.hh" /* Setup UDP Socket for incoming commands */ -int wl_setupsock(const char *host, int port) +int wl_setupsock(const char *host, int port, struct sockaddr_in saddr) { - struct sockaddr_in saddr; int sock; if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { @@ -22,9 +21,9 @@ int wl_setupsock(const char *host, int port) memset(&saddr, 0, sizeof(saddr)); saddr.sin_family = PF_INET; saddr.sin_port = htons(port); saddr.sin_addr.s_addr = inet_addr(host); - + if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) { wl_logerr("Cannot bind socket: %s", strerror(errno)); close(sock); @@ -72,17 +71,19 @@ int wl_send(const char *host, int port, const char *string, ...) return 1; } /* Check for new messages on commsock */ -int wl_recv(int *sock, char *out, int maxlen) +int wl_recv(int *sock, struct sockaddr_in cliaddr, char *out, int maxlen) { - struct sockaddr_in *cliaddr; socklen_t len = sizeof(struct sockaddr); char retval[3]; - + memset(out, 0, maxlen); - if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0) + if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)&cliaddr, &len) < 0) + { + wl_logerr("Cannot receive from socket: %s", strerror(errno)); return -1; + } /* Get packet type and return it */ memset(retval, 0, sizeof(retval)); memcpy(retval, out, 2); diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh index 6ddbaef..e7d9747 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh @@ -1,9 +1,10 @@ -/* $id */ +/* $Id */ #ifndef WLSOCK_HH #define WLSOCK_HH +#include <stdarg.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> @@ -12,9 +13,9 @@ #include <unistd.h> #include <stdlib.h> #include <errno.h> -int wl_setupsock(const char *, int); +int wl_setupsock(const char *, int, struct sockaddr_in); int wl_send(const char *, int, const char *, ...); -int wl_recv(int *, char *, int); +int wl_recv(int *, struct sockaddr_in, char *, int); #endif /* WLSOCK_HH */ |