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 | |||
@@ -8,10 +8,14 @@ | |||
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; |
@@ -95,18 +99,16 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack | |||
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"); |
@@ -114,6 +116,7 @@ void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *pack | |||
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); |
@@ -237,7 +240,8 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
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)); |
@@ -251,7 +255,8 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
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; |
@@ -259,19 +264,24 @@ int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | |||
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)); |
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 | |||
@@ -4,6 +4,7 @@ | |||
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" |
@@ -34,7 +35,7 @@ int get_field(const char *buffer, char *out, int maxlen) | |||
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)); |
@@ -54,7 +55,7 @@ int send_network_found (const char *guihost, int guiport, void *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 | ||
@@ -98,7 +99,7 @@ int get_network_found (void *structure, const char *buffer) | |||
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 | ||
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 | |||
@@ -18,13 +18,4 @@ 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 | |||
@@ -8,9 +8,8 @@ | |||
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) |
@@ -23,7 +22,7 @@ int wl_setupsock(const char *host, int port) | |||
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)); |
@@ -73,15 +72,17 @@ int wl_send(const char *host, int port, const char *string, ...) | |||
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)); |
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,8 +1,9 @@ | |||
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> |
@@ -13,8 +14,8 @@ | |||
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 */ |