]> git.zerfleddert.de Git - hmcfgusb/blob - hmland.c
print lan-communication in verbose-mode
[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 (verbose) {
243 int i;
244
245 printf("LAN < ");
246 for (i = 0; i < outpos-out; i++)
247 printf("%c", out[i]);
248 }
249
250 w = write(fd, out, outpos-out);
251 if (w <= 0) {
252 perror("write");
253 return 0;
254 }
255
256 return 1;
257 }
258
259 static int hmlan_parse_in(int fd, void *data)
260 {
261 struct hmcfgusb_dev *dev = data;
262 uint8_t buf[1025];
263 uint8_t out[0x40]; //FIXME!!!
264 uint8_t *outpos;
265 uint8_t *inpos;
266 int i;
267 int last;
268 int r;
269
270 memset(buf, 0, sizeof(buf));
271
272 r = read(fd, buf, sizeof(buf)-1);
273 if (r > 0) {
274 uint8_t *inend = buf + r;
275
276 inpos = buf;
277
278 while (inpos < inend) {
279 uint8_t *instart = inpos;
280
281 if ((*inpos == '\r') || (*inpos == '\n')) {
282 inpos++;
283 continue;
284 }
285
286 outpos = out;
287
288 last = inend - inpos;
289
290 for (i = 0; i < last; i++) {
291 if ((inpos[i] == '\r') || (inpos[i] == '\n')) {
292 last = i;
293 break;
294 }
295 }
296
297 if (last == 0)
298 continue;
299
300 if (verbose) {
301 printf("LAN > ");
302 for (i = 0; i < last; i++)
303 printf("%c", instart[i]);
304 printf("\n");
305 }
306
307 memset(out, 0, sizeof(out));
308 *outpos++ = *inpos++;
309
310 switch(*instart) {
311 case 'S':
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)), 0);
314 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
315 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
316 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
317 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_LENGTH_BYTE);
318 break;
319 case 'Y':
320 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
321 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), 0);
322 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_LENGTH_BYTE);
323 break;
324 default:
325 parse_part_in(&inpos, (last-(inpos-instart)), &outpos, (sizeof(out)-(outpos-out)), FLAG_IGNORE_COMMAS);
326 break;
327 }
328
329 hmcfgusb_send(dev, out, sizeof(out), 1);
330 }
331 } else if (r < 0) {
332 perror("read");
333 return r;
334 } else {
335 return 0;
336 }
337
338 return 1;
339 }
340
341 static int comm(int fd_in, int fd_out, int master_socket, int flags)
342 {
343 struct hmcfgusb_dev *dev;
344 uint8_t out[0x40]; //FIXME!!!
345 int quit = 0;
346
347 hmcfgusb_set_debug(debug);
348
349 dev = hmcfgusb_init(hmlan_format_out, &fd_out);
350 if (!dev) {
351 fprintf(stderr, "Can't initialize HM-CFG-USB!\n");
352 return 0;
353 }
354
355 if (!hmcfgusb_add_pfd(dev, fd_in, POLLIN)) {
356 fprintf(stderr, "Can't add client to pollfd!\n");
357 hmcfgusb_close(dev);
358 return 0;
359 }
360
361 if (master_socket >= 0) {
362 if (!hmcfgusb_add_pfd(dev, master_socket, POLLIN)) {
363 fprintf(stderr, "Can't add master_socket to pollfd!\n");
364 hmcfgusb_close(dev);
365 return 0;
366 }
367 }
368
369 memset(out, 0, sizeof(out));
370 out[0] = 'K';
371 hmcfgusb_send_null_frame(dev);
372 hmcfgusb_send(dev, out, sizeof(out), 1);
373
374 while(!quit) {
375 int fd;
376
377 fd = hmcfgusb_poll(dev, 1); /* Wakeup device/bus at least once a second */
378 if (fd >= 0) {
379 if (fd == master_socket) {
380 int client;
381
382 client = accept(master_socket, NULL, 0);
383 if (client >= 0) {
384 shutdown(client, SHUT_RDWR);
385 close(client);
386 }
387 } else {
388 if (hmlan_parse_in(fd, dev) <= 0) {
389 quit = 1;
390 }
391 }
392 } else if (fd == -1) {
393 if (errno) {
394 perror("hmcfgusb_poll");
395 quit = 1;
396 } else {
397 /* periodically wakeup the device */
398 hmcfgusb_send_null_frame(dev);
399 }
400 }
401 }
402
403 hmcfgusb_close(dev);
404 return 1;
405 }
406
407 void sigterm_handler(int sig)
408 {
409 if (unlink(PID_FILE) == -1)
410 perror("Can't remove PID file");
411
412 exit(EXIT_SUCCESS);
413 }
414
415 #define FLAG_DAEMON (1 << 0)
416 #define FLAG_PID_FILE (1 << 1)
417
418 static int socket_server(char *iface, int port, int flags)
419 {
420 struct sigaction sact;
421 struct sockaddr_in sin;
422 int sock;
423 int n;
424 pid_t pid;
425
426 if (flags & FLAG_DAEMON) {
427 FILE *pidfile = NULL;
428
429 if (flags & FLAG_PID_FILE) {
430 int fd;
431
432 fd = open(PID_FILE, O_CREAT | O_EXCL | O_WRONLY, 0644);
433 if (fd == -1) {
434 if (errno == EEXIST) {
435 pid_t old_pid;
436 pidfile = fopen(PID_FILE, "r");
437 if (!pidfile) {
438 perror("PID file " PID_FILE " already exists, already running?");
439 exit(EXIT_FAILURE);
440 }
441
442 if (fscanf(pidfile, "%u", &old_pid) != 1) {
443 fclose(pidfile);
444 fprintf(stderr, "Can't read old PID from " PID_FILE ", already running?\n");
445 exit(EXIT_FAILURE);
446 }
447
448 fclose(pidfile);
449
450 fprintf(stderr, "Already running with PID %u according to " PID_FILE "!\n", old_pid);
451 exit(EXIT_FAILURE);
452 }
453 perror("Can't create PID file " PID_FILE);
454 exit(EXIT_FAILURE);
455 }
456
457 pidfile = fdopen(fd, "w");
458 if (!pidfile) {
459 perror("Can't reopen PID file fd");
460 exit(EXIT_FAILURE);
461 }
462
463 memset(&sact, 0, sizeof(sact));
464 sact.sa_handler = sigterm_handler;
465
466 if (sigaction(SIGTERM, &sact, NULL) == -1) {
467 perror("sigaction(SIGTERM)");
468 exit(EXIT_FAILURE);
469 }
470 }
471
472 pid = fork();
473 if (pid > 0) {
474 if (pidfile) {
475 fprintf(pidfile, "%u\n", pid);
476 fclose(pidfile);
477 }
478
479 printf("Daemon with PID %u started!\n", pid);
480 exit(EXIT_SUCCESS);
481 } else if (pid < 0) {
482 perror("fork");
483 exit(EXIT_FAILURE);
484 }
485
486 if (pidfile)
487 fclose(pidfile);
488 }
489
490 memset(&sact, 0, sizeof(sact));
491 sact.sa_handler = SIG_IGN;
492
493 if (sigaction(SIGPIPE, &sact, NULL) == -1) {
494 perror("sigaction(SIGPIPE)");
495 exit(EXIT_FAILURE);
496 }
497
498 impersonate_hmlanif = 1;
499
500 sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
501 if (sock == -1) {
502 perror("Can't open socket");
503 return EXIT_FAILURE;
504 }
505
506 n = 1;
507 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) {
508 perror("Can't set socket options");
509 return EXIT_FAILURE;
510 }
511
512 memset(&sin, 0, sizeof(sin));
513 sin.sin_family = AF_INET;
514 sin.sin_port = htons(port);
515 if (!iface) {
516 sin.sin_addr.s_addr = htonl(INADDR_ANY);
517 } else {
518 if (inet_pton(AF_INET, iface, &(sin.sin_addr.s_addr)) != 1) {
519 perror("inet_ntop");
520 return EXIT_FAILURE;
521 }
522 }
523
524 if (bind(sock, (struct sockaddr*)&sin, sizeof(sin)) == -1) {
525 perror("Can't bind socket");
526 return EXIT_FAILURE;
527 }
528
529 if (listen(sock, 1) == -1) {
530 perror("Can't listen on socket");
531 return EXIT_FAILURE;
532 }
533
534 while(1) {
535 struct sockaddr_in csin;
536 socklen_t csinlen;
537 int client;
538 in_addr_t client_addr;
539
540 memset(&csin, 0, sizeof(csin));
541 csinlen = sizeof(csin);
542 client = accept(sock, (struct sockaddr*)&csin, &csinlen);
543 if (client == -1) {
544 perror("Couldn't accept client");
545 continue;
546 }
547
548 /* FIXME: getnameinfo... */
549 client_addr = ntohl(csin.sin_addr.s_addr);
550
551 if (verbose) {
552 printf("Client %d.%d.%d.%d connected!\n",
553 (client_addr & 0xff000000) >> 24,
554 (client_addr & 0x00ff0000) >> 16,
555 (client_addr & 0x0000ff00) >> 8,
556 (client_addr & 0x000000ff));
557 }
558
559 comm(client, client, sock, flags);
560
561 shutdown(client, SHUT_RDWR);
562 close(client);
563
564 if (verbose) {
565 printf("Connection to %d.%d.%d.%d closed!\n",
566 (client_addr & 0xff000000) >> 24,
567 (client_addr & 0x00ff0000) >> 16,
568 (client_addr & 0x0000ff00) >> 8,
569 (client_addr & 0x000000ff));
570 }
571 sleep(1);
572 }
573
574 return EXIT_SUCCESS;
575 }
576
577 static int interactive_server(int flags)
578 {
579 if (!comm(STDIN_FILENO, STDOUT_FILENO, -1, flags))
580 return EXIT_FAILURE;
581
582 return EXIT_SUCCESS;
583 }
584
585 void hmlan_syntax(char *prog)
586 {
587 fprintf(stderr, "Syntax: %s options\n\n", prog);
588 fprintf(stderr, "Possible options:\n");
589 fprintf(stderr, "\t-D\tdebug mode\n");
590 fprintf(stderr, "\t-d\tdaemon mode\n");
591 fprintf(stderr, "\t-h\tthis help\n");
592 fprintf(stderr, "\t-i\tinteractive mode (connect HM-CFG-USB to terminal)\n");
593 fprintf(stderr, "\t-l ip\tlisten on given IP address only (for example 127.0.0.1)\n");
594 fprintf(stderr, "\t-P\tcreate PID file " PID_FILE " in daemon mode\n");
595 fprintf(stderr, "\t-p n\tlisten on port n (default 1000)\n");
596 fprintf(stderr, "\t-v\tverbose mode\n");
597
598 }
599
600 int main(int argc, char **argv)
601 {
602 int port = 1000;
603 char *iface = NULL;
604 int interactive = 0;
605 int flags = 0;
606 char *ep;
607 int opt;
608
609 while((opt = getopt(argc, argv, "DdhiPp:Rl:v")) != -1) {
610 switch (opt) {
611 case 'D':
612 debug = 1;
613 verbose = 1;
614 break;
615 case 'd':
616 flags |= FLAG_DAEMON;
617 break;
618 case 'i':
619 interactive = 1;
620 break;
621 case 'P':
622 flags |= FLAG_PID_FILE;
623 break;
624 case 'p':
625 port = strtoul(optarg, &ep, 10);
626 if (*ep != '\0') {
627 fprintf(stderr, "Can't parse port!\n");
628 exit(EXIT_FAILURE);
629 }
630 break;
631 case 'R':
632 fprintf(stderr, "-R is no longer needed (1s wakeup is default)\n");
633 break;
634 case 'l':
635 iface = optarg;
636 break;
637 case 'v':
638 verbose = 1;
639 break;
640 case 'h':
641 case ':':
642 case '?':
643 default:
644 hmlan_syntax(argv[0]);
645 exit(EXIT_FAILURE);
646 break;
647 }
648 }
649
650 if (interactive) {
651 return interactive_server(flags);
652 } else {
653 return socket_server(iface, port, flags);
654 }
655 }
Impressum, Datenschutz