KVIrc  4.9.2
DeveloperAPIs
KviNetUtils.h
Go to the documentation of this file.
1 #ifndef _KVI_NETUTILS_H_
2 #define _KVI_NETUTILS_H_
3 //=============================================================================
4 //
5 // File : KviNetUtils.h
6 // Creation date : Sun Jun 18 2000 18:37:27 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2000-2010 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //=============================================================================
26 
27 #include "kvi_settings.h"
28 #include "kvi_inttypes.h"
29 
30 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
31 #include <winsock2.h>
32 #ifdef COMPILE_IPV6_SUPPORT
33 #ifdef WIN2K
34 #include <ws2ip6.h>
35 #else
36 #include <ws2tcpip.h>
37 //#include <tpipv6.h>
38 #define in6_addr in_addr6
39 #endif
40 #else
41 #ifdef WIN2K
42 #include <wspiapi.h>
43 #else
44 #include <ws2tcpip.h>
45 #endif
46 #endif
47 #else
48 #include <sys/types.h>
49 #include <sys/socket.h>
50 #include <netinet/in.h> //in_addr
51 #include <arpa/inet.h> //inet_ntoa inet_ntop and inet_pton depend on this one.
52 #endif
53 
54 #include "KviCString.h"
55 
57 {
58 public:
59  KviSockaddr(const char * szIpAddress, kvi_u32_t uPort, bool bIPv6, bool bUdp = false);
60  KviSockaddr(kvi_u32_t uPort, bool bIPv6, bool bUdp = false); // passive
61  ~KviSockaddr();
62 
63 private:
64  struct addrinfo * m_pData;
65 
66 public:
67  struct sockaddr * socketAddress();
68  size_t addressLength();
69  int addressFamily();
70  bool isIPv6();
71  bool getStringAddress(QString & szBuffer);
72  kvi_u32_t port();
73 };
74 
75 KVILIB_API extern bool kvi_select(int fd, bool * bCanRead, bool * bCanWrite, int iUSecs = 0);
76 
77 // Warning : NOT THREAD SAFE!
78 KVILIB_API extern bool kvi_getLocalHostAddress(QString & buffer);
79 KVILIB_API extern bool kvi_isRoutableIp(const char * ipaddr);
80 KVILIB_API extern bool kvi_isRoutableIpString(const char * ipstring);
81 
82 namespace KviNetUtils
83 {
84  KVILIB_API bool stringIpToBinaryIp(const QString & szStringIp, struct in_addr * address);
85  KVILIB_API bool isValidStringIp(const QString & szStringIp);
86  KVILIB_API bool binaryIpToStringIp(struct in_addr in, QString & szBuffer);
87  KVILIB_API bool getInterfaceAddress(const QString & szInterfaceName, QString & szBuffer);
88 #ifdef COMPILE_IPV6_SUPPORT
89  KVILIB_API bool isValidStringIPv6(const QString & szStringIp);
90  KVILIB_API bool stringIpToBinaryIp_V6(const QString & szStringIp, struct in6_addr * address);
91  KVILIB_API bool binaryIpToStringIp_V6(struct in6_addr in, QString & szBuffer);
92 #endif
93  KVILIB_API bool isRoutableIp(const char * ipaddr);
94  KVILIB_API bool isRoutableIpString(const QString & szIpString);
95  KVILIB_API void formatNetworkBandwidthString(QString & szBuffer, unsigned int uBytesPerSec);
96 }
97 
98 #endif
KVILIB_API bool kvi_getLocalHostAddress(QString &buffer)
Definition: KviNetUtils.cpp:767
KVILIB_API bool kvi_isRoutableIp(const char *ipaddr)
Definition: KviNetUtils.cpp:741
bool binaryIpToStringIp(struct in_addr in, QString &szBuffer)
Definition: KviNetUtils.cpp:623
Definition: KviNetUtils.h:56
bool getInterfaceAddress(const QString &, QString &)
COMPILE_GET_INTERFACE_ADDRESS.
Definition: KviNetUtils.cpp:700
KVILIB_API bool kvi_select(int fd, bool *bCanRead, bool *bCanWrite, int iUSecs=0)
Definition: KviNetUtils.cpp:529
bool isRoutableIpString(const QString &szIpString)
Definition: KviNetUtils.cpp:632
void formatNetworkBandwidthString(QString &szBuffer, unsigned int uBytesPerSec)
Definition: KviNetUtils.cpp:706
bool isRoutableIp(const char *ipaddr)
Definition: KviNetUtils.cpp:641
bool isValidStringIp(const QString &szIp)
Definition: KviNetUtils.cpp:589
unsigned int uPort
Definition: libkvisetup.cpp:44
struct addrinfo * m_pData
Definition: KviNetUtils.h:64
char szBuffer[4096]
Definition: winamp.cpp:77
bool stringIpToBinaryIp(const QString &szStringIp, struct in_addr *address)
Definition: KviNetUtils.cpp:555
This file contains compile time settings.
KVILIB_API bool kvi_isRoutableIpString(const char *ipstring)
Definition: KviNetUtils.cpp:732
#define KVILIB_API
Definition: kvi_settings.h:125