summaryrefslogtreecommitdiff
authormjm <mjm>2002-12-28 15:28:49 (UTC)
committer mjm <mjm>2002-12-28 15:28:49 (UTC)
commit94ac3da47b0b36316cff680d319dab23c9339308 (patch) (unidiff)
tree5161a4da84fb05c53fd5225be5674ab75087ff3f
parent0ab4ac99bead80d8af18988045748fd2b3dd3a15 (diff)
downloadopie-94ac3da47b0b36316cff680d319dab23c9339308.zip
opie-94ac3da47b0b36316cff680d319dab23c9339308.tar.gz
opie-94ac3da47b0b36316cff680d319dab23c9339308.tar.bz2
cleanup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc46
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh2
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc6
3 files changed, 23 insertions, 31 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
index 5317f52..ae6d406 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -1,131 +1,123 @@
1/* 1/*
2 * Communication protocol 2 * Communication protocol
3 * 3 *
4 * $Id$ 4 * $Id$
5 */ 5 */
6 6
7#include "wl_proto.hh" 7#include "wl_proto.hh"
8#include "wl_log.hh" 8#include "wl_log.hh"
9#include "wl_sock.hh" 9#include "wl_sock.hh"
10 10
11/* Adds a field to the buffer */ 11/* Adds a field to the buffer */
12int add_field(char *buffer, char *string, int len) 12int add_field(char *buffer, char *string, int len)
13{ 13{
14 char newlen[5]; 14 char newlen[5];
15 15
16 /* 3 Byte = Length */ 16 /* 3 Byte = Length */
17 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); 17 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len);
18 memcpy(buffer, newlen, 3); 18 memcpy(buffer, newlen, 3);
19 19
20 /* Length bytes = Value */ 20 /* Length bytes = Value */
21 memcpy(buffer + 3, string, atoi(newlen)); 21 memcpy(buffer + 3, string, atoi(newlen));
22 22
23 /* Return length of attached field */ 23 /* Return length of attached field */
24 return (atoi(newlen) + 3); 24 return (atoi(newlen) + 3);
25} 25}
26 26
27int get_field(const char *buffer, char *out) 27int get_field(const char *buffer, char *out)
28{ 28{
29 char len[5]; 29 char len[5];
30 30
31 /* Get length of value */ 31 /* Get length of value */
32 memcpy(len, buffer, 3); 32 memcpy(len, buffer, 3);
33 33
34 /* Copy buffer to out pointer */ 34 /* Copy buffer to out pointer */
35 memset(out, 0, atoi(len) + 1); 35 memset(out, 0, atoi(len) + 1);
36 memcpy(out, buffer + 3, atoi(len)); 36 memcpy(out, buffer + 3, atoi(len));
37 37
38 /* Return length of whole field (including 3 byte length) */ 38 /* Return length of whole field (including 3 byte length) */
39 return (atoi(len) + 3); 39 return (atoi(len) + 3);
40} 40}
41 41
42/* Send found network to UI */ 42/* Send found network to UI */
43int send_network_found (const char *guihost, int guiport, void *structure) 43int send_network_found (const char *guihost, int guiport, void *structure)
44{ 44{
45 wl_network_t *ptr; 45 wl_network_t *ptr;
46 char buffer[2048]; 46 char buffer[2048], temp[5];
47 char temp[128]; 47 int len = 0;
48 int retval=0, len=0;
49
50 memset(temp, 0, sizeof(temp));
51 48
52 ptr = (wl_network_t *)structure; 49 ptr = (wl_network_t *)structure;
53 50
54 /* Type = Found new net (without length field) */ 51 /* Type = Found new net (without length field) */
55 memset(temp, 0, sizeof(temp)); 52 memset(temp, 0, sizeof(temp));
56 snprintf(temp, sizeof(temp), "%.2d", NETFOUND); 53 snprintf(temp, sizeof(temp), "%.2d", NETFOUND);
57 memcpy(buffer, temp, 2); 54 memcpy(buffer, temp, 2);
58 len += 2; 55 len += 2;
59 56
60 /* Set Net-type */ 57 /* Set Net-type */
61 memset(temp, 0, sizeof(temp)); 58 memset(temp, 0, sizeof(temp));
62 snprintf(temp, sizeof(temp), "%d", ptr->net_type); 59 snprintf(temp, sizeof(temp), "%d", ptr->net_type);
63 retval = add_field(buffer + len, temp, 1); 60 len += add_field(buffer + len, temp, 1);
64 len += retval;
65 61
66 /* Set channel */ 62 /* Set channel */
67 memset(temp, 0, sizeof(temp)); 63 memset(temp, 0, sizeof(temp));
68 snprintf(temp, sizeof(temp), "%.2d", ptr->channel); 64 snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
69 retval = add_field(buffer + len, temp, 2); 65 len += add_field(buffer + len, temp, 2);
70 len += retval;
71 66
72 /* Set WEP y/n */ 67 /* Set WEP y/n */
73 memset(temp, 0, sizeof(temp)); 68 memset(temp, 0, sizeof(temp));
74 snprintf(temp, sizeof(temp), "%d", ptr->wep); 69 snprintf(temp, sizeof(temp), "%d", ptr->wep);
75 retval = add_field(buffer + len, temp, 1); 70 len += add_field(buffer + len, temp, 1);
76 len += retval;
77 71
78 /* Set Mac */ 72 /* Set Mac */
79 retval = add_field(buffer + len, ptr->mac, 17); 73 len += add_field(buffer + len, ptr->mac, 17);
80 len += retval;
81 74
82 /* Set ssid */ 75 /* Set ssid */
83 retval = add_field(buffer + len, ptr->bssid, ptr->ssid_len); 76 if(len + ptr->ssid_len < sizeof(buffer) - 1)
77 len += add_field(buffer + len, ptr->bssid, ptr->ssid_len);
78 else
79 len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1);
84 80
85 /* Send prepared buffer to UI */ 81 /* Send prepared buffer to UI */
86#ifdef DEBUG 82#ifdef DEBUG
87 wl_loginfo("Sending network to UI: '%s'", buffer); 83 wl_loginfo("Sending network to UI: '%s'", buffer);
88#endif 84#endif
89 85
90 return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); 86 return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
91} 87}
92 88
93/* Fill buffer into structur */ 89/* Fill buffer into structur */
94int get_network_found (void *structure, const char *buffer) 90int get_network_found (void *structure, const char *buffer)
95{ 91{
96 wl_network_t *ptr; 92 wl_network_t *ptr;
97 char temp[512]; 93 char temp[5];
98 int retval=0, len=0; 94 int len = 0;
99 95
100 ptr = (wl_network_t *)structure; 96 ptr = (wl_network_t *)structure;
101 97
102 /* packet type already determined */ 98 /* packet type already determined, skip check */
103 len += 2; 99 len += 2;
104 100
105 /* Get net type */ 101 /* Get net type (accesspoint || ad-hoc || ...) */
106 memset(temp, 0, sizeof(temp)); 102 memset(temp, 0, sizeof(temp));
107 retval = get_field(buffer + len, temp); 103 len += get_field(buffer + len, temp);
108 len += retval;
109 ptr->net_type = atoi(temp); 104 ptr->net_type = atoi(temp);
110 105
111 /* Get channel */ 106 /* Get channel */
112 memset(temp, 0, sizeof(temp)); 107 memset(temp, 0, sizeof(temp));
113 retval = get_field(buffer + len, temp); 108 len += get_field(buffer + len, temp);
114 len += retval;
115 ptr->channel = atoi(temp); 109 ptr->channel = atoi(temp);
116 110
117 /* Set WEP y/n */ 111 /* Set WEP y/n */
118 memset(temp, 0, sizeof(temp)); 112 memset(temp, 0, sizeof(temp));
119 retval = get_field(buffer + len, temp); 113 len += get_field(buffer + len, temp);
120 len += retval;
121 ptr->wep = atoi(temp); 114 ptr->wep = atoi(temp);
122 115
123 /* Set MAC address */ 116 /* Set MAC address */
124 retval = get_field(buffer + len, ptr->mac); 117 len += get_field(buffer + len, ptr->mac);
125 len += retval;
126 118
127 /* Set BSSID */ 119 /* Set BSSID */
128 retval = get_field(buffer + len, ptr->bssid); 120 len += get_field(buffer + len, ptr->bssid);
129 121
130 return 1; 122 return 1;
131} 123}
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
index f755589..a196091 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
@@ -1,28 +1,28 @@
1/* $Id$ */ 1/* $Id$ */
2 2
3#ifndef WLPROTO_HH 3#ifndef WLPROTO_HH
4#define WLPROTO_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
16int send_network_found (const char *, int, void *); 16int send_network_found (const char *, int, void *);
17int get_network_found (void *, const char *); 17int get_network_found (void *, const char *);
18 18
19typedef struct { 19typedef 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 Net */
26} wl_network_t; 26} wl_network_t;
27 27
28#endif /* WLPROTO_HH */ 28#endif /* WLPROTO_HH */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
index 4942fba..db6b7b8 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_sock.cc
@@ -1,91 +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 "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)
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 */
38int wl_send(const char *host, int port, const char *string, ...) 38int 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 0; 59 return 0;
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 0;
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 1;
73} 73}
74 74
75/* Check for new messages on commsock */ 75/* Check for new messages on commsock */
76int wl_recv(int *sock, char *out, int maxlen) 76int 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 retval[3]; 80 char retval[3];
81 81
82 memset(out, 0, maxlen); 82 memset(out, 0, maxlen);
83 if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0) 83 if(recvfrom(*sock, out, maxlen - 1, 0, (struct sockaddr *)cliaddr, &len) < 0)
84 return -1; 84 return -1;
85 85
86 /* Get packet type and return it */ 86 /* Get packet type and return it */
87 memset(retval, 0, sizeof(retval)); 87 memset(retval, 0, sizeof(retval));
88 memcpy(retval, out, 2); 88 memcpy(retval, out, 2);
89 89
90 return atoi(retval); 90 return atoi(retval);
91} 91}