From 8024e86b5ce80beb2870654cf29308a0f1f208b8 Mon Sep 17 00:00:00 2001 From: Niklas Date: Thu, 1 Sep 2011 16:16:07 +0200 Subject: bigger changes in the checkConnectivity method. using now route command to delete and add the default route. for this i am writing the gateways for every interface into a new file. located at /var/tmp/gateways_ --- customdhcpcd/src/logwriter.c | 74 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 14 deletions(-) (limited to 'customdhcpcd/src/logwriter.c') diff --git a/customdhcpcd/src/logwriter.c b/customdhcpcd/src/logwriter.c index 74c0181..cc7a595 100644 --- a/customdhcpcd/src/logwriter.c +++ b/customdhcpcd/src/logwriter.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -12,6 +13,7 @@ #include "common.h" #include "dhcp.h" #include "dhcpcd.h" +#include "errno.h" #include "logger.h" #include "logwriter.h" #include "status.h" @@ -77,25 +79,39 @@ void logToQt(char * status, char * substatus, char * msg) { void sendToQt(log_msg * msg) { int n = -1; + int t; const char *tpl = "%s;%d;%d;%s\n"; char *outbuf; - size_t outbuf_size = - sizeof(char)*4 + // ";" *3 + newline - sizeof(int)*2 + // status, substatus - sizeof(msg->device) + // devicename - sizeof(msg->msg); // msg + char ack[4]; + size_t outbuf_size = sizeof(char) * 4 + // ";" *3 + newline + sizeof(int) * 2 + // status, substatus + sizeof(msg->device) + // devicename + sizeof(msg->msg); // msg outbuf = malloc(outbuf_size); - memset(outbuf,0,outbuf_size); - snprintf(outbuf, sizeof(char)*3 + sizeof(int)*2 + sizeof(msg->device) + sizeof(msg->msg), tpl, msg->device, msg->status, msg->substatus, msg->msg); - if (outbuf != NULL){ - n = write(sockfd, outbuf, outbuf_size); + memset(outbuf, 0, outbuf_size); + snprintf(outbuf, sizeof(char) * 3 + sizeof(int) * 2 + sizeof(msg->device) + + sizeof(msg->msg), tpl, msg->device, msg->status, msg->substatus, + msg->msg); + if (outbuf != NULL) { + n = send(sockfd, outbuf, outbuf_size, 0); } free(outbuf); - syslog (LOG_INFO, "[fbgui] INFO writing to socket: [%d:%d] %s (%s)", msg->status, msg->substatus, msg->msg, msg->device); -// fflush(sockfd); - if (n < 0) { - syslog (LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)", msg->status, msg->substatus, msg->msg, msg->device); -// fprintf(stdout, "ERROR writing to socket: %s", msg); + syslog(LOG_INFO, "[fbgui] INFO writing to socket: [%d:%d] %s (%s)", + msg->status, msg->substatus, msg->msg, msg->device); + // fflush(sockfd); + if (n <= 0) { + syslog(LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)", + msg->status, msg->substatus, msg->msg, msg->device); + // fprintf(stdout, "ERROR writing to socket: %s", msg); + } + if ((t = recv(sockfd, ack, 4, 0)) > 0) { + ack[t] = '\0'; + syslog(LOG_ERR, "[fbgui] recv ack echo> %s", ack); + } else { + if (t < 0) + syslog(LOG_ERR, "[fbgui] ERROR receiving from socket"); + else + syslog(LOG_ERR, "[fbgui] ERROR Server closed"); } //usleep(500); } @@ -147,3 +163,33 @@ void logLoggerToQt(int level, const char *fmt, va_list args) { strcat(mesg, "\n"); logToQt(level, DHCPCD_LOG, mesg); } + +void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp) { + FILE *f; + route_t *route; + char path[QTSOCKETADDRESSLENGTH]; + + strcpy(path, DEFAULT_GATEWAY_INFO_LOCATION); + strcat(path, iface->name); + + syslog (LOG_INFO, "[fbgui] try to open file: %s", path); + + logger(LOG_DEBUG, "writing %s", iface->infofile); + if ((f = fopen(path, "w")) == NULL) { + logger(LOG_ERR, "fopen `%s': %s", path, strerror(errno)); + } + + if (dhcp->routes) { + bool doneone = false; + STAILQ_FOREACH (route, dhcp->routes, entries) { + if (route->destination.s_addr == 0) { + if (doneone) + fprintf(f, ","); + fprintf(f, "%s", inet_ntoa(route->gateway)); + doneone = true; + } + } + fprintf(f, "\n"); + } + fclose(f); +} -- cgit v1.2.3-55-g7522