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/Makefile | 4 +-- customdhcpcd/src/configure.c | 2 ++ customdhcpcd/src/customdhcpcd | Bin 173171 -> 175254 bytes customdhcpcd/src/dhcpcd.h | 1 + customdhcpcd/src/logwriter.c | 74 ++++++++++++++++++++++++++++++++++-------- customdhcpcd/src/logwriter.h | 2 +- 6 files changed, 66 insertions(+), 17 deletions(-) (limited to 'customdhcpcd') diff --git a/customdhcpcd/src/Makefile b/customdhcpcd/src/Makefile index 7f90db4..bb1078f 100644 --- a/customdhcpcd/src/Makefile +++ b/customdhcpcd/src/Makefile @@ -5,10 +5,10 @@ PROG= customdhcpcd SRCS= arp.c client.c common.c configure.c dhcp.c dhcpcd.c duid.c \ info.c interface.c ipv4ll.c logger.c logwriter.c signal.c socket.c -MAN= dhcpcd.8 +MAN= VERSION= 3.2.3 -CLEANFILES= version.h dhcpcd.8 +CLEANFILES= version.h BINDIR= ${PREFIX}/sbin diff --git a/customdhcpcd/src/configure.c b/customdhcpcd/src/configure.c index 91e3c9f..1eaf8f6 100644 --- a/customdhcpcd/src/configure.c +++ b/customdhcpcd/src/configure.c @@ -554,6 +554,8 @@ int configure (const options_t *options, interface_t *iface, if (dhcp->address.s_addr == 0) up = 0; + logGatewayToFile(iface, dhcp); + /* Remove old routes. * Always do this as the interface may have >1 address not added by us * so the routes we added may still exist. */ diff --git a/customdhcpcd/src/customdhcpcd b/customdhcpcd/src/customdhcpcd index 5ef34d0..1fd0594 100755 Binary files a/customdhcpcd/src/customdhcpcd and b/customdhcpcd/src/customdhcpcd differ diff --git a/customdhcpcd/src/dhcpcd.h b/customdhcpcd/src/dhcpcd.h index 7deb5b7..3f4c085 100644 --- a/customdhcpcd/src/dhcpcd.h +++ b/customdhcpcd/src/dhcpcd.h @@ -43,6 +43,7 @@ /* added by Niklas Goby, additional field, storing the socket address path for * communicating with Qt "server" */ #define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default" +#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_" #define QTSOCKETADDRESSLENGTH 255 #define CLASS_ID_MAX_LEN 48 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); +} diff --git a/customdhcpcd/src/logwriter.h b/customdhcpcd/src/logwriter.h index 1a755fc..11693e5 100644 --- a/customdhcpcd/src/logwriter.h +++ b/customdhcpcd/src/logwriter.h @@ -32,6 +32,6 @@ void logToQt(int status, int substatus, const char * msg); void logSendToQt(int type); void logLoggerToQt(int level, const char *fmt, va_list args); //void logToQt(char * status, char * substatus, char * msg); - +void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp); #endif /* LOGWRITER_H_ */ -- cgit v1.2.3-55-g7522