author | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-12-31 12:36:06 (UTC) |
commit | d331ca1cf11e8f525665a1e5cb10f491d47c19e8 (patch) (unidiff) | |
tree | 42e46b280ac5b9ce5762f0df3a09189c4912d560 /noncore/net/wellenreiter | |
parent | e34eef8e2f2a36797ef980d505a99948f88a5df2 (diff) | |
download | opie-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
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 | |||
@@ -5,16 +5,20 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
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 */ |
14 | void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) | 15 | void 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; |
19 | unsigned int HEADER_LENGTH; | 23 | unsigned int HEADER_LENGTH; |
20 | 24 | ||
@@ -92,31 +96,30 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack | |||
92 | others must be noise packets */ | 96 | others must be noise packets */ |
93 | pinfoptr->isvalid = 0; | 97 | pinfoptr->isvalid = 0; |
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; |
121 | 124 | ||
122 | wl_loginfo("Channel is: %d", pinfoptr->channel); | 125 | wl_loginfo("Channel is: %d", pinfoptr->channel); |
@@ -234,13 +237,14 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
234 | switch (*(p + offset)) | 237 | switch (*(p + offset)) |
235 | { | 238 | { |
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 |
245 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); | 249 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); |
246 | ppinfo->ssid_len = pbody.ssid.length; | 250 | ppinfo->ssid_len = pbody.ssid.length; |
@@ -248,33 +252,39 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
248 | break; | 252 | break; |
249 | 253 | ||
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; |
279 | } | 289 | } |
280 | break; | 290 | break; |
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 | |||
@@ -1,12 +1,13 @@ | |||
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_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 | ||
11 | /* Adds a field to the buffer */ | 12 | /* Adds a field to the buffer */ |
12 | int add_field(char *buffer, const char *string, int len) | 13 | int add_field(char *buffer, const char *string, int len) |
@@ -31,13 +32,13 @@ int get_field(const char *buffer, char *out, int maxlen) | |||
31 | /* Get length of value */ | 32 | /* Get length of value */ |
32 | memcpy(len, buffer, 3); | 33 | memcpy(len, buffer, 3); |
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 | ||
42 | /* Return length of whole field (including 3 byte length) */ | 43 | /* Return length of whole field (including 3 byte length) */ |
43 | return (atoi(len) + 3); | 44 | return (atoi(len) + 3); |
@@ -51,13 +52,13 @@ int send_network_found (const char *guihost, int guiport, void *structure) | |||
51 | unsigned int len = 0; | 52 | unsigned int len = 0; |
52 | 53 | ||
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 */ |
62 | memset(temp, 0, sizeof(temp)); | 63 | memset(temp, 0, sizeof(temp)); |
63 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); | 64 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); |
@@ -95,13 +96,13 @@ int get_network_found (void *structure, const char *buffer) | |||
95 | { | 96 | { |
96 | wl_network_t *ptr; | 97 | wl_network_t *ptr; |
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 || ...) */ |
106 | memset(temp, 0, sizeof(temp)); | 107 | memset(temp, 0, sizeof(temp)); |
107 | len += get_field(buffer + len, temp, sizeof(temp)); | 108 | len += get_field(buffer + len, temp, sizeof(temp)); |
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 | |||
@@ -15,16 +15,7 @@ | |||
15 | 15 | ||
16 | int add_field(char *, const char *, int); | 16 | int add_field(char *, const char *, int); |
17 | int get_field(const char *, char *, int); | 17 | int get_field(const char *, char *, int); |
18 | int send_network_found (const char *, int, void *); | 18 | int send_network_found (const char *, int, void *); |
19 | int get_network_found (void *, const char *); | 19 | int get_network_found (void *, const char *); |
20 | 20 | ||
21 | typedef 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 | |||
@@ -5,28 +5,27 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
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 */ |
11 | int wl_setupsock(const char *host, int port) | 11 | int 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 | { |
18 | wl_logerr("Cannot set up socket: %s", strerror(errno)); | 17 | wl_logerr("Cannot set up socket: %s", strerror(errno)); |
19 | return -1; | 18 | return -1; |
20 | } | 19 | } |
21 | 20 | ||
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); |
31 | return -1; | 30 | return -1; |
32 | } | 31 | } |
@@ -70,21 +69,23 @@ int wl_send(const char *host, int port, const char *string, ...) | |||
70 | wl_logerr("Cannot close socket: %s", strerror(errno)); | 69 | wl_logerr("Cannot close socket: %s", strerror(errno)); |
71 | 70 | ||
72 | return 1; | 71 | return 1; |
73 | } | 72 | } |
74 | 73 | ||
75 | /* Check for new messages on commsock */ | 74 | /* Check for new messages on commsock */ |
76 | int wl_recv(int *sock, char *out, int maxlen) | 75 | int 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); |
89 | 90 | ||
90 | return atoi(retval); | 91 | return atoi(retval); |
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,20 +1,21 @@ | |||
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> |
10 | #include <signal.h> | 11 | #include <signal.h> |
11 | #include <string.h> | 12 | #include <string.h> |
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 | ||
16 | int wl_setupsock(const char *, int); | 17 | int wl_setupsock(const char *, int, struct sockaddr_in); |
17 | int wl_send(const char *, int, const char *, ...); | 18 | int wl_send(const char *, int, const char *, ...); |
18 | int wl_recv(int *, char *, int); | 19 | int wl_recv(int *, struct sockaddr_in, char *, int); |
19 | 20 | ||
20 | #endif /* WLSOCK_HH */ | 21 | #endif /* WLSOCK_HH */ |