1
//=============================================================================
4
// Creation date : Tue Jul 23 02:54:44 2002 GMT by Szymon Stefanek
6
// This file is part of the KVirc irc client distribution
7
// Copyright (C) 2002-2008 Szymon Stefanek (pragma at kvirc dot net)
9
// This program is FREE software. You can redistribute it and/or
10
// modify it under the terms of the GNU General Public License
11
// as published by the Free Software Foundation; either version 2
12
// of the License, or (at your opinion) any later version.
14
// This program is distributed in the HOPE that it will be USEFUL,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program. If not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
//=============================================================================
29
#include "kvi_options.h"
30
#include "kvi_locale.h"
31
#include "kvi_netutils.h"
32
#include "kvi_ircsocket.h"
33
#include "kvi_irclink.h"
34
#include "kvi_qstring.h"
37
bool dcc_module_get_listen_ip_address(KviCommand *c,KviConsole * pConsole,QString &szListenIp)
40
// Find an interface suitable for listening....
41
// Either from user options or from the current connection...
44
if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault))
46
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed();
47
if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty())
49
if(kvi_isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
51
if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0"))
53
// Try to find the first available IPv4 interface
54
if(!kvi_getLocalHostAddress(szListenIp))
56
if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"),
57
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
61
szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
65
#ifdef COMPILE_IPV6_SUPPORT
66
if(kvi_isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
68
szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
71
if(!kvi_getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data(),szListenIp))
73
KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
74
if(c)c->warning(__tr2qs_ctx("Can't listen on default interface '%s': fix it in the options dialog, disabling the option (so the next dcc will work)","dcc"),
75
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
78
#ifdef COMPILE_IPV6_SUPPORT
83
// the option was empty.. disable it
84
KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
90
if(pConsole->isConnected())
92
//#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports"
93
pConsole->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection());
95
szListenIp = "0.0.0.0"; // huh ? :)
98
szListenIp = "0.0.0.0";
105
bool dcc_kvs_get_listen_ip_address(KviKvsModuleCommandCall *c,KviConsole * pConsole,QString &szListenIp)
108
// Find an interface suitable for listening....
109
// Either from user options or from the current connection...
112
if(KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault))
114
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).trimmed();
115
if(!KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).isEmpty())
117
if(KviNetUtils::isValidStringIp(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
119
if(KviQString::equalCI(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),"0.0.0.0"))
121
// Try to find the first available IPv4 interface
122
if(!kvi_getLocalHostAddress(szListenIp))
124
if(c)c->warning(__tr2qs_ctx("Can't retrieve a suitable local IPV4 address","dcc"),
125
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
129
szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
133
#ifdef COMPILE_IPV6_SUPPORT
134
if(KviNetUtils::isValidStringIPv6(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data()))
136
szListenIp = KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface);
139
if(!KviNetUtils::getInterfaceAddress(KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface),szListenIp))
141
KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
142
if(c)c->warning(__tr2qs_ctx("Can't listen on default interface '%s': fix it in the options dialog, disabling the option (so the next dcc will work)","dcc"),
143
KVI_OPTION_STRING(KviOption_stringDccListenDefaultInterface).toUtf8().data());
146
#ifdef COMPILE_IPV6_SUPPORT
151
// the option was empty.. disable it
152
KVI_OPTION_BOOL(KviOption_boolDccListenOnSpecifiedInterfaceByDefault) = false;
158
if(pConsole->isConnected())
160
//#warning "The IPV6 choice is not OK here.... and maybe allow to bind to specified ports"
161
pConsole->connection()->link()->socket()->getLocalHostIp(szListenIp,pConsole->isIPv6Connection());
163
szListenIp = "0.0.0.0"; // huh ? :)
166
szListenIp = "0.0.0.0";