ipsock.h

Go to the documentation of this file.
00001 /*
00002  * ipsock.h
00003  *
00004  * Internet Protocol socket I/O channel class.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
00025  * All Rights Reserved.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Log: ipsock.h,v $
00030  * Revision 1.90  2007/08/22 05:00:02  rjongbloed
00031  * Added function to return local and peer address as string in "addr:port" format.
00032  *
00033  * Revision 1.89  2007/06/27 03:15:21  rjongbloed
00034  * Added ability to select filtering of down network interfaces.
00035  *
00036  * Revision 1.88  2007/05/21 06:09:25  csoutheren
00037  * Add paramaterless constructor for PIPSocket::InterfaceEntry
00038  *
00039  * Revision 1.87  2007/02/19 04:37:19  csoutheren
00040  * Fixed parsing in PIPSocketAddressAndPort
00041  *
00042  * Revision 1.86  2007/02/01 03:18:42  csoutheren
00043  * Add extra features to PIPSocketAddressAndPort
00044  *
00045  * Revision 1.85  2007/01/31 00:44:34  csoutheren
00046  * Fix warning on Linux
00047  *
00048  * Revision 1.84  2007/01/30 02:26:21  csoutheren
00049  * Fix minor problem with PIPSocketAddressAndPort
00050  *
00051  * Revision 1.83  2006/10/03 06:29:38  csoutheren
00052  * Add PIPSocketAndPort::AsString
00053  *
00054  * Revision 1.82  2006/07/05 03:58:09  csoutheren
00055  * Additional implementation of PIPSocketAddressAndPort
00056  *
00057  * Revision 1.81  2006/04/09 07:05:40  rjongbloed
00058  * Moved output stream operator for PString from sockets code to string code and fixed
00059  *   its implemetation to continue to use PrintOn. Why it was added is unknown, probably
00060  *   a compiler issue, but it should not be in a random source file!
00061  *
00062  * Revision 1.80  2006/02/26 11:51:20  csoutheren
00063  * Extended DNS test program to include URL based SRV lookups
00064  * Re-arranged SRV lookup code to allow access to internal routine
00065  * Reformatted code
00066  *
00067  * Revision 1.79  2005/11/30 12:47:37  csoutheren
00068  * Removed tabs, reformatted some code, and changed tags for Doxygen
00069  *
00070  * Revision 1.78  2005/11/25 03:43:47  csoutheren
00071  * Fixed function argument comments to be compatible with Doxygen
00072  *
00073  * Revision 1.77  2005/07/13 11:48:41  csoutheren
00074  * Backported QOS changes from isvo branch
00075  *
00076  * Revision 1.76.2.1  2005/04/25 13:30:41  shorne
00077  * Extra support for DHCP Environment (Win32)
00078  *
00079  * Revision 1.76  2005/03/22 07:29:29  csoutheren
00080  * Fixed problem where PStrings sometimes get case into
00081  * PIPSocket::Address when outputting to an ostream
00082  *
00083  * Revision 1.75  2005/02/13 23:01:35  csoutheren
00084  * Fixed problem with not detecting mapped IPV6 addresses within the RFC1918
00085  * address range as RFC1918
00086  *
00087  * Revision 1.74  2005/02/07 12:12:33  csoutheren
00088  * Expanded interface list routines to include IPV6 addresses
00089  * Added IPV6 to GetLocalAddress
00090  *
00091  * Revision 1.73  2005/02/07 00:47:17  csoutheren
00092  * Changed IPV6 code to use standard IPV6 macros
00093  *
00094  * Revision 1.72  2005/02/04 05:50:27  csoutheren
00095  * Extended IsRFC1918 to handle IPV6
00096  *
00097  * Revision 1.71  2005/01/16 21:27:01  csoutheren
00098  * Changed PIPSocket::IsAny to be const
00099  *
00100  * Revision 1.70  2004/12/20 07:59:33  csoutheren
00101  * Fixed operator *= for IPV6
00102  *
00103  * Revision 1.69  2004/12/14 14:24:19  csoutheren
00104  * Added PIPSocket::Address::operator*= to compare IPV4 addresses
00105  * to IPV4-compatible IPV6 addresses. More documentation needed
00106  * once this is tested as working
00107  *
00108  * Revision 1.68  2004/12/14 06:20:29  csoutheren
00109  * Added function to get address of network interface
00110  *
00111  * Revision 1.67  2004/08/24 07:08:13  csoutheren
00112  * Added use of recvmsg to determine which interface UDP packets arrive on
00113  *
00114  * Revision 1.66  2004/07/11 07:56:35  csoutheren
00115  * Applied jumbo VxWorks patch, thanks to Eize Slange
00116  *
00117  * Revision 1.65  2004/04/18 04:33:36  rjongbloed
00118  * Changed all operators that return BOOL to return standard type bool. This is primarily
00119  *   for improved compatibility with std STL usage removing many warnings.
00120  *
00121  * Revision 1.64  2004/04/07 05:29:50  csoutheren
00122  * Added function to detect RFC 1918 addresses
00123  *
00124  * Revision 1.63  2004/02/23 17:27:19  ykiryanov
00125  * Added == and != operators for in_addr_t on BeOS as suggested by Craig Southeren to please compiler
00126  *
00127  * Revision 1.62  2003/09/17 05:41:58  csoutheren
00128  * Removed recursive includes
00129  *
00130  * Revision 1.61  2003/09/17 01:18:02  csoutheren
00131  * Removed recursive include file system and removed all references
00132  * to deprecated coooperative threading support
00133  *
00134  * Revision 1.60  2003/05/21 09:34:43  rjongbloed
00135  * Name lookup support for IPv6, thanks again Sébastien Josset
00136  *
00137  * Revision 1.59  2003/04/28 02:55:08  robertj
00138  * Added function to see at run time if IPv6 available, thanks Sebastien Josset
00139  *
00140  * Revision 1.58  2003/04/03 08:43:23  robertj
00141  * Added IPv4 mapping into IPv6, thanks Sebastien Josset
00142  *
00143  * Revision 1.57  2003/03/26 05:36:37  robertj
00144  * More IPv6 support (INADDR_ANY handling), thanks Sébastien Josset
00145  *
00146  * Revision 1.56  2003/02/03 11:23:32  robertj
00147  * Added function to get pointer to IP address data.
00148  *
00149  * Revision 1.55  2003/02/03 08:51:44  robertj
00150  * Fixed compatibility with old code so taking address of PIPSocket::Address
00151  *   gets address of 4 or 16 byte IP address.
00152  *
00153  * Revision 1.54  2002/12/02 03:57:18  robertj
00154  * More RTEMS support patches, thank you Vladimir Nesic.
00155  *
00156  * Revision 1.53  2002/11/02 00:32:21  robertj
00157  * Further fixes to VxWorks (Tornado) port, thanks Andreas Sikkema.
00158  *
00159  * Revision 1.52  2002/10/29 07:59:45  robertj
00160  * Changed in_addr6 to more universally used in6_addr.
00161  *
00162  * Revision 1.51  2002/10/08 14:31:43  robertj
00163  * Changed for IPv6 support, thanks Sébastien Josset.
00164  *
00165  * Revision 1.50  2002/10/08 12:41:51  robertj
00166  * Changed for IPv6 support, thanks Sébastien Josset.
00167  *
00168  * Revision 1.49  2002/09/16 01:08:59  robertj
00169  * Added #define so can select if #pragma interface/implementation is used on
00170  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00171  *
00172  * Revision 1.48  2001/12/13 09:17:01  robertj
00173  * Added function to convert PString to IP address with error checking that can
00174  *   distinguish between 0.0.0.0 or 255.255.255.255 and illegal address.
00175  *
00176  * Revision 1.47  2001/09/14 08:00:38  robertj
00177  * Added new versions of Conenct() to allow binding to a specific local interface.
00178  *
00179  * Revision 1.46  2001/05/22 12:49:32  robertj
00180  * Did some seriously wierd rewrite of platform headers to eliminate the
00181  *   stupid GNU compiler warning about braces not matching.
00182  *
00183  * Revision 1.45  2001/03/05 04:18:27  robertj
00184  * Added net mask to interface info returned by GetInterfaceTable()
00185  *
00186  * Revision 1.44  2001/01/29 06:41:18  robertj
00187  * Added printing of entry of interface table.
00188  *
00189  * Revision 1.43  2000/06/26 11:17:19  robertj
00190  * Nucleus++ port (incomplete).
00191  *
00192  * Revision 1.42  1999/09/10 04:35:42  robertj
00193  * Added Windows version of PIPSocket::GetInterfaceTable() function.
00194  *
00195  * Revision 1.41  1999/09/10 02:31:42  craigs
00196  * Added interface table routines
00197  *
00198  * Revision 1.40  1999/08/30 02:21:03  robertj
00199  * Added ability to listen to specific interfaces for IP sockets.
00200  *
00201  * Revision 1.39  1999/08/08 09:04:01  robertj
00202  * Added operator>> for PIPSocket::Address class.
00203  *
00204  * Revision 1.38  1999/03/09 02:59:50  robertj
00205  * Changed comments to doc++ compatible documentation.
00206  *
00207  * Revision 1.37  1999/02/23 07:19:22  robertj
00208  * Added [] operator PIPSocket::Address to get the bytes out of an IP address.
00209  *
00210  * Revision 1.36  1999/02/16 08:12:00  robertj
00211  * MSVC 6.0 compatibility changes.
00212  *
00213  * Revision 1.35  1998/12/21 07:22:50  robertj
00214  * Virtualised functions for SOCKS support.
00215  *
00216  * Revision 1.34  1998/12/18 04:34:14  robertj
00217  * PPC Linux GNU C compatibility.
00218  *
00219  * Revision 1.33  1998/11/30 08:57:32  robertj
00220  * New directory structure
00221  *
00222  * Revision 1.32  1998/11/22 11:30:08  robertj
00223  * Check route table function to get a list
00224  *
00225  * Revision 1.31  1998/11/19 05:18:22  robertj
00226  * Added route table manipulation functions to PIPSocket class.
00227  *
00228  * Revision 1.30  1998/09/23 06:20:45  robertj
00229  * Added open source copyright license.
00230  *
00231  * Revision 1.29  1997/12/11 10:28:57  robertj
00232  * Added operators for IP address to DWORD conversions.
00233  *
00234  * Revision 1.28  1996/12/17 11:08:05  robertj
00235  * Added DNS name cache clear command.
00236  *
00237  * Revision 1.27  1996/11/30 12:10:00  robertj
00238  * Added Connect() variant so can set the local port number on link.
00239  *
00240  * Revision 1.26  1996/11/16 10:48:49  robertj
00241  * Fixed missing const in PIPSocket::Address stream output operator..
00242  *
00243  * Revision 1.25  1996/11/04 03:40:54  robertj
00244  * Moved address printer from inline to source.
00245  *
00246  * Revision 1.24  1996/09/14 13:09:21  robertj
00247  * Major upgrade:
00248  *   rearranged sockets to help support IPX.
00249  *   added indirect channel class and moved all protocols to descend from it,
00250  *   separating the protocol from the low level byte transport.
00251  *
00252  * Revision 1.23  1996/08/25 09:33:55  robertj
00253  * Added function to detect "local" host name.
00254  *
00255  * Revision 1.22  1996/03/26 00:51:13  robertj
00256  * Added GetLocalAddress() variant that returns port number as well.
00257  *
00258  * Revision 1.21  1996/03/16 04:41:30  robertj
00259  * Changed all the get host name and get host address functions to be more consistent.
00260  *
00261  * Revision 1.20  1996/03/03 07:37:56  robertj
00262  * Added Reusability clause to the Listen() function on sockets.
00263  *
00264  * Revision 1.19  1996/02/25 03:00:31  robertj
00265  * Added operator<< to PIPSocket::Address.
00266  * Moved some socket functions to platform dependent code.
00267  *
00268  * Revision 1.18  1996/02/08 12:11:19  robertj
00269  * Added GetPeerAddress that returns a port.
00270  *
00271  * Revision 1.17  1996/01/28 14:07:31  robertj
00272  * Changed service parameter to PString for ease of use in GetPortByService function
00273  * Fixed up comments.
00274  *
00275  * Revision 1.16  1995/12/23 03:44:59  robertj
00276  * Fixed unix portability issues.
00277  *
00278  * Revision 1.15  1995/12/10 11:32:11  robertj
00279  * Numerous fixes for sockets.
00280  *
00281  * Revision 1.14  1995/10/14 14:57:26  robertj
00282  * Added internet address to string conversion functionality.
00283  *
00284  * Revision 1.13  1995/07/02 01:18:19  robertj
00285  * Added static functions to get the current host name/address.
00286  *
00287  * Revision 1.12  1995/06/17 00:41:40  robertj
00288  * More logical design of port numbers and service names.
00289  *
00290  * Revision 1.11  1995/03/18 06:26:44  robertj
00291  * Changed IP address variable for GNU compatibility.
00292  *
00293  * Revision 1.10  1995/03/14  12:41:38  robertj
00294  * Updated documentation to use HTML codes.
00295  *
00296  * Revision 1.9  1995/03/12  04:38:41  robertj
00297  * Added more functionality.
00298  *
00299  * Revision 1.8  1995/01/02  12:28:24  robertj
00300  * Documentation.
00301  * Added more socket functions.
00302  *
00303  * Revision 1.7  1995/01/01  01:07:33  robertj
00304  * More implementation.
00305  *
00306  * Revision 1.6  1994/12/15  12:47:14  robertj
00307  * Documentation.
00308  *
00309  * Revision 1.5  1994/08/23  11:32:52  robertj
00310  * Oops
00311  *
00312  * Revision 1.4  1994/08/22  00:46:48  robertj
00313  * Added pragma fro GNU C++ compiler.
00314  *
00315  * Revision 1.3  1994/08/21  23:43:02  robertj
00316  * Spelt Berkeley correctly.
00317  *
00318  * Revision 1.2  1994/07/25  03:36:03  robertj
00319  * Added sockets to common, normalising to same comment standard.
00320  *
00321  */
00322 
00323 #ifndef _PIPSOCKET
00324 #define _PIPSOCKET
00325 
00326 #ifdef P_USE_PRAGMA
00327 #pragma interface
00328 #endif
00329 
00330 #include <ptlib/socket.h>
00331 
00332 #ifdef P_HAS_QOS
00333 #ifdef _WIN32
00334 #ifdef P_KNOCKOUT_WINSOCK2 
00335    #include "IPExport.h"
00336 #endif // KNOCKOUT_WINSOCK2
00337 #endif // _WIN32
00338 #endif // P_HAS_QOS
00339 
00347 class PIPSocket : public PSocket
00348 {
00349   PCLASSINFO(PIPSocket, PSocket);
00350   protected:
00351     /* Create a new Internet Protocol socket based on the port number
00352        specified.
00353      */
00354     PIPSocket();
00355 
00356   public:
00360     class Address : public PObject {
00361       public:
00362 
00365 
00366         Address();
00367 
00371         Address(const PString & dotNotation);
00372 
00374         Address(PINDEX len, const BYTE * bytes);
00375 
00377         Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
00378 
00380         Address(DWORD dw);
00381 
00383         Address(const in_addr & addr);
00384 
00385 #if P_HAS_IPV6
00387         Address(const in6_addr & addr);
00388 
00391         Address(const int ai_family, const int ai_addrlen,struct sockaddr *ai_addr);
00392 #endif
00393 
00394 #ifdef __NUCLEUS_NET__
00395         Address(const struct id_struct & addr);
00396         Address & operator=(const struct id_struct & addr);
00397 #endif
00398 
00400         Address & operator=(const in_addr & addr);
00401 
00402 #if P_HAS_IPV6
00404         Address & operator=(const in6_addr & addr);
00405 #endif
00406 
00408         Address & operator=(const PString & dotNotation);
00409 
00411         Address & operator=(DWORD dw);
00413 
00415         Comparison Compare(const PObject & obj) const;
00416         bool operator==(const Address & addr) const { return Compare(addr) == EqualTo; }
00417         bool operator!=(const Address & addr) const { return Compare(addr) != EqualTo; }
00418 #if P_HAS_IPV6
00419         bool operator==(in6_addr & addr) const;
00420         bool operator!=(in6_addr & addr) const { return !operator==(addr); }
00421 #endif
00422         bool operator==(in_addr & addr) const;
00423         bool operator!=(in_addr & addr) const { return !operator==(addr); }
00424         bool operator==(DWORD dw) const;
00425         bool operator!=(DWORD dw) const   { return !operator==(dw); }
00426 #ifdef P_VXWORKS 
00427         bool operator==(long unsigned int u) const { return  operator==((DWORD)u); }
00428         bool operator!=(long unsigned int u) const { return !operator==((DWORD)u); }
00429 #endif
00430 #ifdef _WIN32
00431         bool operator==(unsigned u) const { return  operator==((DWORD)u); }
00432         bool operator!=(unsigned u) const { return !operator==((DWORD)u); }
00433 #endif
00434 #ifdef P_RTEMS
00435         bool operator==(u_long u) const { return  operator==((DWORD)u); }
00436         bool operator!=(u_long u) const { return !operator==((DWORD)u); }
00437 #endif
00438 #ifdef __BEOS__
00439         bool operator==(in_addr_t a) const { return  operator==((DWORD)a); }
00440         bool operator!=(in_addr_t a) const { return !operator==((DWORD)a); }
00441 #endif
00442         bool operator==(int i) const      { return  operator==((DWORD)i); }
00443         bool operator!=(int i) const      { return !operator==((DWORD)i); }
00444 
00447 #if P_HAS_IPV6
00448         bool operator*=(const Address & addr) const;
00449 #else
00450         bool operator*=(const Address & addr) const { return operator==(addr); }
00451 #endif
00452 
00454         PString AsString() const;
00455 
00457         BOOL FromString(
00458           const PString & str
00459         );
00460 
00462         operator PString() const;
00463 
00465         operator in_addr() const;
00466 
00467 #if P_HAS_IPV6
00469         operator in6_addr() const;
00470 #endif
00471 
00473         operator DWORD() const;
00474 
00476         BYTE Byte1() const;
00477 
00479         BYTE Byte2() const;
00480 
00482         BYTE Byte3() const;
00483 
00485         BYTE Byte4() const;
00486 
00488         BYTE operator[](PINDEX idx) const;
00489 
00491         PINDEX GetSize() const;
00492 
00494         const char * GetPointer() const { return (const char *)&v; }
00495 
00497         unsigned GetVersion() const { return version; }
00498 
00500         BOOL IsValid() const;
00501         BOOL IsAny() const;
00502 
00504         BOOL IsLoopback() const;
00505 
00507         BOOL IsBroadcast() const;
00508 
00509         // Check if the remote address is a private address.
00510         // For IPV4 this is specified RFC 1918 as the following ranges:
00511         //    10.0.0.0    - 10.255.255.255.255
00512         //    172.16.0.0  - 172.31.255.255
00513         //    192.168.0.0 - 192.168.255.255
00514         // For IPV6 this is specified as any address having "1111 1110 1” for the first nine bits
00515         BOOL IsRFC1918() const ;
00516 
00517 #if P_HAS_IPV6
00519         BOOL IsV4Mapped() const;
00520 #endif
00521         
00522         static const Address & GetLoopback();
00523 #if P_HAS_IPV6
00524         static const Address & GetLoopback6();
00525         static const Address & GetAny6();
00526 #endif
00527         static const Address & GetBroadcast();
00528 
00529       protected:
00531         union {
00532           in_addr four;
00533 #if P_HAS_IPV6
00534           in6_addr six;
00535 #endif
00536         } v;
00537         unsigned version;
00538 
00540       friend ostream & operator<<(ostream & s, const Address & a);
00541 
00543       friend istream & operator>>(istream & s, Address & a);
00544     };
00545 
00546   // Overrides from class PChannel
00554     virtual PString GetName() const;
00555 
00556     // Set the default IP address familly.
00557     // Needed as lot of IPv6 stack are not able to receive IPv4 packets in IPv6 sockets
00558     // They are not RFC 2553, chapter 7.3, compliant.
00559     // As a concequence, when opening a socket to listen to port 1720 (for exemple) from any remot host
00560     // one must decide whether this an IPv4 or an IPv6 socket...
00561     static int GetDefaultIpAddressFamily();
00562     static void SetDefaultIpAddressFamily(int ipAdressFamily); // PF_INET, PF_INET6
00563     static void SetDefaultIpAddressFamilyV4(); // PF_INET
00564 #if P_HAS_IPV6
00565     static void SetDefaultIpAddressFamilyV6(); // PF_INET6
00566     static BOOL IsIpAddressFamilyV6Supported();
00567 #endif
00568     static PIPSocket::Address GetDefaultIpAny();
00569 
00570     // Open an IPv4 or IPv6 socket
00571     virtual BOOL OpenSocket(
00572       int ipAdressFamily=PF_INET
00573     ) = 0;
00574 
00575 
00576   // Overrides from class PSocket.
00588     virtual BOOL Connect(
00589       const PString & address   
00590     );
00591     virtual BOOL Connect(
00592       const Address & addr      
00593     );
00594     virtual BOOL Connect(
00595       WORD localPort,           
00596       const Address & addr      
00597     );
00598     virtual BOOL Connect(
00599       const Address & iface,    
00600       const Address & addr      
00601     );
00602     virtual BOOL Connect(
00603       const Address & iface,    
00604       WORD localPort,           
00605       const Address & addr      
00606     );
00607 
00623     virtual BOOL Listen(
00624       unsigned queueSize = 5,  
00625       WORD port = 0,           
00626       Reusability reuse = AddressIsExclusive 
00627     );
00628     virtual BOOL Listen(
00629       const Address & bind,     
00630       unsigned queueSize = 5,   
00631       WORD port = 0,            
00632       Reusability reuse = AddressIsExclusive 
00633     );
00634 
00635 
00636   // New functions for class
00644     static PString GetHostName();
00645     static PString GetHostName(
00646       const PString & hostname  
00647     );
00648     static PString GetHostName(
00649       const Address & addr    
00650     );
00651 
00658     static BOOL GetHostAddress(
00659       Address & addr    
00660     );
00661     static BOOL GetHostAddress(
00662       const PString & hostname,
00663       /* Name of host to get address for. This may be either a domain name or
00664          an IP number in "dot" format.
00665        */
00666       Address & addr    
00667     );
00668 
00676     static PStringArray GetHostAliases(
00677       const PString & hostname
00678       /* Name of host to get address for. This may be either a domain name or
00679          an IP number in "dot" format.
00680        */
00681     );
00682     static PStringArray GetHostAliases(
00683       const Address & addr    
00684       /* Name of host to get address for. This may be either a domain name or
00685          an IP number in "dot" format.
00686        */
00687     );
00688 
00696     static BOOL IsLocalHost(
00697       const PString & hostname
00698       /* Name of host to get address for. This may be either a domain name or
00699          an IP number in "dot" format.
00700        */
00701     );
00702 
00708     virtual PString GetLocalAddress();
00709     virtual BOOL GetLocalAddress(
00710       Address & addr    
00711     );
00712     virtual BOOL GetLocalAddress(
00713       Address & addr,    
00714       WORD & port        
00715     );
00716 
00723     virtual PString GetPeerAddress();
00724     virtual BOOL GetPeerAddress(
00725       Address & addr    
00726     );
00727     virtual BOOL GetPeerAddress(
00728       Address & addr,    
00729       WORD & port        
00730     );
00731 
00737     PString GetLocalHostName();
00738 
00744     PString GetPeerHostName();
00745 
00748     static void ClearNameCache();
00749 
00761     static BOOL GetGatewayAddress(
00762       Address & addr     
00763     );
00764 
00777     static PString GetGatewayInterface();
00778 
00779  #ifdef _WIN32
00780 
00791     static PIPSocket::Address GetGatewayInterfaceAddress();
00792 
00796     static PIPSocket::Address GetRouteAddress(PIPSocket::Address RemoteAddress);
00797 
00800     static unsigned AsNumeric(Address addr);
00801 
00804     static BOOL IsAddressReachable(PIPSocket::Address LocalIP,
00805                                    PIPSocket::Address LocalMask, 
00806                                    PIPSocket::Address RemoteIP);
00807 
00810     static PString GetInterface(PIPSocket::Address addr);
00811  #endif
00812 
00815     class RouteEntry : public PObject
00816     {
00817       PCLASSINFO(RouteEntry, PObject);
00818       public:
00820         RouteEntry(const Address & addr) : network(addr) { }
00821 
00823         Address GetNetwork() const { return network; }
00824 
00826         Address GetNetMask() const { return net_mask; }
00827 
00829         Address GetDestination() const { return destination; }
00830 
00832         const PString & GetInterface() const { return interfaceName; }
00833 
00835         long GetMetric() const { return metric; }
00836 
00837       protected:
00838         Address network;
00839         Address net_mask;
00840         Address destination;
00841         PString interfaceName;
00842         long    metric;
00843 
00844       friend class PIPSocket;
00845     };
00846 
00847     PLIST(RouteTable, RouteEntry);
00848 
00854     static BOOL GetRouteTable(
00855       RouteTable & table      
00856     );
00857 
00858 
00862     class InterfaceEntry : public PObject
00863     {
00864       PCLASSINFO(InterfaceEntry, PObject)
00865 
00866       public:
00868         InterfaceEntry();
00869         InterfaceEntry(
00870           const PString & _name,
00871           const Address & _addr,
00872           const Address & _mask,
00873           const PString & _macAddr
00874 #if P_HAS_IPV6
00875           , const PString & _ip6Addr = PString::Empty()
00876 #endif
00877         );
00878 
00880         virtual void PrintOn(
00881           ostream &strm   // Stream to print the object into.
00882         ) const;
00883 
00885         const PString & GetName() const { return name; }
00886 
00888         Address GetAddress() const { return ipAddr; }
00889 
00890         BOOL HasIP6Address() const
00891 #if ! P_HAS_IPV6
00892         { return FALSE;}
00893 #else
00894         { return !ip6Addr.IsEmpty();}
00895 
00897         Address GetIP6Address() const { return ip6Addr; }
00898 #endif
00899 
00901         Address GetNetMask() const { return netMask; }
00902 
00904         const PString & GetMACAddress() const { return macAddr; }
00905 
00906       protected:
00907         PString name;
00908         Address ipAddr;
00909         Address netMask;
00910         PString macAddr;
00911 #if P_HAS_IPV6
00912         PString ip6Addr;
00913 #endif
00914     };
00915 
00916     PLIST(InterfaceTable, InterfaceEntry);
00917 
00922     static BOOL GetInterfaceTable(
00923       InterfaceTable & table,      
00924       BOOL includeDown = FALSE     
00925     );
00926 
00931     static BOOL GetNetworkInterface(PIPSocket::Address & addr);
00932 
00933 #if P_HAS_RECVMSG
00934 
00940     BOOL SetCaptureReceiveToAddress()
00941     { if (!SetOption(IP_PKTINFO, 1, SOL_IP)) return FALSE; catchReceiveToAddr = TRUE; return TRUE; }
00942 
00946     PIPSocket::Address GetLastReceiveToAddress() const
00947     { return lastReceiveToAddr; }
00948 
00949   protected:
00950     void SetLastReceiveAddr(void * addr, int addrLen)
00951     { if (addrLen == sizeof(in_addr)) lastReceiveToAddr = *(in_addr *)addr; }
00952 
00953     PIPSocket::Address lastReceiveToAddr;
00954 
00955 #else
00956 
00962     BOOL SetCaptureReceiveToAddress()
00963     { return FALSE; }
00964 
00968     PIPSocket::Address GetLastReceiveToAddress() const
00969     { return PIPSocket::Address(); }
00970 
00971 #endif
00972 
00973 // Include platform dependent part of class
00974 #ifdef _WIN32
00975 #include "msos/ptlib/ipsock.h"
00976 #else
00977 #include "unix/ptlib/ipsock.h"
00978 #endif
00979 };
00980 
00981 class PIPSocketAddressAndPort
00982 {
00983   public:
00984     PIPSocketAddressAndPort()
00985       : port(0), sep(':')
00986     { }
00987 
00988     PIPSocketAddressAndPort(char _sep)
00989       : port(0), sep(_sep)
00990     { }
00991 
00992     PIPSocketAddressAndPort(const PString & str, WORD defaultPort = 0, char _sep = ':')
00993       : sep(_sep)
00994     { Parse(str, defaultPort, sep); }
00995 
00996     BOOL Parse(const PString & str, WORD defaultPort = 0, char sep = ':');
00997 
00998     PString AsString(char _sep = 0) const
00999     { return address.AsString() + (_sep ? _sep : sep) + PString(PString::Unsigned, port); }
01000 
01001     PIPSocket::Address address;
01002     WORD port;
01003     char sep;
01004 };
01005 
01006 typedef std::vector<PIPSocketAddressAndPort> PIPSocketAddressAndPortVector;
01007 
01008 #endif
01009 
01010 
01011 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1