]> cvs.zerfleddert.de Git - hmcfgusb/blob - hmland.c
add missing break
[hmcfgusb] / hmland.c
1 /* HM-CFG-LAN emulation for HM-CFG-USB
2 *
3 * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <unistd.h>
27 #include <stdint.h>
28 #include <string.h>
29 #include <strings.h>
30 #include <poll.h>
31 #include <signal.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/stat.h>
36 #include <fcntl.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 #include <libusb-1.0/libusb.h>
40
41 #include "hexdump.h"
42 #include "hmcfgusb.h"
43
44 #define PID_FILE "/var/run/hmland.pid"
45
46 extern char *optarg;
47
48 static int impersonate_hmlanif = 0;
49 static int debug = 0;
50 static int verbose = 0;
51
52 #define FLAG_LENGTH_BYTE (1<<0)
53 #define FLAG_FORMAT_HEX (1<<1)
54 #define FLAG_COMMA_BEFORE (1<<2)
55 #define FLAG_COMMA_AFTER (1<<3)
56 #define FLAG_NL (1<<4)
57 #define FLAG_IGNORE_COMMAS (1<<5)
58
59 #define CHECK_SPACE(x) if ((*outpos + x) > outend) { fprintf(stderr, "Not enough space!\n"); return 0; }
60 #define CHECK_AVAIL(x) if ((*inpos + x) > inend) { fprintf(stderr, "Not enough input available!\n"); return 0; }
61
62 static int format_part_out(uint8_t **inpos, int inlen, uint8_t **outpos, int outlen, int len, int flags)
63 {
64 const uint8_t nibble[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
65 'A', 'B', 'C', 'D', 'E', 'F'};
66 uint8_t *buf_out = *outpos;
67 uint8_t *outend = *outpos + outlen;
68 uint8_t *inend = *inpos + inlen;
69 int i;
70
71 if (flags & FLAG_COMMA_BEFORE) {
72 CHECK_SPACE(1);
73 **outpos=',';
74 *outpos += 1;
75 }
76
77 if (flags & FLAG_LENGTH_BYTE) {
78 CHECK_AVAIL(1);
79 len = **inpos;
80 *inpos += 1;
81 }
82
83 if (flags & FLAG_FORMAT_HEX) {
84 CHECK_AVAIL(len);
85 CHECK_SPACE(len*2);
86 for (i = 0; i < len; i++) {
87 **outpos = nibble[((**inpos) & 0xf0) >> 4];
88 *outpos += 1;
89 **outpos = nibble[((**inpos) & 0xf)];
90 *inpos += 1; *outpos += 1;
91 }
92 } else {
93 CHECK_AVAIL(len);
94 CHECK_SPACE(len);
95 memcpy(*outpos, *inpos, len);
96 *outpos += len;
97 *inpos += len;
98 }
99
100 if (flags & FLAG_COMMA_AFTER) {
101 CHECK_SPACE(1);
102 **outpos=',';
103 *outpos += 1;
104 }
105
106 if (flags & FLAG_NL) {
107 CHECK_SPACE(2);
108 **outpos='\r';
109 *outpos += 1;
110 **outpos='\n';
111 *outpos += 1;
112 }
113
114 return *outpos - buf_out;
115 }
116
117 static uint8_t ascii_to_nibble(uint8_t a)
118 {
119 uint8_t c = 0x00;
120
121 if ((a >= '0') && (a <= '9')) {
122 c = a - '0';
123 } else if ((a >= 'A') && (a <= 'F')) {
124 c = (a - 'A') + 10;
125 } else if ((a >= 'a') && (a <= 'f')) {
126 c = (a - 'a') + 10;
127 }
128
129 return c;
130 }
131
132 static int parse_part_in(uint8_t **inpos, int inlen, uint8_t **outpos, int outlen, int flags)
133 {
134 uint8_t *buf_out = *outpos;
135 uint8_t *outend = *outpos + outlen;
136 uint8_t *inend = *inpos + inlen;
137
138 if (flags & FLAG_LENGTH_BYTE) {
139 int len = 0;
140 uint8_t *ip;
141
142 ip = *inpos;
143 while(ip < inend) {
144 if (*ip == ',') {
145 ip++;
146 if (!(flags & FLAG_IGNORE_COMMAS))
147 break;
148
149 continue;
150 }
151 len++;
152 ip++;
153 }
154 CHECK_SPACE(1);
155 **outpos = (len / 2);
156 *outpos += 1;
157 }
158
159 while(*inpos < inend) {
160 if (**inpos == ',') {
161 *inpos += 1;
162 if (!(flags & FLAG_IGNORE_COMMAS))
163 break;
164
165 continue;
166 }
167
168 CHECK_SPACE(1);
169 CHECK_AVAIL(2);
170
171 **outpos = ascii_to_nibble(**inpos) << 4;
172 *inpos += 1;
173 **outpos |= ascii_to_nibble(**inpos);
174 *inpos += 1; *outpos += 1;
175 }
176
177 return *outpos - buf_out;
178 }
179
180 static int hmlan_format_out(uint8_t *buf, int buf_len, void *data)
181 {
182 uint8_t out[1024];
183 uint8_t *outpos;
184 uint8_t *inpos;
185 int fd = *((int*)data);
186 int w;
187
188 if (buf_len < 1)
189 return 1;
190
191 memset(out, 0, sizeof(out));
192 outpos = out;
193 inpos = buf;
194
195 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, 0);
196 switch(buf[0]) {
197 case 'H':
198 if (impersonate_hmlanif) {
199 buf[5] = 'L';
200 buf[6] = 'A';
201 buf[7] = 'N';
202 }
203 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 0, FLAG_LENGTH_BYTE);
204 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
205 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 0, FLAG_COMMA_BEFORE | FLAG_LENGTH_BYTE);
206 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 3, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
207 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 3, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
208 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 4, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
209 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE | FLAG_NL);
210
211 break;
212 case 'E':
213 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 3, FLAG_FORMAT_HEX);
214 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
215 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 4, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
216 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
217 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
218 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 0, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE | FLAG_LENGTH_BYTE | FLAG_NL);
219
220 break;
221 case 'R':
222 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 4, FLAG_FORMAT_HEX);
223 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
224 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 4, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
225 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
226 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 2, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
227 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 0, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE | FLAG_LENGTH_BYTE | FLAG_NL);
228
229 break;
230 case 'I':
231 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX);
232 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
233 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE);
234 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), 1, FLAG_FORMAT_HEX | FLAG_COMMA_BEFORE | FLAG_NL);
235
236 break;
237 default:
238 format_part_out(&inpos, (buf_len-(inpos-buf)), &outpos, (sizeof(out)-(outpos-out)), buf_len-1, FLAG_FORMAT_HEX | FLAG_NL);
239 hexdump(buf, buf_len, "Unknown> ");
240 break;
241 }
242 if (debug)
243 fprintf(stderr, "LAN < %s\n", out);
244
245 w = write(fd, out, outpos-out);
246 if (w <= 0) {
247 perror("write");
248 return 0;
249 }
250
251 return 1;
252 }
253
254 static int hmlan_parse_in(int fd, void *data)
255 {
256 struct hmcfgusb_dev *dev = data;
257 uint8_t buf[1025];
258 uint8_t out[0x40]; //FIXME!!!
259 uint8_t *outpos;
260 uint8_t *inpos;
261 int i;
262 int last;
263 int r;
264
265 memset(buf, 0, sizeof(buf));
266
267 r = read(fd, buf, sizeof(buf)-1);
268 if (r > 0) {
269 uint8_t *inend = buf + r;
270
271 inpos = buf;
272
273 if (debug)
274 fprintf(stderr, "\nLAN > %s", buf);
275
276 while (inpos < inend) {
277 uint8_t *instart = inpos;
278
279 if ((*inpos == '\r') || (*inpos == '\n')) {
280 inpos++;
281 continue;
282 }
283
284 outpos = out;
285
286 last = inend - inpos;
287
288 for (i = 0; i < last; i++) {
289 if ((inpos[i] == '\r') || (inpos[i] == '\n')) {
290 last = i;
291 break;
292 }
293 }
294
295 if (last == 0)
296 continue;
297
298 memset(out, 0, sizeof(out));
299 *outpos++ = *inpos++;
300
301 switch(*instart) {
302 case 'S':
303 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
304 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
305 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
306 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
307 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
308 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_LENGTH_BYTE);
309 break;
310 case 'Y':
311 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
312 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
313 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_LENGTH_BYTE);
314 break;
315 default:
316 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_IGNORE_COMMAS);
317 break;
318 }
319
320 hmcfgusb_send(dev, out, sizeof(out), 1);
321 }
322 } else if (r < 0) {
323 perror("read");
324 return r;
325 } else {
326 return 0;
327 }
328
329 return 1;
330 }
331
332 static int comm(int fd_in, int fd_out, int master_socket, int flags)
333 {
334 struct hmcfgusb_dev *dev;
335 uint8_t out[0x40]; //FIXME!!!
336 int quit = 0;
337
338 hmcfgusb_set_debug(debug);
339
340 dev = hmcfgusb_init(hmlan_format_out, &fd_out);
341 if (!dev) {
342 fprintf(stderr, "Can't initialize HM-CFG-USB!\n");
343 return 0;
344 }
345
346 if (!hmcfgusb_add_pfd(dev, fd_in, POLLIN)) {
347 fprintf(stderr, "Can't add client to pollfd!\n");
348 hmcfgusb_close(dev);
349 return 0;
350 }
351
352 if (master_socket >= 0) {
353 if (!hmcfgusb_add_pfd(dev, master_socket, POLLIN)) {
354 fprintf(stderr, "Can't add master_socket to pollfd!\n");
355 hmcfgusb_close(dev);
356 return 0;
357 }
358 }
359
360 memset(out, 0, sizeof(out));
361 out[0] = 'K';
362 hmcfgusb_send_null_frame(dev);
363 hmcfgusb_send(dev, out, sizeof(out), 1);
364
365 while(!quit) {
366 int fd;
367
368 fd = hmcfgusb_poll(dev, 1); /* Wakeup device/bus at least once a second */
369 if (fd >= 0) {
370 if (fd == master_socket) {
371 int client;
372
373 client = accept(master_socket, NULL, 0);
374 if (client >= 0) {
375 shutdown(client, SHUT_RDWR);
376 close(client);
377 }
378 } else {
379 if (hmlan_parse_in(fd, dev) <= 0) {
380 quit = 1;
381 }
382 }
383 } else if (fd == -1) {
384 if (errno) {
385 perror("hmcfgusb_poll");
386 quit = 1;
387 } else {
388 /* periodically wakeup the device */
389 hmcfgusb_send_null_frame(dev);
390 }
391 }
392 }
393
394 hmcfgusb_close(dev);
395 return 1;
396 }
397
398 void sigterm_handler(int sig)
399 {
400 if (unlink(PID_FILE) == -1)
401 perror("Can't remove PID file");
402
403 exit(EXIT_SUCCESS);
404 }
405
406 #define FLAG_DAEMON (1 << 0)
407 #define FLAG_PID_FILE (1 << 1)
408
409 static int socket_server(char *iface, int port, int flags)
410 {
411 struct sigaction sact;
412 struct sockaddr_in sin;
413 int sock;
414 int n;
415 pid_t pid;
416
417 if (flags & FLAG_DAEMON) {
418 FILE *pidfile = NULL;
419
420 if (flags & FLAG_PID_FILE) {
421 int fd;
422
423 fd = open(PID_FILE, O_CREAT | O_EXCL | O_WRONLY, 0644);
424 if (fd == -1) {
425 if (errno == EEXIST) {
426 pid_t old_pid;
427 pidfile = fopen(PID_FILE, "r");
428 if (!pidfile) {
429 perror("PID file " PID_FILE " already exists, already running?");
430 exit(EXIT_FAILURE);
431 }
432
433 if (fscanf(pidfile, "%u", &old_pid) != 1) {
434 fclose(pidfile);
435 fprintf(stderr, "Can't read old PID from " PID_FILE ", already running?\n");
436 exit(EXIT_FAILURE);
437 }
438
439 fclose(pidfile);
440
441 fprintf(stderr, "Already running with PID %u according to " PID_FILE "!\n", old_pid);
442 exit(EXIT_FAILURE);
443 }
444 perror("Can't create PID file " PID_FILE);
445 exit(EXIT_FAILURE);
446 }
447
448 pidfile = fdopen(fd, "w");
449 if (!pidfile) {
450 perror("Can't reopen PID file fd");
451 exit(EXIT_FAILURE);
452 }
453
454 memset(&sact, 0, sizeof(sact));
455 sact.sa_handler = sigterm_handler;
456
457 if (sigaction(SIGTERM, &sact, NULL) == -1) {
458 perror("sigaction(SIGTERM)");
459 exit(EXIT_FAILURE);
460 }
461 }
462
463 pid = fork();
464 if (pid > 0) {
465 if (pidfile) {
466 fprintf(pidfile, "%u\n", pid);
467 fclose(pidfile);
468 }
469
470 printf("Daemon with PID %u started!\n", pid);
471 exit(EXIT_SUCCESS);
472 } else if (pid < 0) {
473 perror("fork");
474 exit(EXIT_FAILURE);
475 }
476
477 if (pidfile)
478 fclose(pidfile);
479 }
480
481 memset(&sact, 0, sizeof(sact));
482 sact.sa_handler = SIG_IGN;
483
484 if (sigaction(SIGPIPE, &sact, NULL) == -1) {
485 perror("sigaction(SIGPIPE)");
486 exit(EXIT_FAILURE);
487 }
488
489 impersonate_hmlanif = 1;
490
491 sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
492 if (sock == -1) {
493 perror("Can't open socket");
494 return EXIT_FAILURE;
495 }
496
497 n = 1;
498 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) {
499 perror("Can't set socket options");
500 return EXIT_FAILURE;
501 }
502
503 memset(&sin, 0, sizeof(sin));
504 sin.sin_family = AF_INET;
505 sin.sin_port = htons(port);
506 if (!iface) {
507 sin.sin_addr.s_addr = htonl(INADDR_ANY);
508 } else {
509 if (inet_pton(AF_INET, iface, &(sin.sin_addr.s_addr)) != 1) {
510 perror("inet_ntop");
511 return EXIT_FAILURE;
512 }
513 }
514
515 if (bind(sock, (struct sockaddr*)&sin, sizeof(sin)) == -1) {
516 perror("Can't bind socket");
517 return EXIT_FAILURE;
518 }
519
520 if (listen(sock, 1) == -1) {
521 perror("Can't listen on socket");
522 return EXIT_FAILURE;
523 }
524
525 while(1) {
526 struct sockaddr_in csin;
527 socklen_t csinlen;
528 int client;
529 in_addr_t client_addr;
530
531 memset(&csin, 0, sizeof(csin));
532 csinlen = sizeof(csin);
533 client = accept(sock, (struct sockaddr*)&csin, &csinlen);
534 if (client == -1) {
535 perror("Couldn't accept client");
536 continue;
537 }
538
539 /* FIXME: getnameinfo... */
540 client_addr = ntohl(csin.sin_addr.s_addr);
541
542 if (verbose) {
543 printf("Client %d.%d.%d.%d connected!\n",
544 (client_addr & 0xff000000) >> 24,
545 (client_addr & 0x00ff0000) >> 16,
546 (client_addr & 0x0000ff00) >> 8,
547 (client_addr & 0x000000ff));
548 }
549
550 comm(client, client, sock, flags);
551
552 shutdown(client, SHUT_RDWR);
553 close(client);
554
555 if (verbose) {
556 printf("Connection to %d.%d.%d.%d closed!\n",
557 (client_addr & 0xff000000) >> 24,
558 (client_addr & 0x00ff0000) >> 16,
559 (client_addr & 0x0000ff00) >> 8,
560 (client_addr & 0x000000ff));
561 }
562 sleep(1);
563 }
564
565 return EXIT_SUCCESS;
566 }
567
568 static int interactive_server(int flags)
569 {
570 if (!comm(STDIN_FILENO, STDOUT_FILENO, -1, flags))
571 return EXIT_FAILURE;
572
573 return EXIT_SUCCESS;
574 }
575
576 void hmlan_syntax(char *prog)
577 {
578 fprintf(stderr, "Syntax: %s options\n\n", prog);
579 fprintf(stderr, "Possible options:\n");
580 fprintf(stderr, "\t-D\tdebug mode\n");
581 fprintf(stderr, "\t-d\tdaemon mode\n");
582 fprintf(stderr, "\t-h\tthis help\n");
583 fprintf(stderr, "\t-i\tinteractive mode (connect HM-CFG-USB to terminal)\n");
584 fprintf(stderr, "\t-l ip\tlisten on given IP address only (for example 127.0.0.1)\n");
585 fprintf(stderr, "\t-P\tcreate PID file " PID_FILE " in daemon mode\n");
586 fprintf(stderr, "\t-p n\tlisten on port n (default 1000)\n");
587 fprintf(stderr, "\t-v\tverbose mode\n");
588
589 }
590
591 int main(int argc, char **argv)
592 {
593 int port = 1000;
594 char *iface = NULL;
595 int interactive = 0;
596 int flags = 0;
597 char *ep;
598 int opt;
599
600 while((opt = getopt(argc, argv, "DdhiPp:Rl:v")) != -1) {
601 switch (opt) {
602 case 'D':
603 debug = 1;
604 verbose = 1;
605 break;
606 case 'd':
607 flags |= FLAG_DAEMON;
608 break;
609 case 'i':
610 interactive = 1;
611 break;
612 case 'P':
613 flags |= FLAG_PID_FILE;
614 break;
615 case 'p':
616 port = strtoul(optarg, &ep, 10);
617 if (*ep != '\0') {
618 fprintf(stderr, "Can't parse port!\n");
619 exit(EXIT_FAILURE);
620 }
621 break;
622 case 'R':
623 fprintf(stderr, "-R is no longer needed (1s wakeup is default)\n");
624 break;
625 case 'l':
626 iface = optarg;
627 break;
628 case 'v':
629 verbose = 1;
630 break;
631 case 'h':
632 case ':':
633 case '?':
634 default:
635 hmlan_syntax(argv[0]);
636 exit(EXIT_FAILURE);
637 break;
638 }
639 }
640
641 if (interactive) {
642 return interactive_server(flags);
643 } else {
644 return socket_server(iface, port, flags);
645 }
646 }
Impressum, Datenschutz