summaryrefslogtreecommitdiffstats
path: root/customdhcpcd/src/logwriter.c
diff options
context:
space:
mode:
authorNiklas2011-09-01 16:16:07 +0200
committerNiklas2011-09-01 16:16:07 +0200
commit8024e86b5ce80beb2870654cf29308a0f1f208b8 (patch)
tree90b31ed2d9197999c60c921fc35e0a3db4a70973 /customdhcpcd/src/logwriter.c
parenttried to clean the git. deleted old unused files and folders. moved customdhc... (diff)
downloadfbgui-8024e86b5ce80beb2870654cf29308a0f1f208b8.tar.gz
fbgui-8024e86b5ce80beb2870654cf29308a0f1f208b8.tar.xz
fbgui-8024e86b5ce80beb2870654cf29308a0f1f208b8.zip
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_<interfaceName>
Diffstat (limited to 'customdhcpcd/src/logwriter.c')
-rw-r--r--customdhcpcd/src/logwriter.c74
1 files changed, 60 insertions, 14 deletions
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 <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -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);
+}