author | mjm <mjm> | 2003-02-27 19:32:08 (UTC) |
---|---|---|
committer | mjm <mjm> | 2003-02-27 19:32:08 (UTC) |
commit | 18c19111466e43e91678c5a1fa50f2f561ca3257 (patch) (unidiff) | |
tree | 9f76492a3e0351a5914ada95c68fed169f3a6a29 | |
parent | fca225e970ebb629c4ac79020248a860a651bd85 (diff) | |
download | opie-18c19111466e43e91678c5a1fa50f2f561ca3257.zip opie-18c19111466e43e91678c5a1fa50f2f561ca3257.tar.gz opie-18c19111466e43e91678c5a1fa50f2f561ca3257.tar.bz2 |
fixed typo
-rw-r--r-- | noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc index dcdc16b..6c3846f 100644 --- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc +++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc | |||
@@ -1,221 +1,221 @@ | |||
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_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 */ |
13 | unsigned int add_field(char *buffer, const char *string, int len) | 13 | unsigned 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); |
20 | memcpy(buffer, newlen, 3); | 20 | memcpy(buffer, newlen, 3); |
21 | 21 | ||
22 | /* Length bytes = Value */ | 22 | /* Length bytes = Value */ |
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 | ||
29 | unsigned int get_field(const char *buffer, char *out, int maxlen) | 29 | unsigned 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); |
36 | 36 | ||
37 | /* Copy buffer to out pointer */ | 37 | /* Copy buffer to out pointer */ |
38 | memset(out, 0, maxlen); | 38 | memset(out, 0, maxlen); |
39 | if(atoi(len) > maxlen -1) | 39 | if(atoi(len) > maxlen -1) |
40 | memcpy(out, buffer + 3, maxlen - 1); | 40 | memcpy(out, buffer + 3, maxlen - 1); |
41 | else | 41 | else |
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 */ | 48 | /* Send ok message */ |
49 | int send_ok(const char *guihost, int guiport, int code) | 49 | int send_ok(const char *guihost, int guiport, int code) |
50 | { | 50 | { |
51 | unsigned int len = 0; | 51 | unsigned int len = 0; |
52 | char buffer[128], temp[5]; | 52 | char buffer[128], temp[5]; |
53 | 53 | ||
54 | memset(buffer, 0, sizeof(buffer)); | 54 | memset(buffer, 0, sizeof(buffer)); |
55 | 55 | ||
56 | memset(temp, 0, sizeof(temp)); | 56 | memset(temp, 0, sizeof(temp)); |
57 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_OK); | 57 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_OK); |
58 | memcpy(buffer, temp, 2); | 58 | memcpy(buffer, temp, 2); |
59 | len += 2; | 59 | len += 2; |
60 | 60 | ||
61 | memset(temp, 0, sizeof(temp)); | 61 | memset(temp, 0, sizeof(temp)); |
62 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); | 62 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); |
63 | len += add_field(buffer + len, temp, 2); | 63 | len += add_field(buffer + len, temp, 2); |
64 | 64 | ||
65 | /* Send prepared buffer to UI */ | 65 | /* Send prepared buffer to UI */ |
66 | #ifdef DEBUG | 66 | #ifdef DEBUG |
67 | wl_loginfo("Sent ok to UI: '%s'", buffer); | 67 | wl_loginfo("Sent ok to UI: '%s'", buffer); |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | 70 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); |
71 | } | 71 | } |
72 | 72 | ||
73 | /* Send fail message */ | 73 | /* Send fail message */ |
74 | int send_fail(const char *guihost, int guiport, | 74 | int send_fail(const char *guihost, int guiport, |
75 | int code, const char *errstr) | 75 | int code, const char *errstr) |
76 | { | 76 | { |
77 | unsigned int len = 0; | 77 | unsigned int len = 0; |
78 | char buffer[128], temp[5]; | 78 | char buffer[128], temp[5]; |
79 | 79 | ||
80 | memset(buffer, 0, sizeof(buffer)); | 80 | memset(buffer, 0, sizeof(buffer)); |
81 | 81 | ||
82 | memset(temp, 0, sizeof(temp)); | 82 | memset(temp, 0, sizeof(temp)); |
83 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_FAIL); | 83 | snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_FAIL); |
84 | memcpy(buffer, temp, 2); | 84 | memcpy(buffer, temp, 2); |
85 | len += 2; | 85 | len += 2; |
86 | 86 | ||
87 | memset(temp, 0, sizeof(temp)); | 87 | memset(temp, 0, sizeof(temp)); |
88 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); | 88 | snprintf(temp, sizeof(temp) - 1, "%.2d", code); |
89 | len += add_field(buffer + len, temp, 2); | 89 | len += add_field(buffer + len, temp, 2); |
90 | 90 | ||
91 | len += add_field(buffer + len, errstr, strlen(errstr)); | 91 | len += add_field(buffer + len, errstr, strlen(errstr)); |
92 | 92 | ||
93 | /* Send prepared buffer to UI */ | 93 | /* Send prepared buffer to UI */ |
94 | #ifdef DEBUG | 94 | #ifdef DEBUG |
95 | wl_loginfo("Send CMD_FAIL to UI: '%s'", buffer); | 95 | wl_loginfo("Send CMD_FAIL to UI: '%s'", buffer); |
96 | #endif | 96 | #endif |
97 | 97 | ||
98 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | 98 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); |
99 | } | 99 | } |
100 | 100 | ||
101 | int get_ok(const char *buffer) | 101 | int get_ok(const char *buffer) |
102 | { | 102 | { |
103 | char temp[5]; | 103 | char temp[5]; |
104 | unsigned int len = 0; | 104 | unsigned int len = 0; |
105 | 105 | ||
106 | /* packet type already determined, skip check */ | 106 | /* packet type already determined, skip check */ |
107 | len += 2; | 107 | len += 2; |
108 | 108 | ||
109 | /* what is ok for? */ | 109 | /* what is ok for? */ |
110 | memset(temp, 0, sizeof(temp)); | 110 | memset(temp, 0, sizeof(temp)); |
111 | len += get_field(buffer + len, temp, sizeof(temp)); | 111 | len += get_field(buffer + len, temp, sizeof(temp)); |
112 | 112 | ||
113 | return atoi(temp); | 113 | return atoi(temp); |
114 | } | 114 | } |
115 | 115 | ||
116 | /* put failmessage into buffer */ | 116 | /* put failmessage into buffer */ |
117 | int get_fail(char *out, const char *buffer, size_t len) | 117 | int get_fail(char *out, const char *buffer, size_t bufflen) |
118 | { | 118 | { |
119 | char temp[5]; | 119 | char temp[5]; |
120 | int error=0; | 120 | int error=0; |
121 | unsigned int len = 0; | 121 | unsigned int len = 0; |
122 | 122 | ||
123 | /* packet type already determined, skip check */ | 123 | /* packet type already determined, skip check */ |
124 | len += 2; | 124 | len += 2; |
125 | 125 | ||
126 | /* what is fail for? */ | 126 | /* what is fail for? */ |
127 | memset(temp, 0, sizeof(temp)); | 127 | memset(temp, 0, sizeof(temp)); |
128 | len += get_field(buffer + len, temp, sizeof(temp)); | 128 | len += get_field(buffer + len, temp, sizeof(temp)); |
129 | error=atoi(temp); | 129 | error=atoi(temp); |
130 | 130 | ||
131 | /* get errorstring and fill into buffer */ | 131 | /* get errorstring and fill into buffer */ |
132 | memset(out, 0, len); | 132 | memset(out, 0, bufflen); |
133 | len += get_field(buffer + len, out, len - 1); | 133 | len += get_field(buffer + len, out, bufflen - 1); |
134 | 134 | ||
135 | return error; | 135 | return error; |
136 | } | 136 | } |
137 | 137 | ||
138 | 138 | ||
139 | /* Send found network to UI */ | 139 | /* Send found network to UI */ |
140 | int send_network_found (const char *guihost, int guiport, void *structure) | 140 | int send_network_found (const char *guihost, int guiport, void *structure) |
141 | { | 141 | { |
142 | wl_network_t *ptr; | 142 | wl_network_t *ptr; |
143 | char buffer[2048], temp[5]; | 143 | char buffer[2048], temp[5]; |
144 | unsigned int len = 0; | 144 | unsigned int len = 0; |
145 | 145 | ||
146 | ptr = (wl_network_t *)structure; | 146 | ptr = (wl_network_t *)structure; |
147 | 147 | ||
148 | memset(buffer,0,sizeof(buffer)); | 148 | memset(buffer,0,sizeof(buffer)); |
149 | /* Type = Found new net (without length field) */ | 149 | /* Type = Found new net (without length field) */ |
150 | memset(temp, 0, sizeof(temp)); | 150 | memset(temp, 0, sizeof(temp)); |
151 | snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND); | 151 | snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND); |
152 | memcpy(buffer, temp, 2); | 152 | memcpy(buffer, temp, 2); |
153 | len += 2; | 153 | len += 2; |
154 | 154 | ||
155 | /* Set Net-type */ | 155 | /* Set Net-type */ |
156 | memset(temp, 0, sizeof(temp)); | 156 | memset(temp, 0, sizeof(temp)); |
157 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type); | 157 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type); |
158 | len += add_field(buffer + len, temp, 1); | 158 | len += add_field(buffer + len, temp, 1); |
159 | 159 | ||
160 | /* Set channel */ | 160 | /* Set channel */ |
161 | memset(temp, 0, sizeof(temp)); | 161 | memset(temp, 0, sizeof(temp)); |
162 | snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel); | 162 | snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel); |
163 | len += add_field(buffer + len, temp, 2); | 163 | len += add_field(buffer + len, temp, 2); |
164 | 164 | ||
165 | /* Set WEP y/n */ | 165 | /* Set WEP y/n */ |
166 | memset(temp, 0, sizeof(temp)); | 166 | memset(temp, 0, sizeof(temp)); |
167 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep); | 167 | snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep); |
168 | len += add_field(buffer + len, temp, 1); | 168 | len += add_field(buffer + len, temp, 1); |
169 | 169 | ||
170 | /* Set Mac */ | 170 | /* Set Mac */ |
171 | len += add_field(buffer + len, ptr->mac, 17); | 171 | len += add_field(buffer + len, ptr->mac, 17); |
172 | 172 | ||
173 | /* Set ssid */ | 173 | /* Set ssid */ |
174 | if(len + ptr->ssid_len < sizeof(buffer) - 1) | 174 | if(len + ptr->ssid_len < sizeof(buffer) - 1) |
175 | len += add_field(buffer + len, ptr->bssid, ptr->ssid_len); | 175 | len += add_field(buffer + len, ptr->bssid, ptr->ssid_len); |
176 | else | 176 | else |
177 | len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1); | 177 | len += add_field(buffer + len, ptr->bssid, sizeof(buffer) - len - 1); |
178 | 178 | ||
179 | /* Send prepared buffer to UI */ | 179 | /* Send prepared buffer to UI */ |
180 | #ifdef DEBUG | 180 | #ifdef DEBUG |
181 | wl_loginfo("Sending network to UI: '%s'", buffer); | 181 | wl_loginfo("Sending network to UI: '%s'", buffer); |
182 | #endif | 182 | #endif |
183 | 183 | ||
184 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); | 184 | return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1); |
185 | } | 185 | } |
186 | 186 | ||
187 | /* Fill buffer into structur */ | 187 | /* Fill buffer into structur */ |
188 | int get_network_found (void *structure, const char *buffer) | 188 | int get_network_found (void *structure, const char *buffer) |
189 | { | 189 | { |
190 | wl_network_t *ptr; | 190 | wl_network_t *ptr; |
191 | char temp[5]; | 191 | char temp[5]; |
192 | unsigned int len = 0; | 192 | unsigned int len = 0; |
193 | 193 | ||
194 | ptr = (wl_network_t *)structure; | 194 | ptr = (wl_network_t *)structure; |
195 | 195 | ||
196 | /* packet type already determined, skip check */ | 196 | /* packet type already determined, skip check */ |
197 | len += 2; | 197 | len += 2; |
198 | 198 | ||
199 | /* Get net type (accesspoint || ad-hoc || ...) */ | 199 | /* Get net type (accesspoint || ad-hoc || ...) */ |
200 | memset(temp, 0, sizeof(temp)); | 200 | memset(temp, 0, sizeof(temp)); |
201 | len += get_field(buffer + len, temp, sizeof(temp)); | 201 | len += get_field(buffer + len, temp, sizeof(temp)); |
202 | ptr->net_type = atoi(temp); | 202 | ptr->net_type = atoi(temp); |
203 | 203 | ||
204 | /* Get channel */ | 204 | /* Get channel */ |
205 | memset(temp, 0, sizeof(temp)); | 205 | memset(temp, 0, sizeof(temp)); |
206 | len += get_field(buffer + len, temp, sizeof(temp)); | 206 | len += get_field(buffer + len, temp, sizeof(temp)); |
207 | ptr->channel = atoi(temp); | 207 | ptr->channel = atoi(temp); |
208 | 208 | ||
209 | /* Set WEP y/n */ | 209 | /* Set WEP y/n */ |
210 | memset(temp, 0, sizeof(temp)); | 210 | memset(temp, 0, sizeof(temp)); |
211 | len += get_field(buffer + len, temp, sizeof(temp)); | 211 | len += get_field(buffer + len, temp, sizeof(temp)); |
212 | ptr->wep = atoi(temp); | 212 | ptr->wep = atoi(temp); |
213 | 213 | ||
214 | /* Set MAC address */ | 214 | /* Set MAC address */ |
215 | len += get_field(buffer + len, ptr->mac, sizeof(ptr->mac)); | 215 | len += get_field(buffer + len, ptr->mac, sizeof(ptr->mac)); |
216 | 216 | ||
217 | /* Set BSSID */ | 217 | /* Set BSSID */ |
218 | len += get_field(buffer + len, ptr->bssid, sizeof(ptr->bssid)); | 218 | len += get_field(buffer + len, ptr->bssid, sizeof(ptr->bssid)); |
219 | 219 | ||
220 | return 1; | 220 | return 1; |
221 | } | 221 | } |