summaryrefslogtreecommitdiffstats
path: root/customdhcpcd/src
diff options
context:
space:
mode:
authorNiklas2011-09-02 17:06:02 +0200
committerNiklas2011-09-02 17:06:02 +0200
commit603f6e47b2be2b5e03e63f6bee9c6364c92a251e (patch)
tree1cc7c4583e54691b031fe9de3a5e68f7a4bbddf3 /customdhcpcd/src
parentjust minor changes. deltions of unuseful comments (diff)
downloadfbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.tar.gz
fbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.tar.xz
fbgui-603f6e47b2be2b5e03e63f6bee9c6364c92a251e.zip
added a new container class which holds config informations about an interface. also solved the message loss problem by setting the read an writing messages to the same size
Diffstat (limited to 'customdhcpcd/src')
-rw-r--r--customdhcpcd/src/Makefile2
-rwxr-xr-xcustomdhcpcd/src/customdhcpcdbin175308 -> 179744 bytes
-rw-r--r--customdhcpcd/src/logwriter.c180
-rw-r--r--customdhcpcd/src/logwriter.h5
4 files changed, 128 insertions, 59 deletions
diff --git a/customdhcpcd/src/Makefile b/customdhcpcd/src/Makefile
index bb1078f..f3cdb5d 100644
--- a/customdhcpcd/src/Makefile
+++ b/customdhcpcd/src/Makefile
@@ -4,7 +4,7 @@
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
+ info.c interface.c ipv4ll.c logger.c signal.c socket.c logwriter.c
MAN=
VERSION= 3.2.3
diff --git a/customdhcpcd/src/customdhcpcd b/customdhcpcd/src/customdhcpcd
index 3676699..1b80a4d 100755
--- a/customdhcpcd/src/customdhcpcd
+++ b/customdhcpcd/src/customdhcpcd
Binary files differ
diff --git a/customdhcpcd/src/logwriter.c b/customdhcpcd/src/logwriter.c
index a96bbda..0a78995 100644
--- a/customdhcpcd/src/logwriter.c
+++ b/customdhcpcd/src/logwriter.c
@@ -14,12 +14,12 @@
#include "dhcp.h"
#include "dhcpcd.h"
#include "errno.h"
+#include "info.h"
#include "logger.h"
#include "logwriter.h"
#include "status.h"
#include "../../common/fbgui.h" // for constants
-
/*sockets for the logger and the qt-reader */
int sockfd, ns;
int retval = -1;
@@ -31,7 +31,7 @@ void setSocketName(const char * sn) {
snprintf(socketName, sizeof(socketName), "%s", sn);
}
-void setInterfaceName(const char * in){
+void setInterfaceName(const char * in) {
snprintf(interfaceName, sizeof(interfaceName), "%s", in);
}
@@ -41,10 +41,10 @@ int initQtLoggerSocket() {
*/
struct sockaddr_un serv_addr;
- fprintf(stdout,"start init \n");
+ fprintf(stdout, "start init \n");
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
if (sockfd < 0) {
- fprintf(stdout,"ERROR opening socket \n");
+ fprintf(stdout, "ERROR opening socket \n");
retval = sockfd;
return sockfd;
}
@@ -52,13 +52,13 @@ int initQtLoggerSocket() {
strcpy(serv_addr.sun_path, socketName);
retval = connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
- if ( retval < 0)
- fprintf(stdout,"ERROR connecting \n");
- fprintf(stdout,"init Qt Logger Socket done \n");
+ if (retval < 0)
+ fprintf(stdout, "ERROR connecting \n");
+ fprintf(stdout, "init Qt Logger Socket done \n");
return retval;
}
-void closeQtLoggerSocket (){
+void closeQtLoggerSocket() {
close(sockfd);
}
@@ -70,22 +70,22 @@ void sendToQt(log_msg * msg) {
char outbuf[DHCP_MESSAGE_SIZE];
char ack[ACK_SIZE];
/*
- 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);
- */
+ 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);
+ */
memset(outbuf, '\0', DHCP_MESSAGE_SIZE);
- ret = snprintf(outbuf, DHCP_MESSAGE_SIZE, tpl, msg->device, msg->status, msg->substatus,
- msg->msg);
+ ret = snprintf(outbuf, DHCP_MESSAGE_SIZE, tpl, msg->device, msg->status,
+ msg->substatus, msg->msg);
if (ret < 1) {
- syslog(LOG_INFO, "[fbgui] ERROR filling message buffer");
- return;
+ syslog(LOG_INFO, "[fbgui] ERROR filling message buffer");
+ return;
}
if (outbuf != NULL) {
n = send(sockfd, outbuf, DHCP_MESSAGE_SIZE, 0);
@@ -97,7 +97,7 @@ void sendToQt(log_msg * msg) {
syslog(LOG_ERR, "[fbgui] ERROR writing to socket: [%d:%d] %s (%s)",
msg->status, msg->substatus, msg->msg, msg->device);
}
- memset(ack,0,ACK_SIZE);
+ memset(ack, 0, ACK_SIZE);
if ((t = recv(sockfd, ack, ACK_SIZE, 0)) > 0) {
syslog(LOG_ERR, "[fbgui] recv ack echo> %s", ack);
printf("received: %s\n", ack);
@@ -121,43 +121,65 @@ void logToQt(int status, int substatus, const char * msg) {
}
void logSendToQt(int type) {
- switch(type) {
- case DHCP_DISCOVER:
- logToQt(LOG_INFO, DHCP_DISCOVER, "send discover");
- break;
- case DHCP_OFFER:
- logToQt(LOG_INFO, DHCP_OFFER, "send offer");
- break;
- case DHCP_REQUEST:
- logToQt(LOG_INFO, DHCP_REQUEST, "send request");
- break;
- case DHCP_DECLINE:
- logToQt(LOG_INFO, DHCP_DECLINE, "send decline");
- break;
- case DHCP_ACK:
- logToQt(LOG_INFO, DHCP_ACK, "send ack");
- break;
- case DHCP_NAK:
- logToQt(LOG_INFO, DHCP_NAK, "send nak");
- break;
- case DHCP_RELEASE:
- logToQt(LOG_INFO, DHCP_RELEASE, "send release");
- break;
- case DHCP_INFORM:
- logToQt(LOG_INFO, DHCP_INFORM, "send inform");
- break;
- default :
- break;
- }
+ switch (type) {
+ case DHCP_DISCOVER:
+ logToQt(LOG_INFO, DHCP_DISCOVER, "send discover");
+ break;
+ case DHCP_OFFER:
+ logToQt(LOG_INFO, DHCP_OFFER, "send offer");
+ break;
+ case DHCP_REQUEST:
+ logToQt(LOG_INFO, DHCP_REQUEST, "send request");
+ break;
+ case DHCP_DECLINE:
+ logToQt(LOG_INFO, DHCP_DECLINE, "send decline");
+ break;
+ case DHCP_ACK:
+ logToQt(LOG_INFO, DHCP_ACK, "send ack");
+ break;
+ case DHCP_NAK:
+ logToQt(LOG_INFO, DHCP_NAK, "send nak");
+ break;
+ case DHCP_RELEASE:
+ logToQt(LOG_INFO, DHCP_RELEASE, "send release");
+ break;
+ case DHCP_INFORM:
+ logToQt(LOG_INFO, DHCP_INFORM, "send inform");
+ break;
+ default:
+ break;
+ }
}
void logLoggerToQt(int level, const char *fmt, va_list args) {
- vsnprintf(mesg, sizeof(mesg), fmt, args);
- strcat(mesg, "\n");
- logToQt(level, DHCPCD_LOG, mesg);
+ vsnprintf(mesg, sizeof(mesg), fmt, args);
+ strcat(mesg, "\n");
+ logToQt(level, DHCPCD_LOG, mesg);
}
+static void print_addresses (FILE *f, const struct address_head *addresses)
+{
+ const address_t *addr;
+
+ STAILQ_FOREACH (addr, addresses, entries) {
+ fprintf (f, "%s", inet_ntoa (addr->address));
+ if (STAILQ_NEXT (addr, entries))
+ fprintf (f, " ");
+ }
+}
void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp) {
+ /*void logGatewayToFile(const interface_t iface, const dhcp_t *dhcp,
+ const options_t options)*/
+ //char path[QTSOCKETADDRESSLENGTH];
+
+ /*
+ strcpy(path, DEFAULT_GATEWAY_INFO_LOCATION);
+ strcat(path, iface.name);
+ strcpy(iface.infofile, path);
+ options.test = false;
+ syslog(LOG_INFO, "[fbgui] try to open file: %s", iface.infofile);
+ write_info(&iface, dhcp, &options, true);
+ */
FILE *f;
route_t *route;
char path[QTSOCKETADDRESSLENGTH];
@@ -165,24 +187,68 @@ void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp) {
strcpy(path, DEFAULT_GATEWAY_INFO_LOCATION);
strcat(path, iface->name);
- syslog (LOG_INFO, "[fbgui] try to open file: %s", path);
+ 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));
+ //TODO: exit/return ..
+ return;
+ }
+
+ if (dhcp->address.s_addr) {
+ struct in_addr n;
+ n.s_addr = dhcp->address.s_addr & dhcp->netmask.s_addr;
+ fprintf(f, "IPADDR='%s'\n", inet_ntoa(dhcp->address));
+ fprintf(f, "NETMASK='%s'\n", inet_ntoa(dhcp->netmask));
+ fprintf(f, "NETWORK='%s'\n", inet_ntoa(n));
+ fprintf(f, "BROADCAST='%s'\n", inet_ntoa(dhcp->broadcast));
}
if (dhcp->routes) {
bool doneone = false;
+ fprintf(f, "ROUTES='");
+ STAILQ_FOREACH (route, dhcp->routes, entries) {
+ if (route->destination.s_addr != 0) {
+ if (doneone)
+ fprintf(f, " ");
+ fprintf(f, "%s", inet_ntoa(route->destination));
+ fprintf(f, ",%s", inet_ntoa(route->netmask));
+ fprintf(f, ",%s", inet_ntoa(route->gateway));
+ doneone = true;
+ }
+ }
+ fprintf(f, "'\n");
+
+ doneone = false;
+ fprintf(f, "GATEWAYS='");
STAILQ_FOREACH (route, dhcp->routes, entries) {
if (route->destination.s_addr == 0) {
if (doneone)
- fprintf(f, ",");
+ fprintf(f, " ");
fprintf(f, "%s", inet_ntoa(route->gateway));
doneone = true;
}
}
- fprintf(f, "\n");
+ fprintf(f, "'\n");
+ }
+
+ fprintf(f, "HOSTNAME='%s", dhcp->hostname);
+ fprintf(f, "'\n");
+ fprintf(f, "DNSSEARCH='%s", dhcp->dnssearch);
+ fprintf(f, "'\n");
+
+ if (dhcp->dnsservers) {
+ fprintf(f, "DNSSERVERS='");
+ print_addresses(f, dhcp->dnsservers);
+ fprintf(f, "'\n");
+ }
+ fprintf(f, "INTERFACE='%s", iface->name);
+ fprintf(f, "'\n");
+ if (iface->clientid_len > 0) {
+ fprintf(f, "CLIENTID='%s'\n", hwaddr_ntoa(iface->clientid,
+ iface->clientid_len));
}
+ fprintf(f, "DHCPCHADDR='%s'\n", hwaddr_ntoa(iface->hwaddr, iface->hwlen));
fclose(f);
}
diff --git a/customdhcpcd/src/logwriter.h b/customdhcpcd/src/logwriter.h
index bb834cb..7e41411 100644
--- a/customdhcpcd/src/logwriter.h
+++ b/customdhcpcd/src/logwriter.h
@@ -8,6 +8,9 @@
#ifndef LOGWRITER_H_
#define LOGWRITER_H_
+#include <arpa/inet.h>
+#include "dhcp.h"
+#include "interface.h"
#include "dhcpcd.h"
#define LOG_MSG_SIZE 1024
@@ -32,6 +35,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);
+void logGatewayToFile(const interface_t *iface, const dhcp_t *dhcp);
#endif /* LOGWRITER_H_ */