summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas2011-09-02 17:06:02 +0200
committerNiklas2011-09-02 17:06:02 +0200
commit603f6e47b2be2b5e03e63f6bee9c6364c92a251e (patch)
tree1cc7c4583e54691b031fe9de3a5e68f7a4bbddf3
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
-rwxr-xr-xLogReceiver/LogReceiverbin130952 -> 141290 bytes
-rw-r--r--LogReceiver/LogReceiver.pro6
-rw-r--r--LogReceiver/Makefile27
-rw-r--r--LogReceiver/interfaceconfiguration.cpp133
-rw-r--r--LogReceiver/interfaceconfiguration.h53
-rw-r--r--LogReceiver/logreceiver.cpp63
-rw-r--r--LogReceiver/logreceiver.h4
-rw-r--r--LogReceiver/ndgui.cpp5
-rw-r--r--LogReceiver/ndgui.h3
-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
13 files changed, 368 insertions, 113 deletions
diff --git a/LogReceiver/LogReceiver b/LogReceiver/LogReceiver
index 21d42f2..d29f4e2 100755
--- a/LogReceiver/LogReceiver
+++ b/LogReceiver/LogReceiver
Binary files differ
diff --git a/LogReceiver/LogReceiver.pro b/LogReceiver/LogReceiver.pro
index 19300fa..9666b2f 100644
--- a/LogReceiver/LogReceiver.pro
+++ b/LogReceiver/LogReceiver.pro
@@ -5,11 +5,13 @@ QT += core \
network
LIBS += -lsysfs
INCLUDEPATH += ../customdhcpcd/src
-HEADERS += ndgui.h \
+HEADERS += interfaceconfiguration.h \
+ ndgui.h \
logreceiver.h \
abortbootdialog.h \
chooseinterfacedialog.h
-SOURCES += ndgui.cpp \
+SOURCES += interfaceconfiguration.cpp \
+ ndgui.cpp \
main.cpp \
logreceiver.cpp \
abortbootdialog.cpp \
diff --git a/LogReceiver/Makefile b/LogReceiver/Makefile
index 2b6b8c6..0ba1fe1 100644
--- a/LogReceiver/Makefile
+++ b/LogReceiver/Makefile
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: LogReceiver
-# Generated by qmake (2.01a) (Qt 4.7.2) on: Thu Sep 1 13:01:39 2011
+# Generated by qmake (2.01a) (Qt 4.7.2) on: Fri Sep 2 14:15:11 2011
# Project: LogReceiver.pro
# Template: app
# Command: /usr/local/Trolltech/QtEmbedded-4.7.2/bin/qmake -o Makefile LogReceiver.pro
@@ -43,19 +43,23 @@ OBJECTS_DIR = ./
####### Files
-SOURCES = ndgui.cpp \
+SOURCES = interfaceconfiguration.cpp \
+ ndgui.cpp \
main.cpp \
logreceiver.cpp \
abortbootdialog.cpp \
- chooseinterfacedialog.cpp moc_ndgui.cpp \
+ chooseinterfacedialog.cpp moc_interfaceconfiguration.cpp \
+ moc_ndgui.cpp \
moc_logreceiver.cpp \
moc_abortbootdialog.cpp \
moc_chooseinterfacedialog.cpp
-OBJECTS = ndgui.o \
+OBJECTS = interfaceconfiguration.o \
+ ndgui.o \
main.o \
logreceiver.o \
abortbootdialog.o \
chooseinterfacedialog.o \
+ moc_interfaceconfiguration.o \
moc_ndgui.o \
moc_logreceiver.o \
moc_abortbootdialog.o \
@@ -167,7 +171,7 @@ qmake: FORCE
dist:
@$(CHK_DIR_EXISTS) .tmp/LogReceiver1.0.0 || $(MKDIR) .tmp/LogReceiver1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.h logreceiver.h abortbootdialog.h chooseinterfacedialog.h .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.cpp main.cpp logreceiver.cpp abortbootdialog.cpp chooseinterfacedialog.cpp .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.ui logreceiver.ui .tmp/LogReceiver1.0.0/ && (cd `dirname .tmp/LogReceiver1.0.0` && $(TAR) LogReceiver1.0.0.tar LogReceiver1.0.0 && $(COMPRESS) LogReceiver1.0.0.tar) && $(MOVE) `dirname .tmp/LogReceiver1.0.0`/LogReceiver1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/LogReceiver1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents interfaceconfiguration.h ndgui.h logreceiver.h abortbootdialog.h chooseinterfacedialog.h .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents interfaceconfiguration.cpp ndgui.cpp main.cpp logreceiver.cpp abortbootdialog.cpp chooseinterfacedialog.cpp .tmp/LogReceiver1.0.0/ && $(COPY_FILE) --parents ndgui.ui logreceiver.ui .tmp/LogReceiver1.0.0/ && (cd `dirname .tmp/LogReceiver1.0.0` && $(TAR) LogReceiver1.0.0.tar LogReceiver1.0.0 && $(COMPRESS) LogReceiver1.0.0.tar) && $(MOVE) `dirname .tmp/LogReceiver1.0.0`/LogReceiver1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/LogReceiver1.0.0
clean:compiler_clean
@@ -188,9 +192,12 @@ mocclean: compiler_moc_header_clean compiler_moc_source_clean
mocables: compiler_moc_header_make_all compiler_moc_source_make_all
-compiler_moc_header_make_all: moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+compiler_moc_header_make_all: moc_interfaceconfiguration.cpp moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
compiler_moc_header_clean:
- -$(DEL_FILE) moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+ -$(DEL_FILE) moc_interfaceconfiguration.cpp moc_ndgui.cpp moc_logreceiver.cpp moc_abortbootdialog.cpp moc_chooseinterfacedialog.cpp
+moc_interfaceconfiguration.cpp: interfaceconfiguration.h
+ /usr/local/Trolltech/QtEmbedded-4.7.2/bin/moc $(DEFINES) $(INCPATH) interfaceconfiguration.h -o moc_interfaceconfiguration.cpp
+
moc_ndgui.cpp: ui_ndgui.h \
logreceiver.h \
chooseinterfacedialog.h \
@@ -233,6 +240,9 @@ compiler_clean: compiler_moc_header_clean compiler_uic_clean
####### Compile
+interfaceconfiguration.o: interfaceconfiguration.cpp interfaceconfiguration.h
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o interfaceconfiguration.o interfaceconfiguration.cpp
+
ndgui.o: ndgui.cpp ndgui.h \
ui_ndgui.h \
logreceiver.h \
@@ -256,6 +266,9 @@ abortbootdialog.o: abortbootdialog.cpp abortbootdialog.h
chooseinterfacedialog.o: chooseinterfacedialog.cpp chooseinterfacedialog.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o chooseinterfacedialog.o chooseinterfacedialog.cpp
+moc_interfaceconfiguration.o: moc_interfaceconfiguration.cpp
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_interfaceconfiguration.o moc_interfaceconfiguration.cpp
+
moc_ndgui.o: moc_ndgui.cpp
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_ndgui.o moc_ndgui.cpp
diff --git a/LogReceiver/interfaceconfiguration.cpp b/LogReceiver/interfaceconfiguration.cpp
new file mode 100644
index 0000000..8ab7cbb
--- /dev/null
+++ b/LogReceiver/interfaceconfiguration.cpp
@@ -0,0 +1,133 @@
+/*
+ * interfaceconfiguration.cpp
+ *
+ * Created on: Sep 2, 2011
+ * Author: niklas
+ */
+#include "interfaceconfiguration.h"
+
+interfaceconfiguration::interfaceconfiguration() {
+
+}
+
+interfaceconfiguration::~interfaceconfiguration() {
+ // TODO Auto-generated destructor stub
+}
+
+/**
+ * This method reads the configuration values out of a file.
+ *
+ * This method reads the configuration values out of a file.
+ * The file has to be created before by the customdhcpcd QProcess.
+ * (Overwrites the old values if they are already present.)
+ *
+ * @param pathToConfig
+ * contains the path to the configuration file.
+ */
+bool interfaceconfiguration::readConfigOutOfFile(QString pathToConfig) {
+ QFile file(pathToConfig);
+ if (file.exists()) {
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ qDebug() << "couldn't open file:" << pathToConfig;
+ return false;
+ }
+ while (!file.atEnd()) {
+ QString line(file.readLine());
+ QStringList splitedLine = line.split("=");
+ QString name = splitedLine.first().trimmed();
+ splitedLine.removeFirst();
+ QString values = splitedLine.first().trimmed();
+ values.remove(QChar('\''));
+ qDebug() << "read config file:" << name << values;
+ if (name.compare("IPADDR") == 0) {
+ this->ipAddress = values;
+ } else if (name.compare("NETMASK") == 0) {
+ this->netmask = values;
+ } else if (name.compare("NETWORK") == 0) {
+ this->network = values;
+ } else if (name.compare("BROADCAST") == 0) {
+ this->broadcast = values;
+ } else if (name.compare("ROUTES") == 0) {
+ this->routes = values;
+ } else if (name.compare("GATEWAYS") == 0) {
+ this->gateways = values;
+ this->gateway = this->gateways.split(" ").first().trimmed();
+ } else if (name.compare("HOSTNAME") == 0) {
+ this->hostname = values;
+ } else if (name.compare("DNSSEARCH") == 0) {
+ this->dnssearch = values;
+ } else if (name.compare("DNSSERVERS") == 0) {
+ this->dnsservers = values;
+ } else if (name.compare("DHCPSID") == 0) {
+ this->dhcpsid = values;
+ } else if (name.compare("INTERFACE") == 0) {
+ this->interface = values;
+ } else if (name.compare("CLIENTID") == 0) {
+ this->clientid = values;
+ } else if (name.compare("DHCPCHADDR") == 0) {
+ this->dhcpchaddr = values;
+ } else {
+ qDebug() << "read unknown name" << name << values;
+ }
+ }
+ } else {
+ qDebug() << "file doesn't exist:" << pathToConfig;
+ return false;
+ }
+ return true;
+}
+
+QString interfaceconfiguration::getBroadcast() {
+ return broadcast;
+}
+
+QString interfaceconfiguration::getClientid() {
+ return clientid;
+}
+
+QString interfaceconfiguration::getDhcpchaddr() {
+ return dhcpchaddr;
+}
+
+QString interfaceconfiguration::getDhcpsid() {
+ return dhcpsid;
+}
+QString interfaceconfiguration::getDnssearch() {
+ return dnssearch;
+}
+
+QString interfaceconfiguration::getDnsservers() {
+ return dnsservers;
+}
+
+QString interfaceconfiguration::getGateways() {
+ return gateways;
+}
+
+QString interfaceconfiguration::getGateway() {
+ return gateway;
+}
+
+QString interfaceconfiguration::getHostname() {
+ return hostname;
+}
+
+QString interfaceconfiguration::getInterface() {
+ return interface;
+}
+
+QString interfaceconfiguration::getIpAddress() {
+ return ipAddress;
+}
+
+QString interfaceconfiguration::getNetmask() {
+ return netmask;
+}
+
+QString interfaceconfiguration::getNetwork() {
+ return network;
+}
+
+QString interfaceconfiguration::getRoutes() {
+ return routes;
+}
diff --git a/LogReceiver/interfaceconfiguration.h b/LogReceiver/interfaceconfiguration.h
new file mode 100644
index 0000000..d12bd14
--- /dev/null
+++ b/LogReceiver/interfaceconfiguration.h
@@ -0,0 +1,53 @@
+/*
+ * interfaceconfiguration.h
+ *
+ * Created on: Sep 2, 2011
+ * Author: niklas
+ */
+
+#ifndef INTERFACECONFIGURATION_H_
+#define INTERFACECONFIGURATION_H_
+
+#include <QtCore>
+
+class interfaceconfiguration: public QObject {
+Q_OBJECT
+
+public:
+ interfaceconfiguration();
+ virtual ~interfaceconfiguration();
+
+ bool readConfigOutOfFile(QString pathToConfig);
+ QString getBroadcast();
+ QString getClientid();
+ QString getDhcpchaddr();
+ QString getDhcpsid();
+ QString getDnssearch();
+ QString getDnsservers();
+ QString getGateways();
+ QString getGateway();
+ QString getHostname();
+ QString getInterface();
+ QString getIpAddress();
+ QString getNetmask();
+ QString getNetwork();
+ QString getRoutes();
+
+private:
+ QString ipAddress;
+ QString netmask;
+ QString network;
+ QString broadcast;
+ QString routes;
+ QString gateway;
+ QString gateways;
+ QString hostname;
+ QString dnssearch;
+ QString dnsservers;
+ QString dhcpsid;
+ QString interface;
+ QString clientid;
+ QString dhcpchaddr;
+};
+
+#endif /* INTERFACECONFIGURATION_H_ */
diff --git a/LogReceiver/logreceiver.cpp b/LogReceiver/logreceiver.cpp
index 1e3f388..199f6ed 100644
--- a/LogReceiver/logreceiver.cpp
+++ b/LogReceiver/logreceiver.cpp
@@ -9,11 +9,14 @@
#include <sysfs/libsysfs.h>
#include "logreceiver.h"
+#include "interfaceconfiguration.h"
#include <qlocalserver.h>
#include <qlocalsocket.h>
#include "status.h"
#include "dhcp.h"
+#include "../common/fbgui.h"
+
LogReceiver::LogReceiver() {
server = new QLocalServer(this);
@@ -212,7 +215,7 @@ void LogReceiver::checkInternetConnection(QString ifName) {
qDebug() << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, "");
}
}
@@ -231,22 +234,8 @@ void LogReceiver::checkConnectivity(QString ifName) {
// get gateway address
QString pathToGatewayFile(DEFAULT_GATEWAY_INFO_LOCATION);
pathToGatewayFile += ifName;
- QFile file(pathToGatewayFile);
- if(file.exists()) {
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qDebug() << "couldnt open file:" << pathToGatewayFile;
- return;
- }
- while(!file.atEnd()) {
- QString line(file.readLine());
- QStringList gateways = line.split(",");
- gateway = gateways.first().trimmed();
- }
- }
- else {
- qDebug() << "file doesn't exist:" << pathToGatewayFile;
- return;
- }
+ interfaceconfiguration ifConf;
+ ifConf.readConfigOutOfFile(pathToGatewayFile);
// delete default route
argList << "del" << "default";
@@ -256,7 +245,10 @@ void LogReceiver::checkConnectivity(QString ifName) {
// add new default route
argList.clear();
- argList << "add" << "default" << "gw" << gateway << ifName;
+ qDebug() << "add default route with:" << ifConf.getGateway()
+ << ifConf.getInterface();
+ argList << "add" << "default" << "gw" << ifConf.getGateway()
+ << ifConf.getInterface();
p = new QProcess(this);
p->start(command, argList);
p->waitForFinished();
@@ -272,7 +264,7 @@ void LogReceiver::checkConnectivity(QString ifName) {
qDebug() << "internet: check passed! for interface" << ifName;
emit
updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, gateway);
}
}
@@ -300,7 +292,8 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
session->open();
if (session->waitForOpened(-1)) {
- qDebug () << "used interface for connectivity check:" <<session->interface().humanReadableName();
+ qDebug() << "used interface for connectivity check:"
+ << session->interface().humanReadableName();
QTcpSocket *tcpSocket = new QTcpSocket(this);
tcpSocket->connectToHost(QString("209.85.148.105"), 80);
if (!tcpSocket->waitForConnected(2000)) {
@@ -308,7 +301,7 @@ void LogReceiver::checkInternetConnectionViaTCP(QString ifName) {
emit updateStatusLabel(ifName, "connection not possible");
} else {
emit updateStatusLabel(ifName, "connection possible");
- emit connectionEstablished(ifName);
+ emit connectionEstablished(ifName, "");
}
} else {
qDebug() << "couldn't open session";
@@ -363,34 +356,24 @@ void LogReceiver::handleNewInput(QLocalSocket * client) {
/**
*
+ * This method is connected to the readyRead Signal of the QLocalSocket
+ * client.
+ * send an ACK to the client with every received message.
*/
void LogReceiver::handleNewInput() {
QLocalSocket* socket = qobject_cast<QLocalSocket *> (QObject::sender());
QLocalSocket * client = clients.value(socket);
-
- while(!client->atEnd()) {
- QString data(client->readLine());
-
- data = data.trimmed();
- //qDebug() << data;
- QStringList lines = data.split("\n");
-
- for (int i = 0; i < lines.length(); i++) {
- handleNewInputLine(client, lines.at(i));
- }
- }
-/*
- QString data(client->readAll());
-
+ QString data(client->read(DHCP_MESSAGE_SIZE));
+ client->write("ACK", ACK_SIZE);
+ client->waitForBytesWritten();
data = data.trimmed();
- qDebug() << data;
+ //qDebug() << data;
QStringList lines = data.split("\n");
for (int i = 0; i < lines.length(); i++) {
handleNewInputLine(client, lines.at(i));
}
- */
}
/**
@@ -412,8 +395,6 @@ void LogReceiver::handleNewInput() {
*
* @param data
* the message. (format <interfaceName>;<state>;<subState>;<msg> )
- *
- *
*/
void LogReceiver::handleNewInputLine(QLocalSocket * client, QString data) {
@@ -539,7 +520,7 @@ void LogReceiver::handleProcessFinished(int exitCode,
}
}
QLocalSocket *client = ifNameToClient.value(ifName, 0);
- if(client != 0) {
+ if (client != 0) {
handleNewInput(client);
}
numberOfProcesses = numberOfProcesses - 1;
diff --git a/LogReceiver/logreceiver.h b/LogReceiver/logreceiver.h
index a8572d0..e30e85b 100644
--- a/LogReceiver/logreceiver.h
+++ b/LogReceiver/logreceiver.h
@@ -18,6 +18,7 @@ Q_OBJECT
#define DEFAULT_QTSOCKETADDRESS "/var/tmp/qt_c_socket_default"
#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/customdhcpcd"
#define DEFAULT_GATEWAY_INFO_LOCATION "/var/tmp/gateways_"
+#define ACK_SIZE 4
public:
LogReceiver();
@@ -38,7 +39,7 @@ private slots:
signals:
void addNewInterface(QString ifName);
void changeProgressBarValue(QString ifName, int newValue);
- void connectionEstablished(QString ifName);
+ void connectionEstablished(QString ifName, QString gateway);
void abortBoot(QString msg);
void updateStatusLabel(QString ifName, QString status);
void allProcessesFinished();
@@ -57,6 +58,7 @@ private:
QNetworkConfigurationManager configurationManager;
QNetworkAccessManager *accessManager;
int numberOfProcesses;
+ //const char ack[ACK_SIZE];
void handleNewInput(QLocalSocket * client);
diff --git a/LogReceiver/ndgui.cpp b/LogReceiver/ndgui.cpp
index a839aef..5543eef 100644
--- a/LogReceiver/ndgui.cpp
+++ b/LogReceiver/ndgui.cpp
@@ -9,7 +9,7 @@ ndgui::ndgui(QWidget *parent)
connect(&logReceiver, SIGNAL(addNewInterface(QString)), this, SLOT(addNewInterface(QString)));
connect(&logReceiver, SIGNAL(changeProgressBarValue(QString , int )), this, SLOT(handleProgress(QString, int)));
- connect(&logReceiver, SIGNAL(connectionEstablished(QString)), this, SLOT(handleConnectionEstablished(QString)));
+ connect(&logReceiver, SIGNAL(connectionEstablished(QString, QString)), this, SLOT(handleConnectionEstablished(QString, QString)));
connect(&logReceiver, SIGNAL(abortBoot(QString)), this, SLOT(handleAbortBoot(QString)));
connect(&logReceiver, SIGNAL(updateStatusLabel(QString,QString)), this, SLOT(handleUpdateStatusLabel(QString, QString)));
connect(&logReceiver, SIGNAL(allProcessesFinished()), this, SLOT(handleAllProcessesFinished()));
@@ -89,8 +89,9 @@ void ndgui::handleProgress(QString ifName, int newValue) {
}
}
-void ndgui::handleConnectionEstablished(QString ifName) {
+void ndgui::handleConnectionEstablished(QString ifName, QString gateway) {
finalUsableInterfaces.append(ifName);
+ // TODO:: Fix this!! use a interfaceconfiguration object instead!!!
}
void ndgui::handleAbortBoot(QString msg) {
diff --git a/LogReceiver/ndgui.h b/LogReceiver/ndgui.h
index e8b0b85..cca603d 100644
--- a/LogReceiver/ndgui.h
+++ b/LogReceiver/ndgui.h
@@ -21,7 +21,7 @@ public:
public slots:
void handleProgress(QString ifName, int newValue);
void addNewInterface(QString ifName);
- void handleConnectionEstablished(QString ifName);
+ void handleConnectionEstablished(QString ifName, QString gateway);
void handleAbortBoot(QString msg);
void handleUpdateStatusLabel(QString ifName, QString status);
void handleAllProcessesFinished();
@@ -40,6 +40,7 @@ private:
LogReceiver logReceiver;
QStringList finalUsableInterfaces;
+ QMap<QString, QString> finalUsableIntefacesMap; // maps interfaceName to its gateway
int numberOfInterfaces;
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_ */