summaryrefslogtreecommitdiffstats
path: root/src/networkinterface.h
blob: 651e05e31d698e614e8e96116bb46e9578fa4e4a (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
158
/***************************************************************************
*   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 <tqwidget.h>
#include <tqprocess.h>
#include <tqstringlist.h>
#include <tqobject.h>
#include <tqapplication.h>
#include <tdetempfile.h>
#include <tqhttp.h>
#include <tqstringlist.h>
#include "kvpncconfig.h"

/**
Class for interaction with network interface

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

public:
	/**
	 *     Konstruktor
	 * @param parent Pointer to parent widget
	 * @param name Name of the object
	 * @return nothing
	 */
	NetworkInterface( KVpncConfig* config,TQApplication *app, TQObject *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(TQString Interface);

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

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

	TQString getInterfaceIP2(TQString 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
	 */
	TQString getInterfaceAddress(TQString IP);

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

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

	TQString getNetmaskOfInterface(TQString interface);

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

	/**
	 *     Gets the gateway of the default route
	 * @return The interface
	 */
	TQString 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
	 */
	TQString  getExternalIpAddress();

	bool inSameNetwork(TQString ip1,TQString ip2);

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

protected:
	TQProcess *proc; //< The process for starting external programs
	TQProcess *InterfaceExitsProc;
	TQProcess *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
	TQStringList InterfaceList; //< List with interfaces
	TQString InterfaceIP; //< IP for interface
	TQString InterfaceAddress; //< Device for IP
	TQString GatewayAddress; //< Gateway of Device
	TQString GatewayOfInterfaceAddress;
	TQString GatewayOfDefaultInterfaceAddress; //< Gateway of Device
	bool interfaceExists; //< True if interface exists
	TQString ifconfigbin; //< Path to ifconfig
	TQString routebin; //< Path to route
	TQString defaultinterface; //< Interface with defaultroute
	TQString IPforInterface; //< The Ip for interface
	TQString tmpInterface; //< Interface for getting devname
	TQApplication *app;
	bool readOutput,getExternalIpAddressRunning;
	KTempFile *tmpfile;
	TQHttp *http;
	TQString ExternalIpAddress;
	TQStringList *env;
	KVpncConfig *GlobalConfig;
};

#endif