summaryrefslogtreecommitdiff
authormjm <mjm>2003-02-26 22:28:06 (UTC)
committer mjm <mjm>2003-02-26 22:28:06 (UTC)
commit7659b28b02edb05de0d4c7cf2a3021c005fb63fe (patch) (unidiff)
tree1c0c5d047452dfc82bad01a7ce763490d18a7bc2
parented168abe1c9c1384b0151ea9b49a7e364f9b67be (diff)
downloadopie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.zip
opie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.tar.gz
opie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.tar.bz2
added send_fail/send_ok/get_fail/get_ok.
fixed some bufferproblems
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc103
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh14
2 files changed, 107 insertions, 10 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
index 0d0f075..dcdc16b 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -7,13 +7,13 @@
7#include "wl_types.hh" 7#include "wl_types.hh"
8#include "wl_proto.hh" 8#include "wl_proto.hh"
9#include "wl_log.hh" 9#include "wl_log.hh"
10#include "wl_sock.hh" 10#include "wl_sock.hh"
11 11
12/* Adds a field to the buffer */ 12/* Adds a field to the buffer */
13int add_field(char *buffer, const char *string, int len) 13unsigned int add_field(char *buffer, const char *string, int len)
14{ 14{
15 char newlen[5]; 15 char newlen[5];
16 16
17 /* 3 Byte = Length */ 17 /* 3 Byte = Length */
18 memset(newlen, 0, sizeof(newlen)); 18 memset(newlen, 0, sizeof(newlen));
19 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len); 19 snprintf(newlen, sizeof(newlen) - 1, "%.3d", len);
@@ -23,13 +23,13 @@ int add_field(char *buffer, const char *string, int len)
23 memcpy(buffer + 3, string, atoi(newlen)); 23 memcpy(buffer + 3, string, atoi(newlen));
24 24
25 /* Return length of attached field */ 25 /* Return length of attached field */
26 return (atoi(newlen) + 3); 26 return (atoi(newlen) + 3);
27} 27}
28 28
29int get_field(const char *buffer, char *out, int maxlen) 29unsigned int get_field(const char *buffer, char *out, int maxlen)
30{ 30{
31 char len[5]; 31 char len[5];
32 32
33 /* Get length of value */ 33 /* Get length of value */
34 memset(len, 0, sizeof(len)); 34 memset(len, 0, sizeof(len));
35 memcpy(len, buffer, 3); 35 memcpy(len, buffer, 3);
@@ -42,41 +42,132 @@ int get_field(const char *buffer, char *out, int maxlen)
42 memcpy(out, buffer + 3, atoi(len)); 42 memcpy(out, buffer + 3, atoi(len));
43 43
44 /* Return length of whole field (including 3 byte length) */ 44 /* Return length of whole field (including 3 byte length) */
45 return (atoi(len) + 3); 45 return (atoi(len) + 3);
46} 46}
47 47
48/* Send ok message */
49int send_ok(const char *guihost, int guiport, int code)
50{
51 unsigned int len = 0;
52 char buffer[128], temp[5];
53
54 memset(buffer, 0, sizeof(buffer));
55
56 memset(temp, 0, sizeof(temp));
57 snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_OK);
58 memcpy(buffer, temp, 2);
59 len += 2;
60
61 memset(temp, 0, sizeof(temp));
62 snprintf(temp, sizeof(temp) - 1, "%.2d", code);
63 len += add_field(buffer + len, temp, 2);
64
65 /* Send prepared buffer to UI */
66#ifdef DEBUG
67 wl_loginfo("Sent ok to UI: '%s'", buffer);
68#endif
69
70 return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
71}
72
73/* Send fail message */
74int send_fail(const char *guihost, int guiport,
75 int code, const char *errstr)
76{
77 unsigned int len = 0;
78 char buffer[128], temp[5];
79
80 memset(buffer, 0, sizeof(buffer));
81
82 memset(temp, 0, sizeof(temp));
83 snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_FAIL);
84 memcpy(buffer, temp, 2);
85 len += 2;
86
87 memset(temp, 0, sizeof(temp));
88 snprintf(temp, sizeof(temp) - 1, "%.2d", code);
89 len += add_field(buffer + len, temp, 2);
90
91 len += add_field(buffer + len, errstr, strlen(errstr));
92
93 /* Send prepared buffer to UI */
94#ifdef DEBUG
95 wl_loginfo("Send CMD_FAIL to UI: '%s'", buffer);
96#endif
97
98 return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
99}
100
101int get_ok(const char *buffer)
102{
103 char temp[5];
104 unsigned int len = 0;
105
106 /* packet type already determined, skip check */
107 len += 2;
108
109 /* what is ok for? */
110 memset(temp, 0, sizeof(temp));
111 len += get_field(buffer + len, temp, sizeof(temp));
112
113 return atoi(temp);
114}
115
116/* put failmessage into buffer */
117int get_fail(char *out, const char *buffer, size_t len)
118{
119 char temp[5];
120 int error=0;
121 unsigned int len = 0;
122
123 /* packet type already determined, skip check */
124 len += 2;
125
126 /* what is fail for? */
127 memset(temp, 0, sizeof(temp));
128 len += get_field(buffer + len, temp, sizeof(temp));
129 error=atoi(temp);
130
131 /* get errorstring and fill into buffer */
132 memset(out, 0, len);
133 len += get_field(buffer + len, out, len - 1);
134
135 return error;
136}
137
138
48/* Send found network to UI */ 139/* Send found network to UI */
49int send_network_found (const char *guihost, int guiport, void *structure) 140int send_network_found (const char *guihost, int guiport, void *structure)
50{ 141{
51 wl_network_t *ptr; 142 wl_network_t *ptr;
52 char buffer[2048], temp[5]; 143 char buffer[2048], temp[5];
53 unsigned int len = 0; 144 unsigned int len = 0;
54 145
55 ptr = (wl_network_t *)structure; 146 ptr = (wl_network_t *)structure;
56 147
57 memset(buffer,0,sizeof(buffer)); 148 memset(buffer,0,sizeof(buffer));
58 /* Type = Found new net (without length field) */ 149 /* Type = Found new net (without length field) */
59 memset(temp, 0, sizeof(temp)); 150 memset(temp, 0, sizeof(temp));
60 snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND); 151 snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND);
61 memcpy(buffer, temp, 2); 152 memcpy(buffer, temp, 2);
62 len += 2; 153 len += 2;
63 154
64 /* Set Net-type */ 155 /* Set Net-type */
65 memset(temp, 0, sizeof(temp)); 156 memset(temp, 0, sizeof(temp));
66 snprintf(temp, sizeof(temp), "%d", ptr->net_type); 157 snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type);
67 len += add_field(buffer + len, temp, 1); 158 len += add_field(buffer + len, temp, 1);
68 159
69 /* Set channel */ 160 /* Set channel */
70 memset(temp, 0, sizeof(temp)); 161 memset(temp, 0, sizeof(temp));
71 snprintf(temp, sizeof(temp), "%.2d", ptr->channel); 162 snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel);
72 len += add_field(buffer + len, temp, 2); 163 len += add_field(buffer + len, temp, 2);
73 164
74 /* Set WEP y/n */ 165 /* Set WEP y/n */
75 memset(temp, 0, sizeof(temp)); 166 memset(temp, 0, sizeof(temp));
76 snprintf(temp, sizeof(temp), "%d", ptr->wep); 167 snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep);
77 len += add_field(buffer + len, temp, 1); 168 len += add_field(buffer + len, temp, 1);
78 169
79 /* Set Mac */ 170 /* Set Mac */
80 len += add_field(buffer + len, ptr->mac, 17); 171 len += add_field(buffer + len, ptr->mac, 17);
81 172
82 /* Set ssid */ 173 /* Set ssid */
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
index 46ef8e5..63ac53b 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
@@ -5,17 +5,23 @@
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 CMD_FAIL 50
14#define CMD_OK 51
13#define STARTSNIFF 98 15#define STARTSNIFF 98
14#define STOPSNIFF 99 16#define STOPSNIFF 99
15 17
16int add_field(char *, const char *, int); 18unsigned int add_field(char *, const char *, int);
17int get_field(const char *, char *, int); 19unsigned int get_field(const char *, char *, int);
20int send_ok(const char *, int, int);
21int get_ok(const char *);
22int send_fail(const char *, int, int, const char *);
23int get_fail(char *, const char *, size_t);
18int send_network_found (const char *, int, void *); 24int send_network_found (const char *, int, void *);
19int get_network_found (void *, const char *); 25int get_network_found (void *, const char *);
20 26
21#endif /* WLPROTO_HH */ 27#endif /* WLPROTO_HH */