summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-31 12:36:06 (UTC)
committer mjm <mjm>2002-12-31 12:36:06 (UTC)
commitd331ca1cf11e8f525665a1e5cb10f491d47c19e8 (patch) (unidiff)
tree42e46b280ac5b9ce5762f0df3a09189c4912d560
parente34eef8e2f2a36797ef980d505a99948f88a5df2 (diff)
downloadopie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.zip
opie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.tar.gz
opie-d331ca1cf11e8f525665a1e5cb10f491d47c19e8.tar.bz2
wl_recv was more or less broken because of missing socket structure, fixed.
general cleanup. GUI has to be updated in functions wl_setupsock and wl_recv
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/sniff.cc48
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc7
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh9
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc15
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh7
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 @@
7#include "sniff.hh" 7#include "sniff.hh"
8#include "ieee802_11.hh" 8#include "ieee802_11.hh"
9#include "extract.hh" 9#include "extract.hh"
10#include "wl_log.hh" 10#include "wl_log.hh"
11#include "wl_types.hh"
11#include "wl_proto.hh" 12#include "wl_proto.hh"
12 13
13/* Main function, checks packets */ 14/* Main function, checks packets */
14void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) 15void process_packets(const struct pcap_pkthdr *pkthdr,
16 const unsigned char *packet,
17 char *guihost,
18 int guiport)
15{ 19{
16 unsigned int caplen = pkthdr->caplen; 20 unsigned int caplen = pkthdr->caplen;
17 unsigned int length = pkthdr->len; 21 unsigned int length = pkthdr->len;
18 u_int16_t fc; 22 u_int16_t fc;
@@ -94,27 +98,26 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack
94 return; 98 return;
95 } 99 }
96 100
97 /* Here should be the infos to the gui issued */ 101 /* Here should be the infos to the gui issued */
98 if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) 102 if (pinfoptr->cap_ESS == 1 && pinfoptr->cap_IBSS ==0)
99 { 103 {
100 wl_loginfo("Found an access point"); 104 wl_loginfo("Found an access point");
101 wl_net.net_type=1; 105 wl_net.net_type=1;
102 } 106 }
103 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) 107 else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2)
104 { 108 {
105 wl_loginfo("Found an ad-hoc network"); 109 wl_loginfo("Found an ad-hoc network");
106 wl_net.net_type=2; 110 wl_net.net_type=2;
107 } 111 }
108
109 memset(wl_net.bssid, 0, sizeof(wl_net.bssid));
110 112
111 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) 113 if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0)
112 wl_loginfo("Net is a non-broadcasting network"); 114 wl_loginfo("Net is a non-broadcasting network");
113 else 115 else
114 wl_loginfo("SSID is: %s", pinfoptr->ssid); 116 wl_loginfo("SSID is: %s", pinfoptr->ssid);
115 117
116 wl_loginfo("SSID is: %s", pinfoptr->ssid); 118 wl_loginfo("SSID is: %s", pinfoptr->ssid);
119 memset(wl_net.bssid, 0, sizeof(wl_net.bssid));
117 memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); 120 memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1);
118 121
119 wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); 122 wl_loginfo("SSID length is: %d", pinfoptr->ssid_len);
120 wl_net.ssid_len=pinfoptr->ssid_len; 123 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)
236 case E_SSID: 239 case E_SSID:
237 memcpy(&(pbody.ssid),p+offset,2); offset += 2; 240 memcpy(&(pbody.ssid),p+offset,2); offset += 2;
238 if (pbody.ssid.length > 0) 241 if (pbody.ssid.length > 0)
239 { 242 {
240 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; 243 memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length);
244 offset += pbody.ssid.length;
241 pbody.ssid.ssid[pbody.ssid.length]='\0'; 245 pbody.ssid.ssid[pbody.ssid.length]='\0';
242 if (strcmp((char *)pbody.ssid.ssid,"")==0) 246 if (strcmp((char *)pbody.ssid.ssid,"")==0)
243 memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); 247 memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid));
244 else 248 else
@@ -250,29 +254,35 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo)
250 case E_CHALLENGE: 254 case E_CHALLENGE:
251 memcpy(&(pbody.challenge),p+offset,2); offset += 2; 255 memcpy(&(pbody.challenge),p+offset,2); offset += 2;
252 if (pbody.challenge.length > 0) 256 if (pbody.challenge.length > 0)
253 { 257 {
254 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; 258 memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length);
259 offset += pbody.challenge.length;
255 pbody.challenge.text[pbody.challenge.length]='\0'; 260 pbody.challenge.text[pbody.challenge.length]='\0';
256 } 261 }
257 break; 262 break;
258 case E_RATES: 263 case E_RATES:
259 memcpy(&(pbody.rates),p+offset,2); offset += 2; 264 memcpy(&(pbody.rates),p+offset,2); offset += 2;
260 if (pbody.rates.length > 0) 265 if (pbody.rates.length > 0)
261 { 266 {
262 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; 267 memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length);
268 offset += pbody.rates.length;
263 } 269 }
264 break; 270 break;
265 case E_DS: 271 case E_DS:
266 memcpy(&(pbody.ds),p+offset,3); offset +=3; 272 memcpy(&(pbody.ds),p+offset,3);
273 offset +=3;
267 ppinfo->channel = pbody.ds.channel; 274 ppinfo->channel = pbody.ds.channel;
268 break; 275 break;
269 case E_CF: 276 case E_CF:
270 memcpy(&(pbody.cf),p+offset,8); offset +=8; 277 memcpy(&(pbody.cf),p+offset,8);
278 offset +=8;
271 break; 279 break;
272 case E_TIM: 280 case E_TIM:
273 memcpy(&(pbody.tim),p+offset,2); offset +=2; 281 memcpy(&(pbody.tim),p+offset,2);
274 memcpy(&(pbody.tim.count),p+offset,3); offset +=3; 282 offset +=2;
283 memcpy(&(pbody.tim.count),p+offset,3);
284 offset +=3;
275 if ((pbody.tim.length -3) > 0) 285 if ((pbody.tim.length -3) > 0)
276 { 286 {
277 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); 287 memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3));
278 offset += pbody.tim.length -3; 288 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 @@
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "wl_types.hh"
7#include "wl_proto.hh" 8#include "wl_proto.hh"
8#include "wl_log.hh" 9#include "wl_log.hh"
9#include "wl_sock.hh" 10#include "wl_sock.hh"
10 11
@@ -33,9 +34,9 @@ int get_field(const char *buffer, char *out, int maxlen)
33 34
34 /* Copy buffer to out pointer */ 35 /* Copy buffer to out pointer */
35 memset(out, 0, maxlen); 36 memset(out, 0, maxlen);
36 37
37 if(atoi(len)-3 > maxlen -1) 38 if(atoi(len) > maxlen -1)
38 memcpy(out, buffer + 3, maxlen - 1); 39 memcpy(out, buffer + 3, maxlen - 1);
39 else 40 else
40 memcpy(out, buffer + 3, atoi(len)); 41 memcpy(out, buffer + 3, atoi(len));
41 42
@@ -53,9 +54,9 @@ int send_network_found (const char *guihost, int guiport, void *structure)
53 ptr = (wl_network_t *)structure; 54 ptr = (wl_network_t *)structure;
54 55
55 /* Type = Found new net (without length field) */ 56 /* Type = Found new net (without length field) */
56 memset(temp, 0, sizeof(temp)); 57 memset(temp, 0, sizeof(temp));
57 snprintf(temp, sizeof(temp), "%.2d", NETFOUND); 58 snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND);
58 memcpy(buffer, temp, 2); 59 memcpy(buffer, temp, 2);
59 len += 2; 60 len += 2;
60 61
61 /* Set Net-type */ 62 /* Set Net-type */
@@ -97,9 +98,9 @@ int get_network_found (void *structure, const char *buffer)
97 char temp[5]; 98 char temp[5];
98 unsigned int len = 0; 99 unsigned int len = 0;
99 100
100 ptr = (wl_network_t *)structure; 101 ptr = (wl_network_t *)structure;
101 102
102 /* packet type already determined, skip check */ 103 /* packet type already determined, skip check */
103 len += 2; 104 len += 2;
104 105
105 /* Get net type (accesspoint || ad-hoc || ...) */ 106 /* 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);
17int get_field(const char *, char *, int); 17int get_field(const char *, char *, int);
18int send_network_found (const char *, int, void *); 18int send_network_found (const char *, int, void *);
19int get_network_found (void *, const char *); 19int get_network_found (void *, const char *);
20 20
21typedef struct {
22 int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */
23 int ssid_len; /* Length of SSID */
24 int channel; /* Channel */
25 int wep; /* 1 = WEP enabled ; 0 = disabled */
26 char mac[64]; /* MAC address of Accesspoint */
27 char bssid[128]; /* BSSID of Net */
28} wl_network_t;
29
30#endif /* WLPROTO_HH */ 21#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 @@
7#include "wl_sock.hh" 7#include "wl_sock.hh"
8#include "wl_log.hh" 8#include "wl_log.hh"
9 9
10/* Setup UDP Socket for incoming commands */ 10/* Setup UDP Socket for incoming commands */
11int wl_setupsock(const char *host, int port) 11int wl_setupsock(const char *host, int port, struct sockaddr_in saddr)
12{ 12{
13 struct sockaddr_in saddr;
14 int sock; 13 int sock;
15 14
16 if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) 15 if((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
17 { 16 {
@@ -22,9 +21,9 @@ int wl_setupsock(const char *host, int port)
22 memset(&saddr, 0, sizeof(saddr)); 21 memset(&saddr, 0, sizeof(saddr));
23 saddr.sin_family = PF_INET; 22 saddr.sin_family = PF_INET;
24 saddr.sin_port = htons(port); 23 saddr.sin_port = htons(port);
25 saddr.sin_addr.s_addr = inet_addr(host); 24 saddr.sin_addr.s_addr = inet_addr(host);
26 25
27 if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) 26 if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0)
28 { 27 {
29 wl_logerr("Cannot bind socket: %s", strerror(errno)); 28 wl_logerr("Cannot bind socket: %s", strerror(errno));
30 close(sock); 29 close(sock);
@@ -72,17 +71,19 @@ int wl_send(const char *host, int port, const char *string, ...)
72 return 1; 71 return 1;
73} 72}
74 73
75/* Check for new messages on commsock */ 74/* Check for new messages on commsock */
76int wl_recv(int *sock, char *out, int maxlen) 75int wl_recv(int *sock, struct sockaddr_in cliaddr, char *out, int maxlen)
77{ 76{
78 struct sockaddr_in *cliaddr;
79 socklen_t len = sizeof(struct sockaddr); 77 socklen_t len = sizeof(struct sockaddr);
80 char retval[3]; 78 char retval[3];
81 79
82 memset(out, 0, maxlen); 80 memset(out, 0, maxlen);
83 if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0) 81 if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)&cliaddr, &len) < 0)
82 {
83 wl_logerr("Cannot receive from socket: %s", strerror(errno));
84 return -1; 84 return -1;
85 }
85 86
86 /* Get packet type and return it */ 87 /* Get packet type and return it */
87 memset(retval, 0, sizeof(retval)); 88 memset(retval, 0, sizeof(retval));
88 memcpy(retval, out, 2); 89 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 @@
1/* $id */ 1/* $Id */
2 2
3#ifndef WLSOCK_HH 3#ifndef WLSOCK_HH
4#define WLSOCK_HH 4#define WLSOCK_HH
5 5
6#include <stdarg.h>
6#include <sys/types.h> 7#include <sys/types.h>
7#include <sys/socket.h> 8#include <sys/socket.h>
8#include <netinet/in.h> 9#include <netinet/in.h>
9#include <arpa/inet.h> 10#include <arpa/inet.h>
@@ -12,9 +13,9 @@
12#include <unistd.h> 13#include <unistd.h>
13#include <stdlib.h> 14#include <stdlib.h>
14#include <errno.h> 15#include <errno.h>
15 16
16int wl_setupsock(const char *, int); 17int wl_setupsock(const char *, int, struct sockaddr_in);
17int wl_send(const char *, int, const char *, ...); 18int wl_send(const char *, int, const char *, ...);
18int wl_recv(int *, char *, int); 19int wl_recv(int *, struct sockaddr_in, char *, int);
19 20
20#endif /* WLSOCK_HH */ 21#endif /* WLSOCK_HH */