X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/hmcfgusb/blobdiff_plain/51d4ece67f9843cef2eaebc84fb7e98716fe28ab..27f4063e297cb1d559d0bbacded740801f9bfc00:/hmland.c diff --git a/hmland.c b/hmland.c index c8781a9..24fa34e 100644 --- a/hmland.c +++ b/hmland.c @@ -1,4 +1,4 @@ -/* HM-CFG-LAN emuldation for HM-CFG-USB +/* HM-CFG-LAN emulation for HM-CFG-USB * * Copyright (c) 2013 Michael Gernoth * @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -172,15 +173,16 @@ static int parse_part_in(uint8_t **inpos, int inlen, uint8_t **outpos, int outle return *outpos - buf_out; } -static void hmlan_format_out(uint8_t *buf, int buf_len, void *data) +static int hmlan_format_out(uint8_t *buf, int buf_len, void *data) { uint8_t out[1024]; uint8_t *outpos; uint8_t *inpos; int fd = *((int*)data); + int w; if (buf_len < 1) - return; + return 1; memset(out, 0, sizeof(out)); outpos = out; @@ -233,9 +235,16 @@ static void hmlan_format_out(uint8_t *buf, int buf_len, void *data) hexdump(buf, buf_len, "Unknown> "); break; } - write(fd, out, outpos-out); if (debug) fprintf(stderr, "LAN < %s\n", out); + + w = write(fd, out, outpos-out); + if (w <= 0) { + perror("write"); + return 0; + } + + return 1; } static int hmlan_parse_in(int fd, void *data) @@ -372,6 +381,7 @@ static int comm(int fd_in, int fd_out, int master_socket) static int socket_server(int port, int daemon) { + struct sigaction sact; struct sockaddr_in sin; int sock; int n; @@ -388,6 +398,14 @@ static int socket_server(int port, int daemon) } } + memset(&sact, 0, sizeof(sact)); + sact.sa_handler = SIG_IGN; + + if (sigaction(SIGPIPE, &sact, NULL) == -1) { + perror("sigaction"); + exit(EXIT_FAILURE); + } + impersonate_hmlanif = 1; sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);