summaryrefslogtreecommitdiffstats
path: root/workspace/networkDiscovery/networkdiscovery.cpp
blob: e308de4e2c2eeacaa607f264ca8886c9d7d48b3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <sys/file.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <paths.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif
#include "dhcpcd/config.h"
#include "dhcpcd/client.h"
#include "dhcpcd/dhcpcd.h"
#include "dhcpcd/dhcp.h"
#include "dhcpcd/interface.h"
#include "dhcpcd/logger.h"
#include "dhcpcd/socket.h"
#include "dhcpcd/version.h"
#ifdef __cplusplus
}
#endif

#ifdef __cplusplus

#include <QtGui>
#include "networkdiscovery.h"
#include <QNetworkInterface>
#include <QtNetwork>


#endif

NetworkDiscovery::NetworkDiscovery(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
	QList<QNetworkInterface> interfaces = getListOfNetworkInterfaces();

	/**
	 * test if i get some dhcp values for the dummy0 interface
	 */
	doDHCP(interfaces);
	doDhcp(interfaces.first());
}

NetworkDiscovery::~NetworkDiscovery()
{

}

QList<QNetworkInterface> NetworkDiscovery::getListOfNetworkInterfaces() {
	QList<QNetworkInterface> nIList = QNetworkInterface::allInterfaces();
	QList<QNetworkInterface> result;
	foreach(QNetworkInterface nI, nIList) {
		if (((!(nI.flags() & QNetworkInterface::CanBroadcast)||
				nI.flags() & QNetworkInterface::IsLoopBack) ||
				nI.flags() & QNetworkInterface::IsPointToPoint))
		{
			continue;
		}
	   	qDebug() << nI.humanReadableName();
	   	result.append(nI);
	}
	return result;
}

int NetworkDiscovery::doDHCP(QList<QNetworkInterface> interfaces)
{
    return 0;
}



int NetworkDiscovery::doDhcp(QNetworkInterface interface)
{
    nd_main("eth0");
}

void NetworkDiscovery::listenToLogger()
{
    skt = new QLocalSocket(this);

    connect(skt, SIGNAL(readyRead()), this, SLOT(handleLoggedMessage()));
    connect(skt, SIGNAL(error(QLocalSocket::LocalSocketError)),
                 this, SLOT(displayError(QLocalSocket::LocalSocketError)));
    skt->connectToServer(COM_CH);
}

void NetworkDiscovery::handleLoggedMessage()
{

}

void NetworkDiscovery::displayError(QLocalSocket::LocalSocketError socketError)
 {
     switch (socketError) {
     case QLocalSocket::ServerNotFoundError:
         QMessageBox::information(this, tr("Fortune Client"),
                                  tr("The host was not found. Please check the "
                                     "host name and port settings."));
         break;
     case QLocalSocket::ConnectionRefusedError:
         QMessageBox::information(this, tr("Fortune Client"),
                                  tr("The connection was refused by the peer. "
                                     "Make sure the fortune server is running, "
                                     "and check that the host name and port "
                                     "settings are correct."));
         break;
     case QLocalSocket::PeerClosedError:
         break;
     default:
         QMessageBox::information(this, tr("Fortune Client"),
                                  tr("The following error occurred: %1.")
                                  .arg(skt->errorString()));
     }
 }