summaryrefslogtreecommitdiffstats
path: root/src/networkinterface.h
blob: 99e71b9e073d69883523b4331eab76f320429dae (plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/***************************************************************************
*   Copyright (C) 2004 by Christoph Thielecke                             *
*   crissi99@gmx.de                                                       *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#ifndef NETWORKINTERFACE_H
#define NETWORKINTERFACE_H

#include <qwidget.h>
#include <qprocess.h>
#include <qstringlist.h>
#include <qobject.h>
#include <qapplication.h>
#include <ktempfile.h>
#include <qhttp.h>
#include <qstringlist.h>
#include "kvpncconfig.h"

/**
Class for interaction with network interface

@author Christoph Thielecke
*/
class NetworkInterface : public QObject
{
	Q_OBJECT

public:
	/**
	 *     Konstruktor
	 * @param parent Pointer to parent widget
	 * @param name Name of the object
	 * @return nothing
	 */
	NetworkInterface( KVpncConfig* config,QApplication *app, QObject *parent = 0, const char *name = 0 );

	/**
	 *     Destruktor
	 * @return nothing
	 */
	~NetworkInterface();

	/**
	 *     Tests if the interface exists
	 * @param Interface The interface to test
	 * @return True if interface exist
	 */
	bool interfaceExist(QString Interface);

	/**
	 *     Retrieves a list of all availiable interfaces
	 * @return List with all interfaces
	 */
	QStringList getAllNetworkInterfaces();

	/**
	 *     Gets the IP from a given interface
	 * @param Interface The interface from which the IP whould be given
	 * @return The IP
	 */
	QString getInterfaceIP(QString Interface);

	QString getInterfaceIP2(QString Interface); // old style
	/**
	 *     Gets the device from a given IP
	 * @param IP The IP which the target interface has
	 * @return The interface where the IP is set
	 */
	QString getInterfaceAddress(QString IP);

	/**
	 *     Gets the interface where the default route points
	 * @return The interface
	 */
	QString getDefaultInterface();

	/**
	 *     Gets the gateway of a given interface
	 * @return The interface
	 */
	QString getGatewayOfInterface(QString interface);

	QString getNetmaskOfInterface(QString interface);

	bool inSameNetwork(QString ip1,QString Netmask1,QString ip2,QString Netmask2);

	/**
	 *     Gets the gateway of the default route
	 * @return The interface
	 */
	QString getGatewayOfDefaultInterface();

	/**
	*		Gets the count of default route entries
	* @return count
	*/
	int getDefaultRouteCount();

	/**
	 *    Gets the IP address which is used for communication with internet connections (same as local address if not behind router)
	 * @return The external IP address
	 */
	QString  getExternalIpAddress();

	bool inSameNetwork(QString ip1,QString ip2);

public slots:
	void readFromStdout();
	void readFromStderr();
	void processHasFinished();
	void readFromStdout_interfaceip();
	void readFromStderr_interfaceip();
	void externalIpDataRecieved(const QHttpResponseHeader & resp);

protected:
	QProcess *proc; //< The process for starting external programs
	QProcess *InterfaceExitsProc;
	QProcess *InterfaceIpProc;
	bool interfaceTest; //< True if interface test is running
	bool retrieveInterfaceIP; //< True if retrieve interface IP is running
	bool retrieveInterfaceAddress; //< True if retrieve interface address is running
	QStringList InterfaceList; //< List with interfaces
	QString InterfaceIP; //< IP for interface
	QString InterfaceAddress; //< Device for IP
	QString GatewayAddress; //< Gateway of Device
	QString GatewayOfInterfaceAddress;
	QString GatewayOfDefaultInterfaceAddress; //< Gateway of Device
	bool interfaceExists; //< True if interface exists
	QString ifconfigbin; //< Path to ifconfig
	QString routebin; //< Path to route
	QString defaultinterface; //< Interface with defaultroute
	QString IPforInterface; //< The Ip for interface
	QString tmpInterface; //< Interface for getting devname
	QApplication *app;
	bool readOutput,getExternalIpAddressRunning;
	KTempFile *tmpfile;
	QHttp *http;
	QString ExternalIpAddress;
	QStringList *env;
	KVpncConfig *GlobalConfig;
};

#endif