diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-27 07:55:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-27 07:55:41 +0000 |
commit | adc9d89e46ab3f331fbba30298b2c569a5de14e4 (patch) | |
tree | 35b034be35db39debf2d2eba7abcaf8a9d87dd64 | |
parent | 64dfbc851ed2d2f65b1b04b66e94087f51d5889f (diff) | |
download | gnunet-adc9d89e46ab3f331fbba30298b2c569a5de14e4.tar.gz gnunet-adc9d89e46ab3f331fbba30298b2c569a5de14e4.zip |
unix
-rw-r--r-- | src/transport/test_plugin_transport_wlan_dummy.c | 924 |
1 files changed, 462 insertions, 462 deletions
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c index 21cc74aa2..71fcd29cf 100644 --- a/src/transport/test_plugin_transport_wlan_dummy.c +++ b/src/transport/test_plugin_transport_wlan_dummy.c | |||
@@ -1,465 +1,465 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010 Christian Grothoff (and other contributing authors) | 3 | (C) 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation; either version 3, or (at your |
8 | option) any later version. | 8 | option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | General Public License for more details. | 13 | General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with GNUnet; see the file COPYING. If not, write to the |
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_wlan_dummy.c | 21 | * @file transport/test_transport_wlan_dummy.c |
22 | * @brief helper for the testcases for plugin_transport_wlan.c | 22 | * @brief helper for the testcases for plugin_transport_wlan.c |
23 | * @author David Brodski | 23 | * @author David Brodski |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #include <sys/socket.h> | 26 | #include <sys/socket.h> |
27 | #include <sys/ioctl.h> | 27 | #include <sys/ioctl.h> |
28 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/wait.h> | 29 | #include <sys/wait.h> |
30 | #include <sys/time.h> | 30 | #include <sys/time.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #include <stdio.h> | 32 | #include <stdio.h> |
33 | #include <stdlib.h> | 33 | #include <stdlib.h> |
34 | 34 | ||
35 | #include <errno.h> | 35 | #include <errno.h> |
36 | #include <resolv.h> | 36 | #include <resolv.h> |
37 | #include <string.h> | 37 | #include <string.h> |
38 | #include <utime.h> | 38 | #include <utime.h> |
39 | #include <unistd.h> | 39 | #include <unistd.h> |
40 | #include <getopt.h> | 40 | #include <getopt.h> |
41 | 41 | ||
42 | #include "platform.h" | 42 | #include "platform.h" |
43 | #include "gnunet_constants.h" | 43 | #include "gnunet_constants.h" |
44 | #include "gnunet_os_lib.h" | 44 | #include "gnunet_os_lib.h" |
45 | #include "gnunet_transport_plugin.h" | 45 | #include "gnunet_transport_plugin.h" |
46 | #include "transport.h" | 46 | #include "transport.h" |
47 | #include "gnunet_util_lib.h" | 47 | #include "gnunet_util_lib.h" |
48 | #include "plugin_transport_wlan.h" | 48 | #include "plugin_transport_wlan.h" |
49 | #include "gnunet_common.h" | 49 | #include "gnunet_common.h" |
50 | #include "gnunet-transport-wlan-helper.h" | 50 | #include "gnunet-transport-wlan-helper.h" |
51 | #include "gnunet_crypto_lib.h" | 51 | #include "gnunet_crypto_lib.h" |
52 | #include "wlan/loopback_helper.h" | 52 | #include "wlan/loopback_helper.h" |
53 | #include "wlan/helper_common.h" | 53 | #include "wlan/helper_common.h" |
54 | 54 | ||
55 | int first; | 55 | int first; |
56 | 56 | ||
57 | static void | 57 | static void |
58 | sigfunc(int sig) | 58 | sigfunc(int sig) |
59 | { | 59 | { |
60 | closeprog = 1; | 60 | closeprog = 1; |
61 | unlink(FIFO_FILE1); | 61 | unlink(FIFO_FILE1); |
62 | unlink(FIFO_FILE2); | 62 | unlink(FIFO_FILE2); |
63 | } | 63 | } |
64 | 64 | ||
65 | static void | 65 | static void |
66 | stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 66 | stdin_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
67 | { | 67 | { |
68 | struct sendbuf *write_pout = cls; | 68 | struct sendbuf *write_pout = cls; |
69 | int sendsize; | 69 | int sendsize; |
70 | struct GNUNET_MessageHeader newheader; | 70 | struct GNUNET_MessageHeader newheader; |
71 | unsigned char * from_data; | 71 | unsigned char * from_data; |
72 | unsigned char * to_data; | 72 | unsigned char * to_data; |
73 | //unsigned char * from_radiotap; | 73 | //unsigned char * from_radiotap; |
74 | unsigned char * to_radiotap; | 74 | unsigned char * to_radiotap; |
75 | //unsigned char * from_start; | 75 | //unsigned char * from_start; |
76 | unsigned char * to_start; | 76 | unsigned char * to_start; |
77 | 77 | ||
78 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) | 78 | sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) |
79 | + sizeof(struct Radiotap_rx); | 79 | + sizeof(struct Radiotap_rx); |
80 | 80 | ||
81 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | 81 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) |
82 | { | 82 | { |
83 | fprintf(stderr, "Function stdin_send: wrong packet type\n"); | 83 | fprintf(stderr, "Function stdin_send: wrong packet type\n"); |
84 | exit(1); | 84 | exit(1); |
85 | } | 85 | } |
86 | if ((sendsize + write_pout->size) > MAXLINE * 2) | 86 | if ((sendsize + write_pout->size) > MAXLINE * 2) |
87 | { | 87 | { |
88 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); | 88 | fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); |
89 | exit(1); | 89 | exit(1); |
90 | } | 90 | } |
91 | 91 | ||
92 | newheader.size = htons(sendsize); | 92 | newheader.size = htons(sendsize); |
93 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); | 93 | newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); |
94 | 94 | ||
95 | to_start = write_pout->buf + write_pout->size; | 95 | to_start = write_pout->buf + write_pout->size; |
96 | to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); | 96 | to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); |
97 | to_data = to_radiotap + sizeof(struct Radiotap_rx); | 97 | to_data = to_radiotap + sizeof(struct Radiotap_rx); |
98 | 98 | ||
99 | from_data = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send) | 99 | from_data = ((unsigned char *) hdr) + sizeof(struct Radiotap_Send) |
100 | + sizeof(struct GNUNET_MessageHeader); | 100 | + sizeof(struct GNUNET_MessageHeader); |
101 | 101 | ||
102 | memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); | 102 | memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); |
103 | write_pout->size += sizeof(struct GNUNET_MessageHeader); | 103 | write_pout->size += sizeof(struct GNUNET_MessageHeader); |
104 | 104 | ||
105 | write_pout->size += sizeof(struct Radiotap_rx); | 105 | write_pout->size += sizeof(struct Radiotap_rx); |
106 | 106 | ||
107 | memcpy(to_data, from_data, ntohs(hdr->size) - sizeof(struct Radiotap_Send) | 107 | memcpy(to_data, from_data, ntohs(hdr->size) - sizeof(struct Radiotap_Send) |
108 | - sizeof(struct GNUNET_MessageHeader)); | 108 | - sizeof(struct GNUNET_MessageHeader)); |
109 | write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) | 109 | write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) |
110 | - sizeof(struct GNUNET_MessageHeader); | 110 | - sizeof(struct GNUNET_MessageHeader); |
111 | } | 111 | } |
112 | 112 | ||
113 | static void | 113 | static void |
114 | file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 114 | file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) |
115 | { | 115 | { |
116 | struct sendbuf * write_std = cls; | 116 | struct sendbuf * write_std = cls; |
117 | uint16_t sendsize; | 117 | uint16_t sendsize; |
118 | 118 | ||
119 | sendsize = ntohs(hdr->size); | 119 | sendsize = ntohs(hdr->size); |
120 | 120 | ||
121 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) | 121 | if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) |
122 | { | 122 | { |
123 | fprintf(stderr, "Function file_in_send: wrong packet type\n"); | 123 | fprintf(stderr, "Function file_in_send: wrong packet type\n"); |
124 | exit(1); | 124 | exit(1); |
125 | } | 125 | } |
126 | if ((sendsize + write_std->size) > MAXLINE * 2) | 126 | if ((sendsize + write_std->size) > MAXLINE * 2) |
127 | { | 127 | { |
128 | fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); | 128 | fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); |
129 | exit(1); | 129 | exit(1); |
130 | } | 130 | } |
131 | 131 | ||
132 | memcpy(write_std->buf + write_std->size, hdr, sendsize); | 132 | memcpy(write_std->buf + write_std->size, hdr, sendsize); |
133 | write_std->size += sendsize; | 133 | write_std->size += sendsize; |
134 | } | 134 | } |
135 | 135 | ||
136 | int closeprog; | 136 | int closeprog; |
137 | 137 | ||
138 | 138 | ||
139 | int | 139 | int |
140 | testmode(int argc, char *argv[]) | 140 | testmode(int argc, char *argv[]) |
141 | { | 141 | { |
142 | struct stat st; | 142 | struct stat st; |
143 | int erg; | 143 | int erg; |
144 | 144 | ||
145 | FILE *fpin = NULL; | 145 | FILE *fpin = NULL; |
146 | FILE *fpout = NULL; | 146 | FILE *fpout = NULL; |
147 | 147 | ||
148 | int fdpin; | 148 | int fdpin; |
149 | int fdpout; | 149 | int fdpout; |
150 | 150 | ||
151 | //make the fifos if needed | 151 | //make the fifos if needed |
152 | if (0 != stat(FIFO_FILE1, &st)) | 152 | if (0 != stat(FIFO_FILE1, &st)) |
153 | { | 153 | { |
154 | if (0 == stat(FIFO_FILE2, &st)) | 154 | if (0 == stat(FIFO_FILE2, &st)) |
155 | { | 155 | { |
156 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); | 156 | fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); |
157 | exit(1); | 157 | exit(1); |
158 | } | 158 | } |
159 | 159 | ||
160 | umask(0); | 160 | umask(0); |
161 | //unlink(FIFO_FILE1); | 161 | //unlink(FIFO_FILE1); |
162 | //unlink(FIFO_FILE2); | 162 | //unlink(FIFO_FILE2); |
163 | // FIXME: use mkfifo! | 163 | // FIXME: use mkfifo! |
164 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); | 164 | erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0); |
165 | if (0 != erg) | 165 | if (0 != erg) |
166 | { | 166 | { |
167 | fprintf(stderr, "Error at mknode1 \n"); | 167 | fprintf(stderr, "Error at mknode1 \n"); |
168 | //exit(1); | 168 | //exit(1); |
169 | } | 169 | } |
170 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); | 170 | erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0); |
171 | if (0 != erg) | 171 | if (0 != erg) |
172 | { | 172 | { |
173 | fprintf(stderr, "Error at mknode2 \n"); | 173 | fprintf(stderr, "Error at mknode2 \n"); |
174 | //exit(1); | 174 | //exit(1); |
175 | } | 175 | } |
176 | 176 | ||
177 | } | 177 | } |
178 | else | 178 | else |
179 | { | 179 | { |
180 | 180 | ||
181 | if (0 != stat(FIFO_FILE2, &st)) | 181 | if (0 != stat(FIFO_FILE2, &st)) |
182 | { | 182 | { |
183 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); | 183 | fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); |
184 | exit(1); | 184 | exit(1); |
185 | } | 185 | } |
186 | 186 | ||
187 | } | 187 | } |
188 | 188 | ||
189 | if (strstr(argv[1], "1")) | 189 | if (strstr(argv[1], "1")) |
190 | { | 190 | { |
191 | //fprintf(stderr, "First\n"); | 191 | //fprintf(stderr, "First\n"); |
192 | first = 1; | 192 | first = 1; |
193 | fpin = fopen(FIFO_FILE1, "r"); | 193 | fpin = fopen(FIFO_FILE1, "r"); |
194 | if (NULL == fpin) | 194 | if (NULL == fpin) |
195 | { | 195 | { |
196 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); | 196 | fprintf(stderr, "fopen of read FIFO_FILE1\n"); |
197 | goto end; | 197 | goto end; |
198 | } | 198 | } |
199 | fpout = fopen(FIFO_FILE2, "w"); | 199 | fpout = fopen(FIFO_FILE2, "w"); |
200 | if (NULL == fpout) | 200 | if (NULL == fpout) |
201 | { | 201 | { |
202 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); | 202 | fprintf(stderr, "fopen of write FIFO_FILE2\n"); |
203 | goto end; | 203 | goto end; |
204 | } | 204 | } |
205 | 205 | ||
206 | } | 206 | } |
207 | else | 207 | else |
208 | { | 208 | { |
209 | first = 0; | 209 | first = 0; |
210 | //fprintf(stderr, "Second\n"); | 210 | //fprintf(stderr, "Second\n"); |
211 | fpout = fopen(FIFO_FILE1, "w"); | 211 | fpout = fopen(FIFO_FILE1, "w"); |
212 | if (NULL == fpout) | 212 | if (NULL == fpout) |
213 | { | 213 | { |
214 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); | 214 | fprintf(stderr, "fopen of write FIFO_FILE1\n"); |
215 | goto end; | 215 | goto end; |
216 | } | 216 | } |
217 | fpin = fopen(FIFO_FILE2, "r"); | 217 | fpin = fopen(FIFO_FILE2, "r"); |
218 | if (NULL == fpin) | 218 | if (NULL == fpin) |
219 | { | 219 | { |
220 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); | 220 | fprintf(stderr, "fopen of read FIFO_FILE2\n"); |
221 | goto end; | 221 | goto end; |
222 | } | 222 | } |
223 | 223 | ||
224 | } | 224 | } |
225 | 225 | ||
226 | fdpin = fileno(fpin); | 226 | fdpin = fileno(fpin); |
227 | GNUNET_assert(fpin >= 0); | 227 | GNUNET_assert(fpin >= 0); |
228 | 228 | ||
229 | if (fdpin >= FD_SETSIZE) | 229 | if (fdpin >= FD_SETSIZE) |
230 | { | 230 | { |
231 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, | 231 | fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, |
232 | (unsigned int) FD_SETSIZE); | 232 | (unsigned int) FD_SETSIZE); |
233 | goto end; | 233 | goto end; |
234 | } | 234 | } |
235 | 235 | ||
236 | fdpout = fileno(fpout); | 236 | fdpout = fileno(fpout); |
237 | GNUNET_assert(fdpout >= 0 ); | 237 | GNUNET_assert(fdpout >= 0 ); |
238 | 238 | ||
239 | if (fdpout >= FD_SETSIZE) | 239 | if (fdpout >= FD_SETSIZE) |
240 | { | 240 | { |
241 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, | 241 | fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, |
242 | (unsigned int) FD_SETSIZE); | 242 | (unsigned int) FD_SETSIZE); |
243 | goto end; | 243 | goto end; |
244 | 244 | ||
245 | } | 245 | } |
246 | 246 | ||
247 | signal(SIGINT, &sigfunc); | 247 | signal(SIGINT, &sigfunc); |
248 | signal(SIGTERM, &sigfunc); | 248 | signal(SIGTERM, &sigfunc); |
249 | 249 | ||
250 | char readbuf[MAXLINE]; | 250 | char readbuf[MAXLINE]; |
251 | int readsize = 0; | 251 | int readsize = 0; |
252 | struct sendbuf write_std; | 252 | struct sendbuf write_std; |
253 | write_std.size = 0; | 253 | write_std.size = 0; |
254 | write_std.pos = 0; | 254 | write_std.pos = 0; |
255 | 255 | ||
256 | struct sendbuf write_pout; | 256 | struct sendbuf write_pout; |
257 | write_pout.size = 0; | 257 | write_pout.size = 0; |
258 | write_pout.pos = 0; | 258 | write_pout.pos = 0; |
259 | 259 | ||
260 | int ret = 0; | 260 | int ret = 0; |
261 | int maxfd = 0; | 261 | int maxfd = 0; |
262 | 262 | ||
263 | fd_set rfds; | 263 | fd_set rfds; |
264 | fd_set wfds; | 264 | fd_set wfds; |
265 | struct timeval tv; | 265 | struct timeval tv; |
266 | int retval; | 266 | int retval; |
267 | 267 | ||
268 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; | 268 | struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; |
269 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; | 269 | struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; |
270 | 270 | ||
271 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); | 271 | stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); |
272 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); | 272 | file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); |
273 | 273 | ||
274 | //send mac first | 274 | //send mac first |
275 | 275 | ||
276 | struct MacAddress macaddr; | 276 | struct MacAddress macaddr; |
277 | 277 | ||
278 | //Send random mac address | 278 | //Send random mac address |
279 | macaddr.mac[0] = 0x13; | 279 | macaddr.mac[0] = 0x13; |
280 | macaddr.mac[1] = 0x22; | 280 | macaddr.mac[1] = 0x22; |
281 | macaddr.mac[2] = 0x33; | 281 | macaddr.mac[2] = 0x33; |
282 | macaddr.mac[3] = 0x44; | 282 | macaddr.mac[3] = 0x44; |
283 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); | 283 | macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); |
284 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); | 284 | macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); |
285 | 285 | ||
286 | write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac); | 286 | write_std.size = send_mac_to_plugin((char *) write_std.buf, macaddr.mac); |
287 | 287 | ||
288 | while (0 == closeprog) | 288 | while (0 == closeprog) |
289 | { | 289 | { |
290 | 290 | ||
291 | maxfd = 0; | 291 | maxfd = 0; |
292 | 292 | ||
293 | //set timeout | 293 | //set timeout |
294 | tv.tv_sec = 5; | 294 | tv.tv_sec = 5; |
295 | tv.tv_usec = 0; | 295 | tv.tv_usec = 0; |
296 | 296 | ||
297 | FD_ZERO(&rfds); | 297 | FD_ZERO(&rfds); |
298 | // if output queue is empty | 298 | // if output queue is empty |
299 | if (0 == write_pout.size) | 299 | if (0 == write_pout.size) |
300 | { | 300 | { |
301 | FD_SET(STDIN_FILENO, &rfds); | 301 | FD_SET(STDIN_FILENO, &rfds); |
302 | 302 | ||
303 | } | 303 | } |
304 | if (0 == write_std.size) | 304 | if (0 == write_std.size) |
305 | { | 305 | { |
306 | FD_SET(fdpin, &rfds); | 306 | FD_SET(fdpin, &rfds); |
307 | maxfd = fdpin; | 307 | maxfd = fdpin; |
308 | } | 308 | } |
309 | FD_ZERO(&wfds); | 309 | FD_ZERO(&wfds); |
310 | // if there is something to write | 310 | // if there is something to write |
311 | if (0 < write_std.size) | 311 | if (0 < write_std.size) |
312 | { | 312 | { |
313 | FD_SET(STDOUT_FILENO, &wfds); | 313 | FD_SET(STDOUT_FILENO, &wfds); |
314 | maxfd = MAX(maxfd, STDOUT_FILENO); | 314 | maxfd = MAX(maxfd, STDOUT_FILENO); |
315 | } | 315 | } |
316 | 316 | ||
317 | if (0 < write_pout.size) | 317 | if (0 < write_pout.size) |
318 | { | 318 | { |
319 | FD_SET(fdpout, &wfds); | 319 | FD_SET(fdpout, &wfds); |
320 | maxfd = MAX(maxfd, fdpout); | 320 | maxfd = MAX(maxfd, fdpout); |
321 | } | 321 | } |
322 | 322 | ||
323 | retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); | 323 | retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); |
324 | 324 | ||
325 | if (-1 == retval && EINTR == errno) | 325 | if (-1 == retval && EINTR == errno) |
326 | { | 326 | { |
327 | continue; | 327 | continue; |
328 | } | 328 | } |
329 | if (0 > retval) | 329 | if (0 > retval) |
330 | { | 330 | { |
331 | fprintf(stderr, "select failed: %s\n", strerror(errno)); | 331 | fprintf(stderr, "select failed: %s\n", strerror(errno)); |
332 | closeprog = 1; | 332 | closeprog = 1; |
333 | break; | 333 | break; |
334 | } | 334 | } |
335 | 335 | ||
336 | if (FD_ISSET(STDOUT_FILENO, &wfds)) | 336 | if (FD_ISSET(STDOUT_FILENO, &wfds)) |
337 | { | 337 | { |
338 | ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, | 338 | ret = write(STDOUT_FILENO, write_std.buf + write_std.pos, |
339 | write_std.size - write_std.pos); | 339 | write_std.size - write_std.pos); |
340 | 340 | ||
341 | if (0 > ret) | 341 | if (0 > ret) |
342 | { | 342 | { |
343 | closeprog = 1; | 343 | closeprog = 1; |
344 | fprintf(stderr, "Write ERROR to STDOUT\n"); | 344 | fprintf(stderr, "Write ERROR to STDOUT\n"); |
345 | break; | 345 | break; |
346 | } | 346 | } |
347 | else | 347 | else |
348 | { | 348 | { |
349 | write_std.pos += ret; | 349 | write_std.pos += ret; |
350 | // check if finished | 350 | // check if finished |
351 | if (write_std.pos == write_std.size) | 351 | if (write_std.pos == write_std.size) |
352 | { | 352 | { |
353 | write_std.pos = 0; | 353 | write_std.pos = 0; |
354 | write_std.size = 0; | 354 | write_std.size = 0; |
355 | } | 355 | } |
356 | } | 356 | } |
357 | } | 357 | } |
358 | 358 | ||
359 | if (FD_ISSET(fdpout, &wfds)) | 359 | if (FD_ISSET(fdpout, &wfds)) |
360 | { | 360 | { |
361 | ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size | 361 | ret = write(fdpout, write_pout.buf + write_pout.pos, write_pout.size |
362 | - write_pout.pos); | 362 | - write_pout.pos); |
363 | 363 | ||
364 | if (0 > ret) | 364 | if (0 > ret) |
365 | { | 365 | { |
366 | closeprog = 1; | 366 | closeprog = 1; |
367 | fprintf(stderr, "Write ERROR to fdpout\n"); | 367 | fprintf(stderr, "Write ERROR to fdpout\n"); |
368 | } | 368 | } |
369 | else | 369 | else |
370 | { | 370 | { |
371 | write_pout.pos += ret; | 371 | write_pout.pos += ret; |
372 | // check if finished | 372 | // check if finished |
373 | if (write_pout.pos == write_pout.size) | 373 | if (write_pout.pos == write_pout.size) |
374 | { | 374 | { |
375 | write_pout.pos = 0; | 375 | write_pout.pos = 0; |
376 | write_pout.size = 0; | 376 | write_pout.size = 0; |
377 | } | 377 | } |
378 | } | 378 | } |
379 | } | 379 | } |
380 | 380 | ||
381 | if (FD_ISSET(STDIN_FILENO, &rfds)) | 381 | if (FD_ISSET(STDIN_FILENO, &rfds)) |
382 | { | 382 | { |
383 | readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); | 383 | readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); |
384 | 384 | ||
385 | if (0 > readsize) | 385 | if (0 > readsize) |
386 | { | 386 | { |
387 | closeprog = 1; | 387 | closeprog = 1; |
388 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); | 388 | fprintf(stderr, "Read ERROR to STDIN_FILENO\n"); |
389 | } | 389 | } |
390 | else if (0 < readsize) | 390 | else if (0 < readsize) |
391 | { | 391 | { |
392 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, | 392 | GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize, |
393 | GNUNET_NO, GNUNET_NO); | 393 | GNUNET_NO, GNUNET_NO); |
394 | 394 | ||
395 | } | 395 | } |
396 | else | 396 | else |
397 | { | 397 | { |
398 | //eof | 398 | //eof |
399 | closeprog = 1; | 399 | closeprog = 1; |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | if (FD_ISSET(fdpin, &rfds)) | 403 | if (FD_ISSET(fdpin, &rfds)) |
404 | { | 404 | { |
405 | readsize = read(fdpin, readbuf, sizeof(readbuf)); | 405 | readsize = read(fdpin, readbuf, sizeof(readbuf)); |
406 | 406 | ||
407 | if (0 > readsize) | 407 | if (0 > readsize) |
408 | { | 408 | { |
409 | closeprog = 1; | 409 | closeprog = 1; |
410 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); | 410 | fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); |
411 | break; | 411 | break; |
412 | } | 412 | } |
413 | else if (0 < readsize) | 413 | else if (0 < readsize) |
414 | { | 414 | { |
415 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, | 415 | GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, |
416 | GNUNET_NO, GNUNET_NO); | 416 | GNUNET_NO, GNUNET_NO); |
417 | 417 | ||
418 | } | 418 | } |
419 | else | 419 | else |
420 | { | 420 | { |
421 | //eof | 421 | //eof |
422 | closeprog = 1; | 422 | closeprog = 1; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | 425 | ||
426 | } | 426 | } |
427 | 427 | ||
428 | //clean up | 428 | //clean up |
429 | 429 | ||
430 | GNUNET_SERVER_mst_destroy(stdin_mst); | 430 | GNUNET_SERVER_mst_destroy(stdin_mst); |
431 | GNUNET_SERVER_mst_destroy(file_in_mst); | 431 | GNUNET_SERVER_mst_destroy(file_in_mst); |
432 | 432 | ||
433 | end: if (fpout != NULL) | 433 | end: if (fpout != NULL) |
434 | fclose(fpout); | 434 | fclose(fpout); |
435 | if (fpin != NULL) | 435 | if (fpin != NULL) |
436 | fclose(fpin); | 436 | fclose(fpin); |
437 | 437 | ||
438 | if (1 == first) | 438 | if (1 == first) |
439 | { | 439 | { |
440 | unlink(FIFO_FILE1); | 440 | unlink(FIFO_FILE1); |
441 | unlink(FIFO_FILE2); | 441 | unlink(FIFO_FILE2); |
442 | } | 442 | } |
443 | 443 | ||
444 | return (0); | 444 | return (0); |
445 | } | 445 | } |
446 | 446 | ||
447 | int | 447 | int |
448 | main(int argc, char *argv[]) | 448 | main(int argc, char *argv[]) |
449 | { | 449 | { |
450 | if (2 != argc) | 450 | if (2 != argc) |
451 | { | 451 | { |
452 | fprintf (stderr, | 452 | fprintf (stderr, |
453 | "This program must be started with the operating mode as argument.\n"); | 453 | "This program must be started with the operating mode as argument.\n"); |
454 | fprintf (stderr, | 454 | fprintf (stderr, |
455 | "Usage: options\n" | 455 | "Usage: options\n" |
456 | "options:\n" | 456 | "options:\n" |
457 | "1 = first loopback file\n" | 457 | "1 = first loopback file\n" |
458 | "2 = second loopback file\n" | 458 | "2 = second loopback file\n" |
459 | "\n"); | 459 | "\n"); |
460 | return 1; | 460 | return 1; |
461 | } | 461 | } |
462 | if (strstr(argv[1], "1") || strstr(argv[1], "2")) | 462 | if (strstr(argv[1], "1") || strstr(argv[1], "2")) |
463 | return testmode(argc, argv); | 463 | return testmode(argc, argv); |
464 | return 1; | 464 | return 1; |
465 | } | 465 | } |