author | mjm <mjm> | 2002-12-27 16:35:28 (UTC) |
---|---|---|
committer | mjm <mjm> | 2002-12-27 16:35:28 (UTC) |
commit | 3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf (patch) (unidiff) | |
tree | 180016a8feae9e40c3e6b8be62b518bdf8ef18fc | |
parent | e6aaae74f39e3aed4dc3c186c56f92cef8c7da09 (diff) | |
download | opie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.zip opie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.tar.gz opie-3cb928900ffb1d2799bd7e8e1871aaf8d89b56cf.tar.bz2 |
cleanup, new protocol, renaming of some functions, GUI has to update!
12 files changed, 164 insertions, 152 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/Makefile b/noncore/net/wellenreiter/libwellenreiter/source/Makefile index 3670d96..51b5ff3 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/Makefile +++ b/noncore/net/wellenreiter/libwellenreiter/source/Makefile | |||
@@ -1,17 +1,17 @@ | |||
1 | # $Id$ | 1 | # $Id$ |
2 | 2 | ||
3 | INCLUDES = | 3 | OBJ = wl_proto.o wl_sock.o wl_log.o cardmode.o sniff.o |
4 | LIBRARIES = | 4 | CPP = g++ |
5 | LIBOBJ = proto.o sock.o log.o cardmode.o sniff.o | 5 | CPPFLAGS = -Wall -pedantic -g -DDEBUG |
6 | CXX = g++ -Wall -pedantic -g $(INCLUDES) -DDEBUG | ||
7 | 6 | ||
8 | static:libwellenreiter.a | 7 | static:libwellenreiter.a |
9 | libwellenreiter.a: $(LIBOBJ) | 8 | libwellenreiter.a: $(OBJ) |
10 | ar -cr libwellenreiter.a $(LIBOBJ) | 9 | ar -cr libwellenreiter.a $(OBJ) |
11 | 10 | ||
12 | shared:libwellenreiter.so | 11 | shared:libwellenreiter.so |
13 | libwellenreiter.so: $(LIBOBJ) | 12 | libwellenreiter.so: $(OBJ) |
14 | $(CXX) -shared -o libwellenreiter.so $(LIBOBJ) | 13 | $(CPP) $(CPPFLAGS) -shared -o libwellenreiter.so $(OBJ) |
15 | 14 | ||
16 | clean: | 15 | clean: |
17 | rm -f *.o *.a *.so *~ | 16 | rm -f *.o *.a *.so *~ |
17 | |||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc index 3aaa4a7..c29f4d0 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.cc | |||
@@ -1,78 +1,77 @@ | |||
1 | /* | 1 | /* |
2 | * Set card modes for sniffing | 2 | * Set card modes for sniffing |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "cardmode.hh" | 7 | #include "cardmode.hh" |
8 | #include "log.hh" | 8 | #include "wl_log.hh" |
9 | 9 | ||
10 | /* main card into monitor function */ | 10 | /* main card into monitor function */ |
11 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) | 11 | int card_into_monitormode (pcap_t **orighandle, char *device, int cardtype) |
12 | { | 12 | { |
13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; | 13 | char CiscoRFMON[35] = "/proc/driver/aironet/"; |
14 | FILE *CISCO_CONFIG_FILE; | 14 | FILE *CISCO_CONFIG_FILE; |
15 | pcap_t *handle = (pcap_t*)orighandle; | ||
16 | 15 | ||
17 | /* Checks if we have a device to sniff on */ | 16 | /* Checks if we have a device to sniff on */ |
18 | if(device == NULL) | 17 | if(device == NULL) |
19 | { | 18 | { |
20 | wl_logerr("No device given"); | 19 | wl_logerr("No device given"); |
21 | return 0; | 20 | return 0; |
22 | } | 21 | } |
23 | 22 | ||
24 | /* Setting the prmiscous and up flag to the interface */ | 23 | /* Setting the prmiscous and up flag to the interface */ |
25 | if (!card_set_promisc_up(device)) | 24 | if (!card_set_promisc_up(device)) |
26 | { | 25 | { |
27 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); | 26 | wl_logerr("Cannot set interface to promisc mode: %s", strerror(errno)); |
28 | return 0; | 27 | return 0; |
29 | } | 28 | } |
30 | wl_loginfo("Interface set to promisc mode"); | 29 | wl_loginfo("Interface set to promisc mode"); |
31 | 30 | ||
32 | /* Check the cardtype and executes the commands to go into monitor mode */ | 31 | /* Check the cardtype and executes the commands to go into monitor mode */ |
33 | if (cardtype == CARD_TYPE_CISCO) | 32 | if (cardtype == CARD_TYPE_CISCO) |
34 | { | 33 | { |
35 | /* bring the sniffer into rfmon mode */ | 34 | /* bring the sniffer into rfmon mode */ |
36 | snprintf(CiscoRFMON, sizeof(CiscoRFMON), DEFAULT_PATH, device); | 35 | snprintf(CiscoRFMON, sizeof(CiscoRFMON) - 1, DEFAULT_PATH, device); |
37 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) | 36 | if((CISCO_CONFIG_FILE = fopen(CiscoRFMON,"w")) == NULL) |
38 | { | 37 | { |
39 | wl_logerr("Cannot open config file: %s", strerror(errno)); | 38 | wl_logerr("Cannot open config file: %s", strerror(errno)); |
40 | return 0; | 39 | return 0; |
41 | } | 40 | } |
42 | fputs ("Mode: r",CISCO_CONFIG_FILE); | 41 | fputs ("Mode: r",CISCO_CONFIG_FILE); |
43 | fputs ("Mode: y",CISCO_CONFIG_FILE); | 42 | fputs ("Mode: y",CISCO_CONFIG_FILE); |
44 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); | 43 | fputs ("XmitPower: 1",CISCO_CONFIG_FILE); |
45 | fclose(CISCO_CONFIG_FILE); | 44 | fclose(CISCO_CONFIG_FILE); |
46 | } | 45 | } |
47 | else if (cardtype == CARD_TYPE_NG) | 46 | else if (cardtype == CARD_TYPE_NG) |
48 | { | 47 | { |
49 | char wlanngcmd[62]; | 48 | char wlanngcmd[62]; |
50 | snprintf(wlanngcmd, sizeof(wlanngcmd), "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); | 49 | snprintf(wlanngcmd, sizeof(wlanngcmd) - 1, "%s %s lnxreq_wlansniff channel=1 enable=true", WLANCTL_PATH, device); |
51 | if (system(wlanngcmd) != 0) | 50 | if (system(wlanngcmd) != 0) |
52 | { | 51 | { |
53 | wl_logerr("Could not set %s in raw mode, check cardtype", device); | 52 | wl_logerr("Could not set %s in raw mode, check cardtype", device); |
54 | return 0; | 53 | return 0; |
55 | } | 54 | } |
56 | } | 55 | } |
57 | else if (cardtype == CARD_TYPE_HOSTAP) | 56 | else if (cardtype == CARD_TYPE_HOSTAP) |
58 | { | 57 | { |
59 | wl_logerr("Got a host-ap card, nothing is implemented now"); | 58 | wl_logerr("Got a host-ap card, nothing is implemented now"); |
60 | } | 59 | } |
61 | 60 | ||
62 | return 1; | 61 | return 1; |
63 | } | 62 | } |
64 | 63 | ||
65 | /* Set card into promisc mode */ | 64 | /* Set card into promisc mode */ |
66 | int card_set_promisc_up (const char *device) | 65 | int card_set_promisc_up (const char *device) |
67 | { | 66 | { |
68 | char ifconfigcmd[32]; | 67 | char ifconfigcmd[32]; |
69 | int retval=0; | 68 | int retval=0; |
70 | 69 | ||
71 | snprintf(ifconfigcmd, sizeof(ifconfigcmd), SBIN_PATH, device); | 70 | snprintf(ifconfigcmd, sizeof(ifconfigcmd) - 1, SBIN_PATH, device); |
72 | retval = system(ifconfigcmd); | 71 | retval = system(ifconfigcmd); |
73 | 72 | ||
74 | if(retval != 0) | 73 | if(retval != 0) |
75 | return 0; | 74 | return 0; |
76 | 75 | ||
77 | return 1; | 76 | return 1; |
78 | } | 77 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh index b85b7b7..6ec5b95 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/cardmode.hh | |||
@@ -1,36 +1,32 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef CARDMODE_HH | 3 | #ifndef CARDMODE_HH |
4 | #define CARDMODE_HH | 4 | #define CARDMODE_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdlib.h> | 7 | #include <stdlib.h> |
8 | #include <errno.h> | 8 | #include <errno.h> |
9 | #include <sys/types.h> | 9 | #include <sys/types.h> |
10 | #include <sys/time.h> | 10 | #include <sys/time.h> |
11 | #include <sys/socket.h> | 11 | #include <sys/socket.h> |
12 | #include <netinet/in.h> | 12 | #include <netinet/in.h> |
13 | |||
14 | extern "C" | ||
15 | { | ||
16 | #include <net/bpf.h> | 13 | #include <net/bpf.h> |
17 | #include <pcap.h> | 14 | #include <pcap.h> |
18 | } | ||
19 | 15 | ||
20 | /* Defines, used for the card setup */ | 16 | /* Defines, used for the card setup */ |
21 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" | 17 | #define DEFAULT_PATH "/proc/driver/aironet/%s/Config" |
22 | #define CARD_TYPE_CISCO1 | 18 | #define CARD_TYPE_CISCO1 |
23 | #define CARD_TYPE_NG 2 | 19 | #define CARD_TYPE_NG 2 |
24 | #define CARD_TYPE_HOSTAP3 | 20 | #define CARD_TYPE_HOSTAP3 |
25 | 21 | ||
26 | /* only for now, until we have the daemon running */ | 22 | /* only for now, until we have the daemon running */ |
27 | /*the config file should provide these information */ | 23 | /*the config file should provide these information */ |
28 | #define CARD_TYPE CARD_TYPE_HOSTAP | 24 | #define CARD_TYPE CARD_TYPE_HOSTAP |
29 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" | 25 | #define SBIN_PATH "/sbin/ifconfig %s promisc up" |
30 | #define WLANCTL_PATH "/sbin/wlanctl-ng" | 26 | #define WLANCTL_PATH "/sbin/wlanctl-ng" |
31 | 27 | ||
32 | /* Prototypes */ | 28 | /* Prototypes */ |
33 | int card_into_monitormode (pcap_t **, char *, int); | 29 | int card_into_monitormode (pcap_t **, char *, int); |
34 | int card_set_promisc_up (const char *); | 30 | int card_set_promisc_up (const char *); |
35 | 31 | ||
36 | #endif /* CARDMODE_HH */ | 32 | #endif /* CARDMODE_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/proto.cc deleted file mode 100644 index a1228e4..0000000 --- a/noncore/net/wellenreiter/libwellenreiter/source/proto.cc +++ b/dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | /* | ||
2 | * Communication protocol | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "proto.hh" | ||
8 | #include "sock.hh" | ||
9 | #include "log.hh" | ||
10 | |||
11 | /* Send found network to GUI */ | ||
12 | int send_network_found (const char *guihost, int guiport, void *structure) | ||
13 | { | ||
14 | wl_network_t *ptr; | ||
15 | char buffer[2048]; | ||
16 | char temp[5]; | ||
17 | |||
18 | ptr = (wl_network_t *)structure; | ||
19 | |||
20 | memset(buffer, 0, 2048); | ||
21 | |||
22 | /* Type = Found new net */ | ||
23 | memcpy(buffer, "01", 2); | ||
24 | |||
25 | /* Set Net-type */ | ||
26 | memset(temp, 0, sizeof(temp)); | ||
27 | snprintf(temp, 2, "%d", ptr->net_type); | ||
28 | memcpy(buffer + 2, temp, 1); | ||
29 | |||
30 | /* Set channel */ | ||
31 | memset(temp, 0, sizeof(temp)); | ||
32 | |||
33 | if(ptr->channel < 10) | ||
34 | snprintf(temp, 3, "0%d", ptr->channel); | ||
35 | else | ||
36 | snprintf(temp, 3, "%d", ptr->channel); | ||
37 | |||
38 | memcpy(buffer + 3, temp, 2); | ||
39 | |||
40 | /* Set WEP y/n */ | ||
41 | memset(temp, 0, sizeof(temp)); | ||
42 | snprintf(temp, 2, "%d", ptr->wep); | ||
43 | memcpy(buffer + 5, temp, 1); | ||
44 | |||
45 | /* Set MAC address */ | ||
46 | memcpy(buffer + 6, ptr->mac, 17); | ||
47 | |||
48 | /* Set lenght of ssid */ | ||
49 | memset(temp, 0, sizeof(temp)); | ||
50 | |||
51 | if(ptr->ssid_len > 99) | ||
52 | snprintf(temp, 4, "%d", ptr->ssid_len); | ||
53 | else if(ptr->ssid_len < 10) | ||
54 | snprintf(temp, 4, "00%d", ptr->ssid_len); | ||
55 | else | ||
56 | snprintf(temp, 4, "0%d", ptr->ssid_len); | ||
57 | |||
58 | memcpy(buffer + 23, temp, 3); | ||
59 | |||
60 | /* Set ssid */ | ||
61 | memcpy(buffer + 26, ptr->bssid, ptr->ssid_len); | ||
62 | |||
63 | /* Send prepared buffer to GUI */ | ||
64 | #ifdef DEBUG | ||
65 | wl_loginfo("Sending network to GUI: '%s'", buffer); | ||
66 | #endif | ||
67 | |||
68 | sendcomm(guihost, guiport, buffer); | ||
69 | |||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | /* Fill buffer into structur */ | ||
74 | int get_network_found (void *structure, const char *buffer) | ||
75 | { | ||
76 | wl_network_t *ptr; | ||
77 | char temp[512]; | ||
78 | |||
79 | ptr = (wl_network_t *)structure; | ||
80 | |||
81 | /* Get net type */ | ||
82 | memset(temp, 0, sizeof(temp)); | ||
83 | memcpy(temp, buffer + 2, 1); | ||
84 | ptr->net_type = atoi(temp); | ||
85 | |||
86 | /* Get channel */ | ||
87 | memset(temp, 0, sizeof(temp)); | ||
88 | memcpy(temp, buffer + 3, 2); | ||
89 | ptr->channel = atoi(temp); | ||
90 | |||
91 | /* Set WEP y/n */ | ||
92 | memset(temp, 0, sizeof(temp)); | ||
93 | memcpy(temp, buffer + 5, 1); | ||
94 | ptr->wep = atoi(temp); | ||
95 | |||
96 | /* Set MAC address */ | ||
97 | memcpy(ptr->mac, buffer + 6, 17); | ||
98 | ptr->mac[17]='\0'; | ||
99 | |||
100 | /* Set lenght of ssid */ | ||
101 | memset(temp, 0, sizeof(temp)); | ||
102 | memcpy(temp, buffer + 23, 3); | ||
103 | ptr->ssid_len = atoi(temp); | ||
104 | |||
105 | /* Set ssid */ | ||
106 | memcpy(ptr->bssid, buffer + 26, ptr->ssid_len + 1); | ||
107 | |||
108 | return 1; | ||
109 | } | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc index c703052..e2169ca 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.cc | |||
@@ -1,331 +1,331 @@ | |||
1 | /* | 1 | /* |
2 | * rfmon mode sniffer | 2 | * rfmon mode sniffer |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
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 "log.hh" | 10 | #include "wl_log.hh" |
11 | #include "proto.hh" | 11 | #include "wl_proto.hh" |
12 | 12 | ||
13 | /* Main function, checks packets */ | 13 | /* Main function, checks packets */ |
14 | void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) | 14 | void process_packets(const struct pcap_pkthdr *pkthdr, const unsigned char *packet, char *guihost, int guiport) |
15 | { | 15 | { |
16 | unsigned int caplen = pkthdr->caplen; | 16 | unsigned int caplen = pkthdr->caplen; |
17 | unsigned int length = pkthdr->len; | 17 | unsigned int length = pkthdr->len; |
18 | u_int16_t fc; | 18 | u_int16_t fc; |
19 | unsigned int HEADER_LENGTH; | 19 | unsigned int HEADER_LENGTH; |
20 | 20 | ||
21 | /* pinfo holds all interresting information for us */ | 21 | /* pinfo holds all interresting information for us */ |
22 | struct packetinfo pinfo; | 22 | struct packetinfo pinfo; |
23 | struct packetinfo *pinfoptr; | 23 | struct packetinfo *pinfoptr; |
24 | 24 | ||
25 | /* wl_network_t will finally be set and send to the ui */ | 25 | /* wl_network_t will finally be set and send to the ui */ |
26 | wl_network_t wl_net; | 26 | wl_network_t wl_net; |
27 | 27 | ||
28 | pinfoptr=&pinfo; | 28 | pinfoptr=&pinfo; |
29 | 29 | ||
30 | pinfoptr->isvalid = 0; | 30 | pinfoptr->isvalid = 0; |
31 | pinfoptr->pktlen = pkthdr->len; | 31 | pinfoptr->pktlen = pkthdr->len; |
32 | 32 | ||
33 | if (caplen < IEEE802_11_FC_LEN) | 33 | if (caplen < IEEE802_11_FC_LEN) |
34 | { | 34 | { |
35 | /* This is a garbage packet, because is does not long enough | 35 | /* This is a garbage packet, because is does not long enough |
36 | to hold a 802.11b header */ | 36 | to hold a 802.11b header */ |
37 | pinfoptr->isvalid = 0; | 37 | pinfoptr->isvalid = 0; |
38 | return; | 38 | return; |
39 | } | 39 | } |
40 | 40 | ||
41 | /* Gets the framecontrol bits (2bytes long) */ | 41 | /* Gets the framecontrol bits (2bytes long) */ |
42 | fc = EXTRACT_LE_16BITS(packet); | 42 | fc = EXTRACT_LE_16BITS(packet); |
43 | 43 | ||
44 | HEADER_LENGTH = GetHeaderLength(fc); | 44 | HEADER_LENGTH = GetHeaderLength(fc); |
45 | 45 | ||
46 | if (caplen < HEADER_LENGTH) | 46 | if (caplen < HEADER_LENGTH) |
47 | { | 47 | { |
48 | /* This is a garbage packet, because it is not long enough | 48 | /* This is a garbage packet, because it is not long enough |
49 | to hold a correct header of its type */ | 49 | to hold a correct header of its type */ |
50 | pinfoptr->isvalid = 0; | 50 | pinfoptr->isvalid = 0; |
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | 53 | ||
54 | /* Decode 802.11b header out of the packet */ | 54 | /* Decode 802.11b header out of the packet */ |
55 | if (decode_80211b_hdr(packet,pinfoptr) == 0) | 55 | if (decode_80211b_hdr(packet,pinfoptr) == 0) |
56 | { | 56 | { |
57 | /* Justification of the ofset to further process the packet */ | 57 | /* Justification of the ofset to further process the packet */ |
58 | length -= HEADER_LENGTH; | 58 | length -= HEADER_LENGTH; |
59 | caplen -= HEADER_LENGTH; | 59 | caplen -= HEADER_LENGTH; |
60 | packet += HEADER_LENGTH; | 60 | packet += HEADER_LENGTH; |
61 | } | 61 | } |
62 | else /* Something is wrong,could not be a correct packet */ | 62 | else /* Something is wrong,could not be a correct packet */ |
63 | return; | 63 | return; |
64 | 64 | ||
65 | switch (FC_TYPE(fc)) | 65 | switch (FC_TYPE(fc)) |
66 | { | 66 | { |
67 | /* Is it a managemnet frame? */ | 67 | /* Is it a managemnet frame? */ |
68 | case T_MGMT: | 68 | case T_MGMT: |
69 | switch (FC_SUBTYPE(fc)) | 69 | switch (FC_SUBTYPE(fc)) |
70 | { | 70 | { |
71 | case ST_BEACON: | 71 | case ST_BEACON: |
72 | if (handle_beacon(fc, packet,pinfoptr) ==0) | 72 | if (handle_beacon(fc, packet,pinfoptr) ==0) |
73 | { | 73 | { |
74 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) | 74 | if (!strcmp(pinfoptr->desthwaddr,"ff:ff:ff:ff:ff:ff") == 0) |
75 | { | 75 | { |
76 | /* Every beacon must have the broadcast as destination | 76 | /* Every beacon must have the broadcast as destination |
77 | so it must be a shitti packet */ | 77 | so it must be a shitti packet */ |
78 | pinfoptr->isvalid = 0; | 78 | pinfoptr->isvalid = 0; |
79 | return; | 79 | return; |
80 | } | 80 | } |
81 | 81 | ||
82 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) | 82 | if (pinfoptr->cap_ESS == pinfoptr->cap_IBSS) |
83 | { | 83 | { |
84 | /* Only one of both are possible, so must be | 84 | /* Only one of both are possible, so must be |
85 | a noise packet, if this comes up */ | 85 | a noise packet, if this comes up */ |
86 | pinfoptr->isvalid = 0; | 86 | pinfoptr->isvalid = 0; |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) | 89 | if (pinfoptr->channel < 1 || pinfoptr->channel > 14) |
90 | { | 90 | { |
91 | /* Only channels between 1 and 14 are possible | 91 | /* Only channels between 1 and 14 are possible |
92 | others must be noise packets */ | 92 | others must be noise packets */ |
93 | pinfoptr->isvalid = 0; | 93 | pinfoptr->isvalid = 0; |
94 | return; | 94 | return; |
95 | } | 95 | } |
96 | 96 | ||
97 | /* Here should be the infos to the gui issued */ | 97 | /* Here should be the infos to the gui issued */ |
98 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) | 98 | if (pinfoptr->cap_ESS == 1 &&pinfoptr->cap_IBSS ==0) |
99 | { | 99 | { |
100 | wl_loginfo("Found an access point"); | 100 | wl_loginfo("Found an access point"); |
101 | wl_net.net_type=1; | 101 | wl_net.net_type=1; |
102 | } | 102 | } |
103 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) | 103 | else if(pinfoptr->cap_ESS == 0 && pinfoptr->cap_IBSS == 2) |
104 | { | 104 | { |
105 | wl_loginfo("Found an ad-hoc network"); | 105 | wl_loginfo("Found an ad-hoc network"); |
106 | wl_net.net_type=2; | 106 | wl_net.net_type=2; |
107 | } | 107 | } |
108 | 108 | ||
109 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) | 109 | if (strcmp (pinfoptr->ssid,NONBROADCASTING) ==0) |
110 | wl_loginfo("Net is a non-broadcasting network"); | 110 | wl_loginfo("Net is a non-broadcasting network"); |
111 | else | 111 | else |
112 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 112 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
113 | 113 | ||
114 | wl_loginfo("SSID is: %s", pinfoptr->ssid); | 114 | wl_loginfo("SSID is: %s", pinfoptr->ssid); |
115 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); | 115 | memcpy(wl_net.bssid, pinfoptr->ssid, sizeof(wl_net.bssid)-1); |
116 | 116 | ||
117 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); | 117 | wl_loginfo("SSID length is: %d", pinfoptr->ssid_len); |
118 | wl_net.ssid_len=pinfoptr->ssid_len; | 118 | wl_net.ssid_len=pinfoptr->ssid_len; |
119 | 119 | ||
120 | wl_loginfo("Channel is: %d", pinfoptr->channel); | 120 | wl_loginfo("Channel is: %d", pinfoptr->channel); |
121 | wl_net.channel=pinfoptr->channel; | 121 | wl_net.channel=pinfoptr->channel; |
122 | wl_net.wep=pinfoptr->cap_WEP; | 122 | wl_net.wep=pinfoptr->cap_WEP; |
123 | 123 | ||
124 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); | 124 | wl_loginfo("Mac is: %s", pinfoptr->sndhwaddr); |
125 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; | 125 | memcpy(wl_net.mac, pinfoptr->sndhwaddr, sizeof(wl_net.mac)-1);; |
126 | 126 | ||
127 | send_network_found((char *)guihost, guiport, &wl_net); | 127 | send_network_found((char *)guihost, guiport, &wl_net); |
128 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); | 128 | wl_loginfo("Sent network to GUI '%s:%d'", guihost, guiport); |
129 | } | 129 | } |
130 | break; | 130 | break; |
131 | 131 | ||
132 | default: | 132 | default: |
133 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); | 133 | wl_logerr("Unknown IEEE802.11 frame subtype (%d)", FC_SUBTYPE(fc)); |
134 | break; | 134 | break; |
135 | } /* End of switch over different mgt frame types */ | 135 | } /* End of switch over different mgt frame types */ |
136 | 136 | ||
137 | break; | 137 | break; |
138 | 138 | ||
139 | case T_CTRL: | 139 | case T_CTRL: |
140 | wl_loginfo("Received control frame, not implemented yet"); | 140 | wl_loginfo("Received control frame, not implemented yet"); |
141 | break; | 141 | break; |
142 | 142 | ||
143 | case T_DATA: | 143 | case T_DATA: |
144 | wl_loginfo("Received date frame, not implemented yet"); | 144 | wl_loginfo("Received date frame, not implemented yet"); |
145 | break; | 145 | break; |
146 | 146 | ||
147 | default: | 147 | default: |
148 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); | 148 | wl_logerr("Unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); |
149 | break; | 149 | break; |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | /* This decodes the 802.11b frame header out of the 802.11b packet | 153 | /* This decodes the 802.11b frame header out of the 802.11b packet |
154 | all the infos is placed into the packetinfo structure */ | 154 | all the infos is placed into the packetinfo structure */ |
155 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) | 155 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo) |
156 | { | 156 | { |
157 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; | 157 | const struct mgmt_header_t *mgthdr = (const struct mgmt_header_t *) p; |
158 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); | 158 | ppinfo->fcsubtype = FC_SUBTYPE(mgthdr->fc); |
159 | 159 | ||
160 | /* Get the sender, bssid and dest mac address */ | 160 | /* Get the sender, bssid and dest mac address */ |
161 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); | 161 | etheraddr_string(mgthdr->bssid,ppinfo->bssid); |
162 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); | 162 | etheraddr_string(mgthdr->da,ppinfo->desthwaddr); |
163 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); | 163 | etheraddr_string(mgthdr->sa,ppinfo->sndhwaddr); |
164 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); | 164 | ppinfo->fc_wep = FC_WEP(mgthdr->fc); |
165 | return 0; | 165 | return 0; |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | void etheraddr_string(register const u_char *ep, char *text) | 169 | void etheraddr_string(register const u_char *ep, char *text) |
170 | { | 170 | { |
171 | static char hex[] = "0123456789abcdef"; | 171 | static char hex[] = "0123456789abcdef"; |
172 | register unsigned int i, j; | 172 | register unsigned int i, j; |
173 | register char *cp; | 173 | register char *cp; |
174 | char buf[sizeof("00:00:00:00:00:00\0")]; | 174 | char buf[sizeof("00:00:00:00:00:00\0")]; |
175 | cp = buf; | 175 | cp = buf; |
176 | if ((j = *ep >> 4) != 0) | 176 | if ((j = *ep >> 4) != 0) |
177 | { | 177 | { |
178 | *cp++ = hex[j]; | 178 | *cp++ = hex[j]; |
179 | } | 179 | } |
180 | else | 180 | else |
181 | { | 181 | { |
182 | *cp++ = '0'; | 182 | *cp++ = '0'; |
183 | } | 183 | } |
184 | *cp++ = hex[*ep++ & 0xf]; | 184 | *cp++ = hex[*ep++ & 0xf]; |
185 | 185 | ||
186 | for (i = 5; (int)--i >= 0;) | 186 | for (i = 5; (int)--i >= 0;) |
187 | { | 187 | { |
188 | *cp++ = ':'; | 188 | *cp++ = ':'; |
189 | if ((j = *ep >> 4) != 0) | 189 | if ((j = *ep >> 4) != 0) |
190 | { | 190 | { |
191 | *cp++ = hex[j]; | 191 | *cp++ = hex[j]; |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | *cp++ = '0'; | 195 | *cp++ = '0'; |
196 | } | 196 | } |
197 | 197 | ||
198 | *cp++ = hex[*ep++ & 0xf]; | 198 | *cp++ = hex[*ep++ & 0xf]; |
199 | } | 199 | } |
200 | *cp = '\0'; | 200 | *cp = '\0'; |
201 | strcpy(text,buf); | 201 | strcpy(text,buf); |
202 | } | 202 | } |
203 | 203 | ||
204 | /* beacon handler */ | 204 | /* beacon handler */ |
205 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) | 205 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo) |
206 | { | 206 | { |
207 | struct mgmt_body_t pbody; | 207 | struct mgmt_body_t pbody; |
208 | int offset = 0; | 208 | int offset = 0; |
209 | 209 | ||
210 | /* Get the static informations out of the packet */ | 210 | /* Get the static informations out of the packet */ |
211 | memset(&pbody, 0, sizeof(pbody)); | 211 | memset(&pbody, 0, sizeof(pbody)); |
212 | memcpy(&pbody.timestamp, p, 8); | 212 | memcpy(&pbody.timestamp, p, 8); |
213 | offset += 8; | 213 | offset += 8; |
214 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); | 214 | pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset); |
215 | offset += 2; | 215 | offset += 2; |
216 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); | 216 | pbody.capability_info = EXTRACT_LE_16BITS(p+offset); |
217 | offset += 2; | 217 | offset += 2; |
218 | 218 | ||
219 | /* Gets the different flags out of the capabilities */ | 219 | /* Gets the different flags out of the capabilities */ |
220 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); | 220 | ppinfo->cap_ESS = CAPABILITY_ESS(pbody.capability_info); |
221 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); | 221 | ppinfo->cap_IBSS = CAPABILITY_IBSS(pbody.capability_info); |
222 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); | 222 | ppinfo->cap_WEP = CAPABILITY_PRIVACY(pbody.capability_info); |
223 | 223 | ||
224 | /* Gets the tagged elements out of the packets */ | 224 | /* Gets the tagged elements out of the packets */ |
225 | while (offset + 1 < ppinfo->pktlen) | 225 | while (offset + 1 < ppinfo->pktlen) |
226 | { | 226 | { |
227 | switch (*(p + offset)) | 227 | switch (*(p + offset)) |
228 | { | 228 | { |
229 | case E_SSID: | 229 | case E_SSID: |
230 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; | 230 | memcpy(&(pbody.ssid),p+offset,2); offset += 2; |
231 | if (pbody.ssid.length > 0) | 231 | if (pbody.ssid.length > 0) |
232 | { | 232 | { |
233 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; | 233 | memcpy(&(pbody.ssid.ssid),p+offset,pbody.ssid.length); offset += pbody.ssid.length; |
234 | pbody.ssid.ssid[pbody.ssid.length]='\0'; | 234 | pbody.ssid.ssid[pbody.ssid.length]='\0'; |
235 | if (strcmp((char *)pbody.ssid.ssid,"")==0) | 235 | if (strcmp((char *)pbody.ssid.ssid,"")==0) |
236 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); | 236 | memcpy(ppinfo->ssid, NONBROADCASTING, sizeof(ppinfo->ssid)); |
237 | else | 237 | else |
238 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); | 238 | memcpy(ppinfo->ssid, pbody.ssid.ssid, sizeof(ppinfo->ssid)); |
239 | ppinfo->ssid_len = pbody.ssid.length; | 239 | ppinfo->ssid_len = pbody.ssid.length; |
240 | } | 240 | } |
241 | break; | 241 | break; |
242 | 242 | ||
243 | case E_CHALLENGE: | 243 | case E_CHALLENGE: |
244 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; | 244 | memcpy(&(pbody.challenge),p+offset,2); offset += 2; |
245 | if (pbody.challenge.length > 0) | 245 | if (pbody.challenge.length > 0) |
246 | { | 246 | { |
247 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; | 247 | memcpy(&(pbody.challenge.text),p+offset,pbody.challenge.length); offset += pbody.challenge.length; |
248 | pbody.challenge.text[pbody.challenge.length]='\0'; | 248 | pbody.challenge.text[pbody.challenge.length]='\0'; |
249 | } | 249 | } |
250 | break; | 250 | break; |
251 | case E_RATES: | 251 | case E_RATES: |
252 | memcpy(&(pbody.rates),p+offset,2); offset += 2; | 252 | memcpy(&(pbody.rates),p+offset,2); offset += 2; |
253 | if (pbody.rates.length > 0) | 253 | if (pbody.rates.length > 0) |
254 | { | 254 | { |
255 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; | 255 | memcpy(&(pbody.rates.rate),p+offset,pbody.rates.length); offset += pbody.rates.length; |
256 | } | 256 | } |
257 | break; | 257 | break; |
258 | case E_DS: | 258 | case E_DS: |
259 | memcpy(&(pbody.ds),p+offset,3); offset +=3; | 259 | memcpy(&(pbody.ds),p+offset,3); offset +=3; |
260 | ppinfo->channel = pbody.ds.channel; | 260 | ppinfo->channel = pbody.ds.channel; |
261 | break; | 261 | break; |
262 | case E_CF: | 262 | case E_CF: |
263 | memcpy(&(pbody.cf),p+offset,8); offset +=8; | 263 | memcpy(&(pbody.cf),p+offset,8); offset +=8; |
264 | break; | 264 | break; |
265 | case E_TIM: | 265 | case E_TIM: |
266 | memcpy(&(pbody.tim),p+offset,2); offset +=2; | 266 | memcpy(&(pbody.tim),p+offset,2); offset +=2; |
267 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; | 267 | memcpy(&(pbody.tim.count),p+offset,3); offset +=3; |
268 | if ((pbody.tim.length -3) > 0) | 268 | if ((pbody.tim.length -3) > 0) |
269 | { | 269 | { |
270 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); | 270 | memcpy((pbody.tim.bitmap),p+(pbody.tim.length -3),(pbody.tim.length -3)); |
271 | offset += pbody.tim.length -3; | 271 | offset += pbody.tim.length -3; |
272 | } | 272 | } |
273 | break; | 273 | break; |
274 | default: | 274 | default: |
275 | 275 | ||
276 | offset+= *(p+offset+1) + 2; | 276 | offset+= *(p+offset+1) + 2; |
277 | break; | 277 | break; |
278 | } /* end of switch*/ | 278 | } /* end of switch*/ |
279 | } /* end of for loop */ | 279 | } /* end of for loop */ |
280 | return 0; | 280 | return 0; |
281 | 281 | ||
282 | } /* End of handle_beacon */ | 282 | } /* End of handle_beacon */ |
283 | 283 | ||
284 | 284 | ||
285 | int GetHeaderLength(u_int16_t fc) | 285 | int GetHeaderLength(u_int16_t fc) |
286 | { | 286 | { |
287 | int iLength=0; | 287 | int iLength=0; |
288 | 288 | ||
289 | switch (FC_TYPE(fc)) | 289 | switch (FC_TYPE(fc)) |
290 | { | 290 | { |
291 | case T_MGMT: | 291 | case T_MGMT: |
292 | iLength = MGMT_HEADER_LEN; | 292 | iLength = MGMT_HEADER_LEN; |
293 | break; | 293 | break; |
294 | case T_CTRL: | 294 | case T_CTRL: |
295 | switch (FC_SUBTYPE(fc)) | 295 | switch (FC_SUBTYPE(fc)) |
296 | { | 296 | { |
297 | case CTRL_PS_POLL: | 297 | case CTRL_PS_POLL: |
298 | iLength = CTRL_PS_POLL_LEN; | 298 | iLength = CTRL_PS_POLL_LEN; |
299 | break; | 299 | break; |
300 | case CTRL_RTS: | 300 | case CTRL_RTS: |
301 | iLength = CTRL_RTS_LEN; | 301 | iLength = CTRL_RTS_LEN; |
302 | break; | 302 | break; |
303 | case CTRL_CTS: | 303 | case CTRL_CTS: |
304 | iLength = CTRL_CTS_LEN; | 304 | iLength = CTRL_CTS_LEN; |
305 | break; | 305 | break; |
306 | case CTRL_ACK: | 306 | case CTRL_ACK: |
307 | iLength = CTRL_ACK_LEN; | 307 | iLength = CTRL_ACK_LEN; |
308 | break; | 308 | break; |
309 | case CTRL_CF_END: | 309 | case CTRL_CF_END: |
310 | iLength = CTRL_END_LEN; | 310 | iLength = CTRL_END_LEN; |
311 | break; | 311 | break; |
312 | case CTRL_END_ACK: | 312 | case CTRL_END_ACK: |
313 | iLength = CTRL_END_ACK_LEN; | 313 | iLength = CTRL_END_ACK_LEN; |
314 | break; | 314 | break; |
315 | default: | 315 | default: |
316 | iLength = 0; | 316 | iLength = 0; |
317 | break; | 317 | break; |
318 | } | 318 | } |
319 | break; | 319 | break; |
320 | case T_DATA: | 320 | case T_DATA: |
321 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) | 321 | if (FC_TO_DS(fc) && FC_FROM_DS(fc)) |
322 | iLength = 30; | 322 | iLength = 30; |
323 | else | 323 | else |
324 | iLength = 24; | 324 | iLength = 24; |
325 | break; | 325 | break; |
326 | default: | 326 | default: |
327 | wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); | 327 | wl_logerr("unknown IEEE802.11 frame type (%d)", FC_TYPE(fc)); |
328 | break; | 328 | break; |
329 | } | 329 | } |
330 | return iLength; | 330 | return iLength; |
331 | } | 331 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh index c7108ac..713b383 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/sniff.hh | |||
@@ -1,70 +1,66 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef SNIFF_HH | 3 | #ifndef SNIFF_HH |
4 | #define SNIFF_HH | 4 | #define SNIFF_HH |
5 | 5 | ||
6 | #include <string.h> | 6 | #include <string.h> |
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | #include <errno.h> | 9 | #include <errno.h> |
10 | #include <sys/types.h> | 10 | #include <sys/types.h> |
11 | #include <sys/time.h> | 11 | #include <sys/time.h> |
12 | #include <sys/socket.h> | 12 | #include <sys/socket.h> |
13 | #include <netinet/in.h> | 13 | #include <netinet/in.h> |
14 | #include <arpa/inet.h> | 14 | #include <arpa/inet.h> |
15 | |||
16 | extern "C" | ||
17 | { | ||
18 | #include <net/bpf.h> | 15 | #include <net/bpf.h> |
19 | #include <pcap.h> | 16 | #include <pcap.h> |
20 | } | ||
21 | 17 | ||
22 | #define NONBROADCASTING "non-broadcasting" | 18 | #define NONBROADCASTING "non-broadcasting" |
23 | 19 | ||
24 | /* holds all the interresting data */ | 20 | /* holds all the interresting data */ |
25 | struct packetinfo | 21 | struct packetinfo |
26 | { | 22 | { |
27 | int isvalid; | 23 | int isvalid; |
28 | int pktlen; | 24 | int pktlen; |
29 | int fctype; | 25 | int fctype; |
30 | int fcsubtype; | 26 | int fcsubtype; |
31 | int fc_wep; | 27 | int fc_wep; |
32 | int cap_WEP; | 28 | int cap_WEP; |
33 | int cap_IBSS; | 29 | int cap_IBSS; |
34 | int cap_ESS; | 30 | int cap_ESS; |
35 | int channel; | 31 | int channel; |
36 | char bssid[sizeof("00:00:00:00:00:00") + 1]; | 32 | char bssid[sizeof("00:00:00:00:00:00") + 1]; |
37 | char desthwaddr[sizeof("00:00:00:00:00:00") + 1]; | 33 | char desthwaddr[sizeof("00:00:00:00:00:00") + 1]; |
38 | char sndhwaddr[sizeof("00:00:00:00:00:00") + 1]; | 34 | char sndhwaddr[sizeof("00:00:00:00:00:00") + 1]; |
39 | char ssid[128]; | 35 | char ssid[128]; |
40 | int ssid_len; | 36 | int ssid_len; |
41 | }; | 37 | }; |
42 | 38 | ||
43 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); | 39 | void process_packets(const struct pcap_pkthdr* pkthdr,const u_char* packet, char *, int); |
44 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); | 40 | int decode_80211b_hdr(const u_char *p,struct packetinfo *ppinfo); |
45 | void etheraddr_string(register const u_char *ep,char * text); | 41 | void etheraddr_string(register const u_char *ep,char * text); |
46 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); | 42 | int handle_beacon(u_int16_t fc, const u_char *p,struct packetinfo *ppinfo); |
47 | 43 | ||
48 | int GetHeaderLength(u_int16_t fc); | 44 | int GetHeaderLength(u_int16_t fc); |
49 | 45 | ||
50 | /* | 46 | /* |
51 | * True if "l" bytes of "var" were captured. | 47 | * True if "l" bytes of "var" were captured. |
52 | * | 48 | * |
53 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large | 49 | * The "snapend - (l) <= snapend" checks to make sure "l" isn't so large |
54 | * that "snapend - (l)" underflows. | 50 | * that "snapend - (l)" underflows. |
55 | * | 51 | * |
56 | * The check is for <= rather than < because "l" might be 0. | 52 | * The check is for <= rather than < because "l" might be 0. |
57 | */ | 53 | */ |
58 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ | 54 | #define TTEST2(var, l) (snapend - (l) <= snapend && \ |
59 | (const u_char *)&(var) <= snapend - (l)) | 55 | (const u_char *)&(var) <= snapend - (l)) |
60 | 56 | ||
61 | /* True if "var" was captured */ | 57 | /* True if "var" was captured */ |
62 | #define TTEST(var) TTEST2(var, sizeof(var)) | 58 | #define TTEST(var) TTEST2(var, sizeof(var)) |
63 | 59 | ||
64 | /* Bail if "l" bytes of "var" were not captured */ | 60 | /* Bail if "l" bytes of "var" were not captured */ |
65 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc | 61 | #define TCHECK2(var, l) if (!TTEST2(var, l)) goto trunc |
66 | 62 | ||
67 | /* Bail if "var" was not captured */ | 63 | /* Bail if "var" was not captured */ |
68 | #define TCHECK(var) TCHECK2(var, sizeof(var)) | 64 | #define TCHECK(var) TCHECK2(var, sizeof(var)) |
69 | 65 | ||
70 | #endif /* SNIFF_HH */ | 66 | #endif /* SNIFF_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.cc index af7f909..7adaba8 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/log.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.cc | |||
@@ -1,51 +1,51 @@ | |||
1 | /* | 1 | /* |
2 | * Small functions to log to syslog | 2 | * Small functions to log to syslog |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "log.hh" | 7 | #include "wl_log.hh" |
8 | 8 | ||
9 | /* Log to syslog INFO */ | 9 | /* Log to syslog INFO */ |
10 | void wl_loginfo(const char *fmt,...) | 10 | void wl_loginfo(const char *fmt,...) |
11 | { | 11 | { |
12 | 12 | ||
13 | char buffer[4096]; | 13 | char buffer[4096]; |
14 | va_list ap; | 14 | va_list ap; |
15 | 15 | ||
16 | memset(buffer, 0, sizeof(buffer)); | 16 | memset(buffer, 0, sizeof(buffer)); |
17 | va_start(ap, fmt); | 17 | va_start(ap, fmt); |
18 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); | 18 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); |
19 | va_end(ap); | 19 | va_end(ap); |
20 | 20 | ||
21 | openlog("libwellenreiter", LOG_PID, LOG_SYSLOG); | 21 | openlog("libwellenreiter", LOG_PID, LOG_SYSLOG); |
22 | syslog(LOG_INFO, "(info) %s", buffer); | 22 | syslog(LOG_INFO, "(info) %s", buffer); |
23 | closelog(); | 23 | closelog(); |
24 | 24 | ||
25 | #ifdef DEBUG | 25 | #ifdef DEBUG |
26 | fprintf(stderr, "(info) %s\n", buffer); | 26 | fprintf(stderr, "(info) %s\n", buffer); |
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | } | 29 | } |
30 | 30 | ||
31 | /* Log to syslog ERR */ | 31 | /* Log to syslog ERR */ |
32 | void wl_logerr(const char *fmt,...) | 32 | void wl_logerr(const char *fmt,...) |
33 | { | 33 | { |
34 | 34 | ||
35 | char buffer[4096]; | 35 | char buffer[4096]; |
36 | va_list ap; | 36 | va_list ap; |
37 | 37 | ||
38 | memset(buffer, 0, sizeof(buffer)); | 38 | memset(buffer, 0, sizeof(buffer)); |
39 | va_start(ap, fmt); | 39 | va_start(ap, fmt); |
40 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); | 40 | vsnprintf(buffer, sizeof(buffer)-1, fmt, ap); |
41 | va_end(ap); | 41 | va_end(ap); |
42 | 42 | ||
43 | openlog("libwellenreiter", LOG_PID, LOG_SYSLOG); | 43 | openlog("libwellenreiter", LOG_PID, LOG_SYSLOG); |
44 | syslog(LOG_INFO, "(err) %s", buffer); | 44 | syslog(LOG_INFO, "(err) %s", buffer); |
45 | closelog(); | 45 | closelog(); |
46 | 46 | ||
47 | #ifdef DEBUG | 47 | #ifdef DEBUG |
48 | fprintf(stderr, "(err) %s\n", buffer); | 48 | fprintf(stderr, "(err) %s\n", buffer); |
49 | #endif | 49 | #endif |
50 | 50 | ||
51 | } | 51 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/log.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.hh index 8f6e543..8f6e543 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/log.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_log.hh | |||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc new file mode 100644 index 0000000..f15523f --- a/dev/null +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |||
@@ -0,0 +1,132 @@ | |||
1 | /* | ||
2 | * Communication protocol | ||
3 | * | ||
4 | * $Id$ | ||
5 | */ | ||
6 | |||
7 | #include "wl_proto.hh" | ||
8 | #include "wl_log.hh" | ||
9 | #include "wl_sock.hh" | ||
10 | |||
11 | /* Adds a field to the buffer */ | ||
12 | int add_field(char *buffer, char *string, int len) | ||
13 | { | ||
14 | char newlen[5]; | ||
15 | |||
16 | /* 3 Byte = Length */ | ||
17 | snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); | ||
18 | memcpy(buffer, newlen, 3); | ||
19 | |||
20 | /* Length bytes = Value */ | ||
21 | memcpy(buffer + 3, string, atoi(newlen)); | ||
22 | |||
23 | /* Return length of attached field */ | ||
24 | return (atoi(newlen) + 3); | ||
25 | } | ||
26 | |||
27 | int get_field(const char *buffer, char *out) | ||
28 | { | ||
29 | char len[5]; | ||
30 | |||
31 | /* Get length of value */ | ||
32 | memcpy(len, buffer, 3); | ||
33 | |||
34 | /* Copy buffer to out pointer */ | ||
35 | memset(out, 0, atoi(len) + 1); | ||
36 | memcpy(out, buffer + 3, atoi(len)); | ||
37 | |||
38 | return atoi(len) + 3; | ||
39 | } | ||
40 | |||
41 | /* Send found network to GUI */ | ||
42 | int send_network_found (const char *guihost, int guiport, void *structure) | ||
43 | { | ||
44 | wl_network_t *ptr; | ||
45 | char buffer[2048]; | ||
46 | char temp[128]; | ||
47 | int retval=0, len=0; | ||
48 | |||
49 | memset(temp, 0, sizeof(temp)); | ||
50 | |||
51 | ptr = (wl_network_t *)structure; | ||
52 | |||
53 | /* Type = Found new net (without length field) */ | ||
54 | memset(temp, 0, sizeof(temp)); | ||
55 | snprintf(temp, sizeof(temp), "%.2d", NETFOUND); | ||
56 | memcpy(buffer, temp, 2); | ||
57 | len += 2; | ||
58 | |||
59 | /* Set Net-type */ | ||
60 | memset(temp, 0, sizeof(temp)); | ||
61 | snprintf(temp, sizeof(temp), "%d", ptr->net_type); | ||
62 | retval = add_field(buffer + len, temp, 1); | ||
63 | len += retval; | ||
64 | |||
65 | /* Set channel */ | ||
66 | memset(temp, 0, sizeof(temp)); | ||
67 | snprintf(temp, sizeof(temp), "%.2d", ptr->channel); | ||
68 | retval = add_field(buffer + len, temp, 2); | ||
69 | len += retval; | ||
70 | |||
71 | /* Set WEP y/n */ | ||
72 | memset(temp, 0, sizeof(temp)); | ||
73 | snprintf(temp, sizeof(temp), "%d", ptr->wep); | ||
74 | retval = add_field(buffer + len, temp, 1); | ||
75 | len += retval; | ||
76 | |||
77 | /* Set Mac */ | ||
78 | retval = add_field(buffer + len, (char *)ptr->mac, 17); | ||
79 | len += retval; | ||
80 | |||
81 | /* Set ssid */ | ||
82 | retval = add_field(buffer + len, (char *)ptr->bssid, ptr->ssid_len); | ||
83 | |||
84 | /* Send prepared buffer to GUI */ | ||
85 | #ifdef DEBUG | ||
86 | wl_loginfo("Sending network to GUI: '%s'", buffer); | ||
87 | #endif | ||
88 | |||
89 | wl_send(guihost, guiport, buffer); | ||
90 | |||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | /* Fill buffer into structur */ | ||
95 | int get_network_found (void *structure, const char *buffer) | ||
96 | { | ||
97 | wl_network_t *ptr; | ||
98 | char temp[512]; | ||
99 | int retval=0, len=0; | ||
100 | |||
101 | ptr = (wl_network_t *)structure; | ||
102 | |||
103 | /* packet type already determined */ | ||
104 | len += 2; | ||
105 | |||
106 | /* Get net type */ | ||
107 | memset(temp, 0, sizeof(temp)); | ||
108 | retval = get_field(buffer + len, temp); | ||
109 | len += retval; | ||
110 | ptr->net_type = atoi(temp); | ||
111 | |||
112 | /* Get channel */ | ||
113 | memset(temp, 0, sizeof(temp)); | ||
114 | retval = get_field(buffer + len, temp); | ||
115 | len += retval; | ||
116 | ptr->channel = atoi(temp); | ||
117 | |||
118 | /* Set WEP y/n */ | ||
119 | memset(temp, 0, sizeof(temp)); | ||
120 | retval = get_field(buffer + len, temp); | ||
121 | len += retval; | ||
122 | ptr->wep = atoi(temp); | ||
123 | |||
124 | /* Set MAC address */ | ||
125 | retval = get_field(buffer + len, ptr->mac); | ||
126 | len += retval; | ||
127 | |||
128 | /* Set BSSID */ | ||
129 | retval = get_field(buffer + len, ptr->bssid); | ||
130 | |||
131 | return 1; | ||
132 | } | ||
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh index e3e9f50..f755589 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/proto.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh | |||
@@ -1,28 +1,28 @@ | |||
1 | /* $Id$ */ | 1 | /* $Id$ */ |
2 | 2 | ||
3 | #ifndef PROTO_HH | 3 | #ifndef WLPROTO_HH |
4 | #define PROTO_HH | 4 | #define WLPROTO_HH |
5 | 5 | ||
6 | #include <stdio.h> | 6 | #include <stdio.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
9 | 9 | ||
10 | /* Type definitions, to be continued */ | 10 | /* Type definitions, to be continued */ |
11 | #define NETFOUND 01 | 11 | #define NETFOUND 01 |
12 | #define NETLOST 02 | 12 | #define NETLOST 02 |
13 | #define STARTSNIFF 98 | 13 | #define STARTSNIFF 98 |
14 | #define STOPSNIFF 99 | 14 | #define STOPSNIFF 99 |
15 | 15 | ||
16 | int send_network_found (const char *, int, void *); | 16 | int send_network_found (const char *, int, void *); |
17 | int get_network_found (void *, const char *); | 17 | int get_network_found (void *, const char *); |
18 | 18 | ||
19 | typedef struct { | 19 | typedef struct { |
20 | int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ | 20 | int net_type; /* 1 = Accesspoint ; 2 = Ad-Hoc */ |
21 | int ssid_len; /* Length of SSID */ | 21 | int ssid_len; /* Length of SSID */ |
22 | int channel; /* Channel */ | 22 | int channel; /* Channel */ |
23 | int wep; /* 1 = WEP enabled ; 0 = disabled */ | 23 | int wep; /* 1 = WEP enabled ; 0 = disabled */ |
24 | char mac[64]; /* MAC address of Accesspoint */ | 24 | char mac[64]; /* MAC address of Accesspoint */ |
25 | char bssid[128]; /* BSSID of Accesspoint */ | 25 | char bssid[128]; /* BSSID of Accesspoint */ |
26 | } wl_network_t; | 26 | } wl_network_t; |
27 | 27 | ||
28 | #endif /* PROTO_HH */ | 28 | #endif /* WLPROTO_HH */ |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc index 90fc20a..5714afb 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sock.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc | |||
@@ -1,93 +1,91 @@ | |||
1 | /* | 1 | /* |
2 | * Socket operations for wellenreiter | 2 | * Socket operations for wellenreiter |
3 | * | 3 | * |
4 | * $Id$ | 4 | * $Id$ |
5 | */ | 5 | */ |
6 | 6 | ||
7 | #include "sock.hh" | 7 | #include "wl_sock.hh" |
8 | #include "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 commsock(const char *host, int port) | 11 | int wl_setupsock(const char *host, int port) |
12 | { | 12 | { |
13 | struct sockaddr_in saddr; | 13 | struct sockaddr_in saddr; |
14 | int sock; | 14 | int sock; |
15 | 15 | ||
16 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) | 16 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
17 | { | 17 | { |
18 | wl_logerr("Cannot set up socket: %s", strerror(errno)); | 18 | wl_logerr("Cannot set up socket: %s", strerror(errno)); |
19 | return -1; | 19 | return -1; |
20 | } | 20 | } |
21 | 21 | ||
22 | memset(&saddr, 0, sizeof(saddr)); | 22 | memset(&saddr, 0, sizeof(saddr)); |
23 | saddr.sin_family = PF_INET; | 23 | saddr.sin_family = PF_INET; |
24 | saddr.sin_port = htons(port); | 24 | saddr.sin_port = htons(port); |
25 | saddr.sin_addr.s_addr = inet_addr(host); | 25 | saddr.sin_addr.s_addr = inet_addr(host); |
26 | 26 | ||
27 | if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) | 27 | if(bind(sock,(struct sockaddr *)&saddr, sizeof(saddr)) < 0) |
28 | { | 28 | { |
29 | wl_logerr("Cannot bind socket: %s", strerror(errno)); | 29 | wl_logerr("Cannot bind socket: %s", strerror(errno)); |
30 | close(sock); | 30 | close(sock); |
31 | return -1; | 31 | return -1; |
32 | } | 32 | } |
33 | 33 | ||
34 | return sock; | 34 | return sock; |
35 | } | 35 | } |
36 | 36 | ||
37 | /* Send a string to commsock */ | 37 | /* Send a string to commsock */ |
38 | int sendcomm(const char *host, int port, const char *string, ...) | 38 | int wl_send(const char *host, int port, const char *string, ...) |
39 | { | 39 | { |
40 | int sock; | 40 | int sock; |
41 | char buffer[4096]; | 41 | char buffer[4096]; |
42 | struct sockaddr_in saddr; | 42 | struct sockaddr_in saddr; |
43 | va_list ap; | 43 | va_list ap; |
44 | 44 | ||
45 | /* Generate string */ | 45 | /* Generate string */ |
46 | memset(buffer, 0, sizeof(buffer)); | 46 | memset(buffer, 0, sizeof(buffer)); |
47 | va_start(ap, string); | 47 | va_start(ap, string); |
48 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); | 48 | vsnprintf(buffer, sizeof(buffer)-1, string, ap); |
49 | va_end(ap); | 49 | va_end(ap); |
50 | 50 | ||
51 | saddr.sin_family = AF_INET; | 51 | saddr.sin_family = AF_INET; |
52 | saddr.sin_port = htons(port); | 52 | saddr.sin_port = htons(port); |
53 | saddr.sin_addr.s_addr = inet_addr(host); | 53 | saddr.sin_addr.s_addr = inet_addr(host); |
54 | 54 | ||
55 | /* Setup socket */ | 55 | /* Setup socket */ |
56 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) | 56 | if((sock=socket(AF_INET, SOCK_DGRAM, 0)) < 0) |
57 | { | 57 | { |
58 | wl_logerr("Cannot set up socket: %s", strerror(errno)); | 58 | wl_logerr("Cannot set up socket: %s", strerror(errno)); |
59 | return -1; | 59 | return -1; |
60 | } | 60 | } |
61 | 61 | ||
62 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) | 62 | if(sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&saddr, sizeof(saddr)) < 0) |
63 | { | 63 | { |
64 | wl_logerr("Cannot write to socket: %s", strerror(errno)); | 64 | wl_logerr("Cannot write to socket: %s", strerror(errno)); |
65 | close(sock); | 65 | close(sock); |
66 | return 0; | 66 | return -1; |
67 | } | 67 | } |
68 | 68 | ||
69 | if(close(sock) < 0) | 69 | if(close(sock) < 0) |
70 | wl_logerr("Cannot close socket: %s", strerror(errno)); | 70 | wl_logerr("Cannot close socket: %s", strerror(errno)); |
71 | 71 | ||
72 | return 1; | 72 | return 0; |
73 | } | 73 | } |
74 | 74 | ||
75 | /* Check for new messages on commsock */ | 75 | /* Check for new messages on commsock */ |
76 | int recvcomm(int *sock, char *out, int maxlen) | 76 | int wl_recv(int *sock, char *out, int maxlen) |
77 | { | 77 | { |
78 | struct sockaddr_in *cliaddr; | 78 | struct sockaddr_in *cliaddr; |
79 | socklen_t len=sizeof(struct sockaddr); | 79 | socklen_t len=sizeof(struct sockaddr); |
80 | char buffer[128], retval[3]; | 80 | char retval[3]; |
81 | |||
82 | memset(buffer, 0, sizeof(buffer)); | ||
83 | if(recvfrom(*sock, buffer, sizeof(buffer)-1, 0, (struct sockaddr *)cliaddr, &len) < 0) | ||
84 | return -1; | ||
85 | 81 | ||
86 | memset(out, 0, maxlen); | 82 | memset(out, 0, maxlen); |
87 | memcpy(out, buffer, maxlen - 1); | 83 | if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0) |
84 | return -1; | ||
88 | 85 | ||
86 | /* Get packet type and return it */ | ||
89 | memset(retval, 0, sizeof(retval)); | 87 | memset(retval, 0, sizeof(retval)); |
90 | memcpy(retval, out, 2); | 88 | memcpy(retval, out, 2); |
91 | 89 | ||
92 | return atoi(retval); | 90 | return atoi(retval); |
93 | } | 91 | } |
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh index 611e335..6ddbaef 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/sock.hh +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.hh | |||
@@ -1,20 +1,20 @@ | |||
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 <sys/types.h> | 6 | #include <sys/types.h> |
7 | #include <sys/socket.h> | 7 | #include <sys/socket.h> |
8 | #include <netinet/in.h> | 8 | #include <netinet/in.h> |
9 | #include <arpa/inet.h> | 9 | #include <arpa/inet.h> |
10 | #include <signal.h> | 10 | #include <signal.h> |
11 | #include <string.h> | 11 | #include <string.h> |
12 | #include <unistd.h> | 12 | #include <unistd.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | 15 | ||
16 | int commsock(const char *, int); | 16 | int wl_setupsock(const char *, int); |
17 | int sendcomm(const char *, int, const char *, ...); | 17 | int wl_send(const char *, int, const char *, ...); |
18 | int recvcomm(int *, char *, int); | 18 | int wl_recv(int *, char *, int); |
19 | 19 | ||
20 | #endif /* WLSOCK_HH */ | 20 | #endif /* WLSOCK_HH */ |