]>
git.zerfleddert.de Git - hmcfgusb/blob - hmland.c
6b89ece6a56d76d3f69ed8daba597ee369743517
1 /* HM-CFG-LAN emulation for HM-CFG-USB
3 * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
34 #include <sys/types.h>
35 #include <sys/socket.h>
39 #include <netinet/in.h>
40 #include <arpa/inet.h>
41 #include <libusb-1.0/libusb.h>
47 #define PID_FILE "/var/run/hmland.pid"
49 #define DEFAULT_REBOOT_SECONDS 86400
53 static int impersonate_hmlanif
= 0;
55 static int verbose
= 0;
56 static FILE *logfile
= NULL
;
57 static int reboot_seconds
= 0;
58 static int reboot_at_hour
= -1;
59 static int reboot_at_minute
= -1;
60 static int reboot_set
= 0;
65 struct queued_rx
*next
;
68 static struct queued_rx
*qrx
= NULL
;
69 static int wait_for_h
= 0;
71 #define FLAG_LENGTH_BYTE (1<<0)
72 #define FLAG_FORMAT_HEX (1<<1)
73 #define FLAG_COMMA_BEFORE (1<<2)
74 #define FLAG_COMMA_AFTER (1<<3)
75 #define FLAG_NL (1<<4)
76 #define FLAG_IGNORE_COMMAS (1<<5)
78 #define CHECK_SPACE(x) if ((*outpos + x) > outend) { fprintf(stderr, "Not enough space!\n"); return 0; }
79 #define CHECK_AVAIL(x) if ((*inpos + x) > inend) { fprintf(stderr, "Not enough input available!\n"); return 0; }
81 static void print_timestamp(FILE *f
)
87 gettimeofday(&tv
, NULL
);
88 tmp
= localtime(&tv
.tv_sec
);
89 memset(ts
, 0, sizeof(ts
));
90 strftime(ts
, sizeof(ts
)-1, "%Y-%m-%d %H:%M:%S", tmp
);
91 fprintf(f
, "%s.%06ld: ", ts
, tv
.tv_usec
);
94 static void write_log(char *buf
, int len
, char *fmt
, ...)
99 if ((!logfile
) && (!verbose
))
103 print_timestamp(logfile
);
105 print_timestamp(stdout
);
110 vfprintf(logfile
, fmt
, ap
);
121 for (i
= 0; i
< len
; i
++) {
123 fprintf(logfile
, "%c", buf
[i
]);
125 printf("%c", buf
[i
]);
128 fprintf(logfile
, "\n");
136 static int format_part_out(uint8_t **inpos
, int inlen
, uint8_t **outpos
, int outlen
, int len
, int flags
)
138 const uint8_t nibble
[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
139 'A', 'B', 'C', 'D', 'E', 'F'};
140 uint8_t *buf_out
= *outpos
;
141 uint8_t *outend
= *outpos
+ outlen
;
142 uint8_t *inend
= *inpos
+ inlen
;
145 if (flags
& FLAG_COMMA_BEFORE
) {
151 if (flags
& FLAG_LENGTH_BYTE
) {
157 if (flags
& FLAG_FORMAT_HEX
) {
160 for (i
= 0; i
< len
; i
++) {
161 **outpos
= nibble
[((**inpos
) & 0xf0) >> 4];
163 **outpos
= nibble
[((**inpos
) & 0xf)];
164 *inpos
+= 1; *outpos
+= 1;
169 memcpy(*outpos
, *inpos
, len
);
174 if (flags
& FLAG_COMMA_AFTER
) {
180 if (flags
& FLAG_NL
) {
188 return *outpos
- buf_out
;
191 static uint8_t ascii_to_nibble(uint8_t a
)
195 if ((a
>= '0') && (a
<= '9')) {
197 } else if ((a
>= 'A') && (a
<= 'F')) {
199 } else if ((a
>= 'a') && (a
<= 'f')) {
206 static int parse_part_in(uint8_t **inpos
, int inlen
, uint8_t **outpos
, int outlen
, int flags
)
208 uint8_t *buf_out
= *outpos
;
209 uint8_t *outend
= *outpos
+ outlen
;
210 uint8_t *inend
= *inpos
+ inlen
;
212 if (flags
& FLAG_LENGTH_BYTE
) {
220 if (!(flags
& FLAG_IGNORE_COMMAS
))
229 **outpos
= (len
/ 2);
233 while(*inpos
< inend
) {
234 if (**inpos
== ',') {
236 if (!(flags
& FLAG_IGNORE_COMMAS
))
245 **outpos
= ascii_to_nibble(**inpos
) << 4;
247 **outpos
|= ascii_to_nibble(**inpos
);
248 *inpos
+= 1; *outpos
+= 1;
251 return *outpos
- buf_out
;
254 static int hmlan_format_out(uint8_t *buf
, int buf_len
, void *data
)
260 int fd
= *((int*)data
);
266 memset(out
, 0, sizeof(out
));
270 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, 0);
273 if (impersonate_hmlanif
) {
278 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0, FLAG_LENGTH_BYTE
);
279 version
= inpos
[0] << 8;
281 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
282 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0, FLAG_COMMA_BEFORE
| FLAG_LENGTH_BYTE
);
283 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 3, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
284 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 3, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
285 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 4, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
286 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
| FLAG_NL
);
289 int new_reboot_seconds
;
291 if (version
< 0x03c7) {
292 new_reboot_seconds
= DEFAULT_REBOOT_SECONDS
;
294 new_reboot_seconds
= 0;
297 if (verbose
&& new_reboot_seconds
&& (reboot_seconds
!= new_reboot_seconds
))
298 printf("Rebooting in %u seconds due to old firmware (0.%d)\n",
299 new_reboot_seconds
, version
);
301 reboot_seconds
= new_reboot_seconds
;
306 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 3, FLAG_FORMAT_HEX
);
307 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
308 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 4, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
309 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
310 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
311 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
);
315 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 4, FLAG_FORMAT_HEX
);
316 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
317 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 4, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
318 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
319 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 2, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
320 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
);
324 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
);
325 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
326 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
);
327 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_COMMA_BEFORE
| FLAG_NL
);
331 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 1, FLAG_FORMAT_HEX
| FLAG_NL
);
335 format_part_out(&inpos
, (buf_len
-(inpos
-buf
)), &outpos
, (sizeof(out
)-(outpos
-out
)), buf_len
-1, FLAG_FORMAT_HEX
| FLAG_NL
);
336 hexdump(buf
, buf_len
, "Unknown> ");
340 /* Queue packet until first respone to 'K' is received */
341 if (wait_for_h
&& buf
[0] != 'H') {
342 struct queued_rx
**rxp
= &qrx
;
345 rxp
= &((*rxp
)->next
);
347 *rxp
= malloc(sizeof(struct queued_rx
));
353 memset(*rxp
, 0, sizeof(struct queued_rx
));
354 (*rxp
)->len
= outpos
-out
;
355 (*rxp
)->rx
= malloc((*rxp
)->len
);
360 memset((*rxp
)->rx
, 0, (*rxp
)->len
);
361 memcpy((*rxp
)->rx
, out
, (*rxp
)->len
);
366 write_log((char*)out
, outpos
-out
-2, "LAN < ");
368 w
= write(fd
, out
, outpos
-out
);
374 /* Send all queued packets */
376 struct queued_rx
*curr_rx
= qrx
;
377 struct queued_rx
*last_rx
;
380 write_log(curr_rx
->rx
, curr_rx
->len
-2, "LAN < ");
382 w
= write(fd
, curr_rx
->rx
, curr_rx
->len
);
387 curr_rx
= curr_rx
->next
;
401 static int hmlan_parse_in(int fd
, void *data
)
403 struct hmcfgusb_dev
*dev
= data
;
405 uint8_t out
[0x40]; //FIXME!!!
412 memset(buf
, 0, sizeof(buf
));
414 r
= read(fd
, buf
, sizeof(buf
)-1);
416 uint8_t *inend
= buf
+ r
;
420 while (inpos
< inend
) {
421 uint8_t *instart
= inpos
;
423 if ((*inpos
== '\r') || (*inpos
== '\n')) {
430 last
= inend
- inpos
;
432 for (i
= 0; i
< last
; i
++) {
433 if ((inpos
[i
] == '\r') || (inpos
[i
] == '\n')) {
442 write_log((char*)instart
, last
, "LAN > ");
444 memset(out
, 0, sizeof(out
));
445 *outpos
++ = *inpos
++;
449 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
450 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
451 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
452 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
453 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
454 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), FLAG_LENGTH_BYTE
);
457 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
458 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), 0);
459 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), FLAG_LENGTH_BYTE
);
462 parse_part_in(&inpos
, (last
-(inpos
-instart
)), &outpos
, (sizeof(out
)-(outpos
-out
)), FLAG_IGNORE_COMMAS
);
466 hmcfgusb_send(dev
, out
, sizeof(out
), 1);
469 if (errno
!= ECONNRESET
)
479 static int comm(int fd_in
, int fd_out
, int master_socket
, int flags
)
481 struct hmcfgusb_dev
*dev
;
482 uint8_t out
[0x40]; //FIXME!!!
485 hmcfgusb_set_debug(debug
);
487 dev
= hmcfgusb_init(hmlan_format_out
, &fd_out
);
489 fprintf(stderr
, "Can't initialize HM-CFG-USB!\n");
493 if (dev
->bootloader
) {
495 printf("HM-CFG-USB in bootloader mode, restarting in normal mode...\n");
497 hmcfgusb_leave_bootloader(dev
);
504 if ((reboot_at_hour
!= -1) && (reboot_at_minute
!= -1)) {
509 tm_s
= localtime(&tm
);
515 tm_s
->tm_hour
= reboot_at_hour
;
516 tm_s
->tm_min
= reboot_at_minute
;
520 reboot_seconds
= tm
- dev
->opened_at
;
522 while (reboot_seconds
<= 0)
523 reboot_seconds
+= 86400;
526 if (verbose
&& reboot_seconds
)
527 printf("Rebooting in %u seconds\n", reboot_seconds
);
530 if (!hmcfgusb_add_pfd(dev
, fd_in
, POLLIN
)) {
531 fprintf(stderr
, "Can't add client to pollfd!\n");
536 if (master_socket
>= 0) {
537 if (!hmcfgusb_add_pfd(dev
, master_socket
, POLLIN
)) {
538 fprintf(stderr
, "Can't add master_socket to pollfd!\n");
544 memset(out
, 0, sizeof(out
));
547 hmcfgusb_send_null_frame(dev
, 1);
548 hmcfgusb_send(dev
, out
, sizeof(out
), 1);
553 fd
= hmcfgusb_poll(dev
, 1000); /* Wakeup device/bus at least once a second */
555 if (fd
== master_socket
) {
558 client
= accept(master_socket
, NULL
, 0);
560 shutdown(client
, SHUT_RDWR
);
564 if (hmlan_parse_in(fd
, dev
) <= 0) {
568 } else if (fd
== -1) {
570 if (errno
!= ETIMEDOUT
) {
571 perror("hmcfgusb_poll");
574 /* periodically wakeup the device */
575 hmcfgusb_send_null_frame(dev
, 1);
577 memset(out
, 0, sizeof(out
));
579 hmcfgusb_send(dev
, out
, sizeof(out
), 1);
585 if (reboot_seconds
&& ((dev
->opened_at
+ reboot_seconds
) <= time(NULL
))) {
587 printf("HM-CFG-USB running since %lu seconds, rebooting now...\n",
588 time(NULL
) - dev
->opened_at
);
590 hmcfgusb_enter_bootloader(dev
);
598 void sigterm_handler(int sig
)
600 if (unlink(PID_FILE
) == -1)
601 perror("Can't remove PID file");
606 #define FLAG_DAEMON (1 << 0)
607 #define FLAG_PID_FILE (1 << 1)
609 static int socket_server(char *iface
, int port
, int flags
)
611 struct sigaction sact
;
612 struct sockaddr_in sin
;
617 if (flags
& FLAG_DAEMON
) {
618 FILE *pidfile
= NULL
;
620 if (flags
& FLAG_PID_FILE
) {
623 fd
= open(PID_FILE
, O_CREAT
| O_EXCL
| O_WRONLY
, 0644);
625 if (errno
== EEXIST
) {
627 pidfile
= fopen(PID_FILE
, "r");
629 perror("PID file " PID_FILE
" already exists, already running?");
633 if (fscanf(pidfile
, "%u", &old_pid
) != 1) {
635 fprintf(stderr
, "Can't read old PID from " PID_FILE
", already running?\n");
641 fprintf(stderr
, "Already running with PID %u according to " PID_FILE
"!\n", old_pid
);
644 perror("Can't create PID file " PID_FILE
);
648 pidfile
= fdopen(fd
, "w");
650 perror("Can't reopen PID file fd");
654 memset(&sact
, 0, sizeof(sact
));
655 sact
.sa_handler
= sigterm_handler
;
657 if (sigaction(SIGTERM
, &sact
, NULL
) == -1) {
658 perror("sigaction(SIGTERM)");
666 fprintf(pidfile
, "%u\n", pid
);
670 printf("Daemon with PID %u started!\n", pid
);
672 } else if (pid
< 0) {
681 memset(&sact
, 0, sizeof(sact
));
682 sact
.sa_handler
= SIG_IGN
;
684 if (sigaction(SIGPIPE
, &sact
, NULL
) == -1) {
685 perror("sigaction(SIGPIPE)");
689 impersonate_hmlanif
= 1;
691 sock
= socket(PF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
693 perror("Can't open socket");
698 if (setsockopt(sock
, SOL_SOCKET
, SO_REUSEADDR
, &n
, sizeof(n
)) == -1) {
699 perror("Can't set socket options");
703 memset(&sin
, 0, sizeof(sin
));
704 sin
.sin_family
= AF_INET
;
705 sin
.sin_port
= htons(port
);
707 sin
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
709 if (inet_pton(AF_INET
, iface
, &(sin
.sin_addr
.s_addr
)) != 1) {
710 fprintf(stderr
, "Can't convert IP %s, aborting!\n", iface
);
715 if (bind(sock
, (struct sockaddr
*)&sin
, sizeof(sin
)) == -1) {
716 perror("Can't bind socket");
720 if (listen(sock
, 1) == -1) {
721 perror("Can't listen on socket");
726 struct sockaddr_in csin
;
729 in_addr_t client_addr
;
731 memset(&csin
, 0, sizeof(csin
));
732 csinlen
= sizeof(csin
);
733 client
= accept(sock
, (struct sockaddr
*)&csin
, &csinlen
);
735 perror("Couldn't accept client");
739 /* FIXME: getnameinfo... */
740 client_addr
= ntohl(csin
.sin_addr
.s_addr
);
742 write_log(NULL
, 0, "Client %d.%d.%d.%d connected!\n",
743 (client_addr
& 0xff000000) >> 24,
744 (client_addr
& 0x00ff0000) >> 16,
745 (client_addr
& 0x0000ff00) >> 8,
746 (client_addr
& 0x000000ff));
748 comm(client
, client
, sock
, flags
);
750 shutdown(client
, SHUT_RDWR
);
753 write_log(NULL
, 0, "Connection to %d.%d.%d.%d closed!\n",
754 (client_addr
& 0xff000000) >> 24,
755 (client_addr
& 0x00ff0000) >> 16,
756 (client_addr
& 0x0000ff00) >> 8,
757 (client_addr
& 0x000000ff));
764 static int interactive_server(int flags
)
766 if (!comm(STDIN_FILENO
, STDOUT_FILENO
, -1, flags
))
772 void hmlan_syntax(char *prog
)
774 fprintf(stderr
, "Syntax: %s options\n\n", prog
);
775 fprintf(stderr
, "Possible options:\n");
776 fprintf(stderr
, "\t-D\t\tdebug mode\n");
777 fprintf(stderr
, "\t-d\t\tdaemon mode\n");
778 fprintf(stderr
, "\t-h\t\tthis help\n");
779 fprintf(stderr
, "\t-i\t\tinteractive mode (connect HM-CFG-USB to terminal)\n");
780 fprintf(stderr
, "\t-l ip\t\tlisten on given IP address only (for example 127.0.0.1)\n");
781 fprintf(stderr
, "\t-L logfile\tlog network-communication to logfile\n");
782 fprintf(stderr
, "\t-P\t\tcreate PID file " PID_FILE
" in daemon mode\n");
783 fprintf(stderr
, "\t-p n\t\tlisten on port n (default: 1000)\n");
784 fprintf(stderr
, "\t-r n\t\treboot HM-CFG-USB after n seconds (0: no reboot, default: %u if FW < 0.967, 0 otherwise)\n", DEFAULT_REBOOT_SECONDS
);
785 fprintf(stderr
, "\t hh:mm\treboot HM-CFG-USB daily at hh:mm\n");
786 fprintf(stderr
, "\t-v\t\tverbose mode\n");
787 fprintf(stderr
, "\t-V\t\tshow version (" VERSION
")\n");
791 int main(int argc
, char **argv
)
800 while((opt
= getopt(argc
, argv
, "DdhiPp:Rr:l:L:vV")) != -1) {
807 flags
|= FLAG_DAEMON
;
813 flags
|= FLAG_PID_FILE
;
816 port
= strtoul(optarg
, &ep
, 10);
818 fprintf(stderr
, "Can't parse port!\n");
823 fprintf(stderr
, "-R is no longer needed (1s wakeup is default)\n");
826 reboot_seconds
= strtoul(optarg
, &ep
, 10);
829 reboot_at_hour
= reboot_seconds
;
831 reboot_at_minute
= strtoul(ep
, &ep
, 10);
833 fprintf(stderr
, "Can't parse reboot-time!\n");
839 fprintf(stderr
, "Can't parse reboot-timeout!\n");
849 logfile
= fopen(optarg
, "a");
851 perror("fopen(logfile)");
859 printf("hmland " VERSION
"\n");
860 printf("Copyright (c) 2013 Michael Gernoth\n\n");
866 hmlan_syntax(argv
[0]);
873 return interactive_server(flags
);
875 return socket_server(iface
, port
, flags
);