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.83  2006/10/03 06:29:38  csoutheren
00031  * Add PIPSocketAndPort::AsString
00032  *
00033  * Revision 1.82  2006/07/05 03:58:09  csoutheren
00034  * Additional implementation of PIPSocketAddressAndPort
00035  *
00036  * Revision 1.81  2006/04/09 07:05:40  rjongbloed
00037  * Moved output stream operator for PString from sockets code to string code and fixed
00038  *   its implemetation to continue to use PrintOn. Why it was added is unknown, probably
00039  *   a compiler issue, but it should not be in a random source file!
00040  *
00041  * Revision 1.80  2006/02/26 11:51:20  csoutheren
00042  * Extended DNS test program to include URL based SRV lookups
00043  * Re-arranged SRV lookup code to allow access to internal routine
00044  * Reformatted code
00045  *
00046  * Revision 1.79  2005/11/30 12:47:37  csoutheren
00047  * Removed tabs, reformatted some code, and changed tags for Doxygen
00048  *
00049  * Revision 1.78  2005/11/25 03:43:47  csoutheren
00050  * Fixed function argument comments to be compatible with Doxygen
00051  *
00052  * Revision 1.77  2005/07/13 11:48:41  csoutheren
00053  * Backported QOS changes from isvo branch
00054  *
00055  * Revision 1.76.2.1  2005/04/25 13:30:41  shorne
00056  * Extra support for DHCP Environment (Win32)
00057  *
00058  * Revision 1.76  2005/03/22 07:29:29  csoutheren
00059  * Fixed problem where PStrings sometimes get case into
00060  * PIPSocket::Address when outputting to an ostream
00061  *
00062  * Revision 1.75  2005/02/13 23:01:35  csoutheren
00063  * Fixed problem with not detecting mapped IPV6 addresses within the RFC1918
00064  * address range as RFC1918
00065  *
00066  * Revision 1.74  2005/02/07 12:12:33  csoutheren
00067  * Expanded interface list routines to include IPV6 addresses
00068  * Added IPV6 to GetLocalAddress
00069  *
00070  * Revision 1.73  2005/02/07 00:47:17  csoutheren
00071  * Changed IPV6 code to use standard IPV6 macros
00072  *
00073  * Revision 1.72  2005/02/04 05:50:27  csoutheren
00074  * Extended IsRFC1918 to handle IPV6
00075  *
00076  * Revision 1.71  2005/01/16 21:27:01  csoutheren
00077  * Changed PIPSocket::IsAny to be const
00078  *
00079  * Revision 1.70  2004/12/20 07:59:33  csoutheren
00080  * Fixed operator *= for IPV6
00081  *
00082  * Revision 1.69  2004/12/14 14:24:19  csoutheren
00083  * Added PIPSocket::Address::operator*= to compare IPV4 addresses
00084  * to IPV4-compatible IPV6 addresses. More documentation needed
00085  * once this is tested as working
00086  *
00087  * Revision 1.68  2004/12/14 06:20:29  csoutheren
00088  * Added function to get address of network interface
00089  *
00090  * Revision 1.67  2004/08/24 07:08:13  csoutheren
00091  * Added use of recvmsg to determine which interface UDP packets arrive on
00092  *
00093  * Revision 1.66  2004/07/11 07:56:35  csoutheren
00094  * Applied jumbo VxWorks patch, thanks to Eize Slange
00095  *
00096  * Revision 1.65  2004/04/18 04:33:36  rjongbloed
00097  * Changed all operators that return BOOL to return standard type bool. This is primarily
00098  *   for improved compatibility with std STL usage removing many warnings.
00099  *
00100  * Revision 1.64  2004/04/07 05:29:50  csoutheren
00101  * Added function to detect RFC 1918 addresses
00102  *
00103  * Revision 1.63  2004/02/23 17:27:19  ykiryanov
00104  * Added == and != operators for in_addr_t on BeOS as suggested by Craig Southeren to please compiler
00105  *
00106  * Revision 1.62  2003/09/17 05:41:58  csoutheren
00107  * Removed recursive includes
00108  *
00109  * Revision 1.61  2003/09/17 01:18:02  csoutheren
00110  * Removed recursive include file system and removed all references
00111  * to deprecated coooperative threading support
00112  *
00113  * Revision 1.60  2003/05/21 09:34:43  rjongbloed
00114  * Name lookup support for IPv6, thanks again Sébastien Josset
00115  *
00116  * Revision 1.59  2003/04/28 02:55:08  robertj
00117  * Added function to see at run time if IPv6 available, thanks Sebastien Josset
00118  *
00119  * Revision 1.58  2003/04/03 08:43:23  robertj
00120  * Added IPv4 mapping into IPv6, thanks Sebastien Josset
00121  *
00122  * Revision 1.57  2003/03/26 05:36:37  robertj
00123  * More IPv6 support (INADDR_ANY handling), thanks Sébastien Josset
00124  *
00125  * Revision 1.56  2003/02/03 11:23:32  robertj
00126  * Added function to get pointer to IP address data.
00127  *
00128  * Revision 1.55  2003/02/03 08:51:44  robertj
00129  * Fixed compatibility with old code so taking address of PIPSocket::Address
00130  *   gets address of 4 or 16 byte IP address.
00131  *
00132  * Revision 1.54  2002/12/02 03:57:18  robertj
00133  * More RTEMS support patches, thank you Vladimir Nesic.
00134  *
00135  * Revision 1.53  2002/11/02 00:32:21  robertj
00136  * Further fixes to VxWorks (Tornado) port, thanks Andreas Sikkema.
00137  *
00138  * Revision 1.52  2002/10/29 07:59:45  robertj
00139  * Changed in_addr6 to more universally used in6_addr.
00140  *
00141  * Revision 1.51  2002/10/08 14:31:43  robertj
00142  * Changed for IPv6 support, thanks Sébastien Josset.
00143  *
00144  * Revision 1.50  2002/10/08 12:41:51  robertj
00145  * Changed for IPv6 support, thanks Sébastien Josset.
00146  *
00147  * Revision 1.49  2002/09/16 01:08:59  robertj
00148  * Added #define so can select if #pragma interface/implementation is used on
00149  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00150  *
00151  * Revision 1.48  2001/12/13 09:17:01  robertj
00152  * Added function to convert PString to IP address with error checking that can
00153  *   distinguish between 0.0.0.0 or 255.255.255.255 and illegal address.
00154  *
00155  * Revision 1.47  2001/09/14 08:00:38  robertj
00156  * Added new versions of Conenct() to allow binding to a specific local interface.
00157  *
00158  * Revision 1.46  2001/05/22 12:49:32  robertj
00159  * Did some seriously wierd rewrite of platform headers to eliminate the
00160  *   stupid GNU compiler warning about braces not matching.
00161  *
00162  * Revision 1.45  2001/03/05 04:18:27  robertj
00163  * Added net mask to interface info returned by GetInterfaceTable()
00164  *
00165  * Revision 1.44  2001/01/29 06:41:18  robertj
00166  * Added printing of entry of interface table.
00167  *
00168  * Revision 1.43  2000/06/26 11:17:19  robertj
00169  * Nucleus++ port (incomplete).
00170  *
00171  * Revision 1.42  1999/09/10 04:35:42  robertj
00172  * Added Windows version of PIPSocket::GetInterfaceTable() function.
00173  *
00174  * Revision 1.41  1999/09/10 02:31:42  craigs
00175  * Added interface table routines
00176  *
00177  * Revision 1.40  1999/08/30 02:21:03  robertj
00178  * Added ability to listen to specific interfaces for IP sockets.
00179  *
00180  * Revision 1.39  1999/08/08 09:04:01  robertj
00181  * Added operator>> for PIPSocket::Address class.
00182  *
00183  * Revision 1.38  1999/03/09 02:59:50  robertj
00184  * Changed comments to doc++ compatible documentation.
00185  *
00186  * Revision 1.37  1999/02/23 07:19:22  robertj
00187  * Added [] operator PIPSocket::Address to get the bytes out of an IP address.
00188  *
00189  * Revision 1.36  1999/02/16 08:12:00  robertj
00190  * MSVC 6.0 compatibility changes.
00191  *
00192  * Revision 1.35  1998/12/21 07:22:50  robertj
00193  * Virtualised functions for SOCKS support.
00194  *
00195  * Revision 1.34  1998/12/18 04:34:14  robertj
00196  * PPC Linux GNU C compatibility.
00197  *
00198  * Revision 1.33  1998/11/30 08:57:32  robertj
00199  * New directory structure
00200  *
00201  * Revision 1.32  1998/11/22 11:30:08  robertj
00202  * Check route table function to get a list
00203  *
00204  * Revision 1.31  1998/11/19 05:18:22  robertj
00205  * Added route table manipulation functions to PIPSocket class.
00206  *
00207  * Revision 1.30  1998/09/23 06:20:45  robertj
00208  * Added open source copyright license.
00209  *
00210  * Revision 1.29  1997/12/11 10:28:57  robertj
00211  * Added operators for IP address to DWORD conversions.
00212  *
00213  * Revision 1.28  1996/12/17 11:08:05  robertj
00214  * Added DNS name cache clear command.
00215  *
00216  * Revision 1.27  1996/11/30 12:10:00  robertj
00217  * Added Connect() variant so can set the local port number on link.
00218  *
00219  * Revision 1.26  1996/11/16 10:48:49  robertj
00220  * Fixed missing const in PIPSocket::Address stream output operator..
00221  *
00222  * Revision 1.25  1996/11/04 03:40:54  robertj
00223  * Moved address printer from inline to source.
00224  *
00225  * Revision 1.24  1996/09/14 13:09:21  robertj
00226  * Major upgrade:
00227  *   rearranged sockets to help support IPX.
00228  *   added indirect channel class and moved all protocols to descend from it,
00229  *   separating the protocol from the low level byte transport.
00230  *
00231  * Revision 1.23  1996/08/25 09:33:55  robertj
00232  * Added function to detect "local" host name.
00233  *
00234  * Revision 1.22  1996/03/26 00:51:13  robertj
00235  * Added GetLocalAddress() variant that returns port number as well.
00236  *
00237  * Revision 1.21  1996/03/16 04:41:30  robertj
00238  * Changed all the get host name and get host address functions to be more consistent.
00239  *
00240  * Revision 1.20  1996/03/03 07:37:56  robertj
00241  * Added Reusability clause to the Listen() function on sockets.
00242  *
00243  * Revision 1.19  1996/02/25 03:00:31  robertj
00244  * Added operator<< to PIPSocket::Address.
00245  * Moved some socket functions to platform dependent code.
00246  *
00247  * Revision 1.18  1996/02/08 12:11:19  robertj
00248  * Added GetPeerAddress that returns a port.
00249  *
00250  * Revision 1.17  1996/01/28 14:07:31  robertj
00251  * Changed service parameter to PString for ease of use in GetPortByService function
00252  * Fixed up comments.
00253  *
00254  * Revision 1.16  1995/12/23 03:44:59  robertj
00255  * Fixed unix portability issues.
00256  *
00257  * Revision 1.15  1995/12/10 11:32:11  robertj
00258  * Numerous fixes for sockets.
00259  *
00260  * Revision 1.14  1995/10/14 14:57:26  robertj
00261  * Added internet address to string conversion functionality.
00262  *
00263  * Revision 1.13  1995/07/02 01:18:19  robertj
00264  * Added static functions to get the current host name/address.
00265  *
00266  * Revision 1.12  1995/06/17 00:41:40  robertj
00267  * More logical design of port numbers and service names.
00268  *
00269  * Revision 1.11  1995/03/18 06:26:44  robertj
00270  * Changed IP address variable for GNU compatibility.
00271  *
00272  * Revision 1.10  1995/03/14  12:41:38  robertj
00273  * Updated documentation to use HTML codes.
00274  *
00275  * Revision 1.9  1995/03/12  04:38:41  robertj
00276  * Added more functionality.
00277  *
00278  * Revision 1.8  1995/01/02  12:28:24  robertj
00279  * Documentation.
00280  * Added more socket functions.
00281  *
00282  * Revision 1.7  1995/01/01  01:07:33  robertj
00283  * More implementation.
00284  *
00285  * Revision 1.6  1994/12/15  12:47:14  robertj
00286  * Documentation.
00287  *
00288  * Revision 1.5  1994/08/23  11:32:52  robertj
00289  * Oops
00290  *
00291  * Revision 1.4  1994/08/22  00:46:48  robertj
00292  * Added pragma fro GNU C++ compiler.
00293  *
00294  * Revision 1.3  1994/08/21  23:43:02  robertj
00295  * Spelt Berkeley correctly.
00296  *
00297  * Revision 1.2  1994/07/25  03:36:03  robertj
00298  * Added sockets to common, normalising to same comment standard.
00299  *
00300  */
00301 
00302 #ifndef _PIPSOCKET
00303 #define _PIPSOCKET
00304 
00305 #ifdef P_USE_PRAGMA
00306 #pragma interface
00307 #endif
00308 
00309 #include <ptlib/socket.h>
00310 
00311 #ifdef P_HAS_QOS
00312 #ifdef _WIN32
00313 #ifdef P_KNOCKOUT_WINSOCK2 
00314    #include "IPExport.h"
00315 #endif // KNOCKOUT_WINSOCK2
00316 #endif // _WIN32
00317 #endif // P_HAS_QOS
00318 
00326 class PIPSocket : public PSocket
00327 {
00328   PCLASSINFO(PIPSocket, PSocket);
00329   protected:
00330     /* Create a new Internet Protocol socket based on the port number
00331        specified.
00332      */
00333     PIPSocket();
00334 
00335   public:
00339     class Address : public PObject {
00340       public:
00341 
00344 
00345         Address();
00346 
00350         Address(const PString & dotNotation);
00351 
00353         Address(PINDEX len, const BYTE * bytes);
00354 
00356         Address(BYTE b1, BYTE b2, BYTE b3, BYTE b4);
00357 
00359         Address(DWORD dw);
00360 
00362         Address(const in_addr & addr);
00363 
00364 #if P_HAS_IPV6
00366         Address(const in6_addr & addr);
00367 
00370         Address(const int ai_family, const int ai_addrlen,struct sockaddr *ai_addr);
00371 #endif
00372 
00373 #ifdef __NUCLEUS_NET__
00374         Address(const struct id_struct & addr);
00375         Address & operator=(const struct id_struct & addr);
00376 #endif
00377 
00379         Address & operator=(const in_addr & addr);
00380 
00381 #if P_HAS_IPV6
00383         Address & operator=(const in6_addr & addr);
00384 #endif
00385 
00387         Address & operator=(const PString & dotNotation);
00388 
00390         Address & operator=(DWORD dw);
00392 
00394         Comparison Compare(const PObject & obj) const;
00395         bool operator==(const Address & addr) const { return Compare(addr) == EqualTo; }
00396         bool operator!=(const Address & addr) const { return Compare(addr) != EqualTo; }
00397 #if P_HAS_IPV6
00398         bool operator==(in6_addr & addr) const;
00399         bool operator!=(in6_addr & addr) const { return !operator==(addr); }
00400 #endif
00401         bool operator==(in_addr & addr) const;
00402         bool operator!=(in_addr & addr) const { return !operator==(addr); }
00403         bool operator==(DWORD dw) const;
00404         bool operator!=(DWORD dw) const   { return !operator==(dw); }
00405 #ifdef P_VXWORKS 
00406         bool operator==(long unsigned int u) const { return  operator==((DWORD)u); }
00407         bool operator!=(long unsigned int u) const { return !operator==((DWORD)u); }
00408 #endif
00409 #ifdef _WIN32
00410         bool operator==(unsigned u) const { return  operator==((DWORD)u); }
00411         bool operator!=(unsigned u) const { return !operator==((DWORD)u); }
00412 #endif
00413 #ifdef P_RTEMS
00414         bool operator==(u_long u) const { return  operator==((DWORD)u); }
00415         bool operator!=(u_long u) const { return !operator==((DWORD)u); }
00416 #endif
00417 #ifdef __BEOS__
00418         bool operator==(in_addr_t a) const { return  operator==((DWORD)a); }
00419         bool operator!=(in_addr_t a) const { return !operator==((DWORD)a); }
00420 #endif
00421         bool operator==(int i) const      { return  operator==((DWORD)i); }
00422         bool operator!=(int i) const      { return !operator==((DWORD)i); }
00423 
00426 #if P_HAS_IPV6
00427         bool operator*=(const Address & addr) const;
00428 #else
00429         bool operator*=(const Address & addr) const { return operator==(addr); }
00430 #endif
00431 
00433         PString AsString() const;
00434 
00436         BOOL FromString(
00437           const PString & str
00438         );
00439 
00441         operator PString() const;
00442 
00444         operator in_addr() const;
00445 
00446 #if P_HAS_IPV6
00448         operator in6_addr() const;
00449 #endif
00450 
00452         operator DWORD() const;
00453 
00455         BYTE Byte1() const;
00456 
00458         BYTE Byte2() const;
00459 
00461         BYTE Byte3() const;
00462 
00464         BYTE Byte4() const;
00465 
00467         BYTE operator[](PINDEX idx) const;
00468 
00470         PINDEX GetSize() const;
00471 
00473         const char * GetPointer() const { return (const char *)&v; }
00474 
00476         unsigned GetVersion() const { return version; }
00477 
00479         BOOL IsValid() const;
00480         BOOL IsAny() const;
00481 
00483         BOOL IsLoopback() const;
00484 
00486         BOOL IsBroadcast() const;
00487 
00488         // Check if the remote address is a private address.
00489         // For IPV4 this is specified RFC 1918 as the following ranges:
00490         //    10.0.0.0    - 10.255.255.255.255
00491         //    172.16.0.0  - 172.31.255.255
00492         //    192.168.0.0 - 192.168.255.255
00493         // For IPV6 this is specified as any address having "1111 1110 1” for the first nine bits
00494         BOOL IsRFC1918() const ;
00495 
00496 #if P_HAS_IPV6
00498         BOOL IsV4Mapped() const;
00499 #endif
00500         
00501         static const Address & GetLoopback();
00502 #if P_HAS_IPV6
00503         static const Address & GetLoopback6();
00504         static const Address & GetAny6();
00505 #endif
00506         static const Address & GetBroadcast();
00507 
00508       protected:
00510         union {
00511           in_addr four;
00512 #if P_HAS_IPV6
00513           in6_addr six;
00514 #endif
00515         } v;
00516         unsigned version;
00517 
00519       friend ostream & operator<<(ostream & s, const Address & a);
00520 
00522       friend istream & operator>>(istream & s, Address & a);
00523     };
00524 
00525   // Overrides from class PChannel
00533     virtual PString GetName() const;
00534 
00535     // Set the default IP address familly.
00536     // Needed as lot of IPv6 stack are not able to receive IPv4 packets in IPv6 sockets
00537     // They are not RFC 2553, chapter 7.3, compliant.
00538     // As a concequence, when opening a socket to listen to port 1720 (for exemple) from any remot host
00539     // one must decide whether this an IPv4 or an IPv6 socket...
00540     static int GetDefaultIpAddressFamily();
00541     static void SetDefaultIpAddressFamily(int ipAdressFamily); // PF_INET, PF_INET6
00542     static void SetDefaultIpAddressFamilyV4(); // PF_INET
00543 #if P_HAS_IPV6
00544     static void SetDefaultIpAddressFamilyV6(); // PF_INET6
00545     static BOOL IsIpAddressFamilyV6Supported();
00546 #endif
00547     static PIPSocket::Address GetDefaultIpAny();
00548 
00549     // Open an IPv4 or IPv6 socket
00550     virtual BOOL OpenSocket(
00551       int ipAdressFamily=PF_INET
00552     ) = 0;
00553 
00554 
00555   // Overrides from class PSocket.
00567     virtual BOOL Connect(
00568       const PString & address   
00569     );
00570     virtual BOOL Connect(
00571       const Address & addr      
00572     );
00573     virtual BOOL Connect(
00574       WORD localPort,           
00575       const Address & addr      
00576     );
00577     virtual BOOL Connect(
00578       const Address & iface,    
00579       const Address & addr      
00580     );
00581     virtual BOOL Connect(
00582       const Address & iface,    
00583       WORD localPort,           
00584       const Address & addr      
00585     );
00586 
00602     virtual BOOL Listen(
00603       unsigned queueSize = 5,  
00604       WORD port = 0,           
00605       Reusability reuse = AddressIsExclusive 
00606     );
00607     virtual BOOL Listen(
00608       const Address & bind,     
00609       unsigned queueSize = 5,   
00610       WORD port = 0,            
00611       Reusability reuse = AddressIsExclusive 
00612     );
00613 
00614 
00615   // New functions for class
00623     static PString GetHostName();
00624     static PString GetHostName(
00625       const PString & hostname  
00626     );
00627     static PString GetHostName(
00628       const Address & addr    
00629     );
00630 
00637     static BOOL GetHostAddress(
00638       Address & addr    
00639     );
00640     static BOOL GetHostAddress(
00641       const PString & hostname,
00642       /* Name of host to get address for. This may be either a domain name or
00643          an IP number in "dot" format.
00644        */
00645       Address & addr    
00646     );
00647 
00655     static PStringArray GetHostAliases(
00656       const PString & hostname
00657       /* Name of host to get address for. This may be either a domain name or
00658          an IP number in "dot" format.
00659        */
00660     );
00661     static PStringArray GetHostAliases(
00662       const Address & addr    
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     );
00667 
00675     static BOOL IsLocalHost(
00676       const PString & hostname
00677       /* Name of host to get address for. This may be either a domain name or
00678          an IP number in "dot" format.
00679        */
00680     );
00681 
00687     virtual BOOL GetLocalAddress(
00688       Address & addr    
00689     );
00690     virtual BOOL GetLocalAddress(
00691       Address & addr,    
00692       WORD & port        
00693     );
00694 
00701     virtual BOOL GetPeerAddress(
00702       Address & addr    
00703     );
00704     virtual BOOL GetPeerAddress(
00705       Address & addr,    
00706       WORD & port        
00707     );
00708 
00714     PString GetLocalHostName();
00715 
00721     PString GetPeerHostName();
00722 
00725     static void ClearNameCache();
00726 
00738     static BOOL GetGatewayAddress(
00739       Address & addr     
00740     );
00741 
00754     static PString GetGatewayInterface();
00755 
00756  #ifdef _WIN32
00757 
00768     static PIPSocket::Address GetGatewayInterfaceAddress();
00769 
00773     static PIPSocket::Address GetRouteAddress(PIPSocket::Address RemoteAddress);
00774 
00777     static unsigned AsNumeric(Address addr);
00778 
00781     static BOOL IsAddressReachable(PIPSocket::Address LocalIP,
00782                                    PIPSocket::Address LocalMask, 
00783                                    PIPSocket::Address RemoteIP);
00784 
00787     static PString GetInterface(PIPSocket::Address addr);
00788  #endif
00789 
00792     class RouteEntry : public PObject
00793     {
00794       PCLASSINFO(RouteEntry, PObject);
00795       public:
00797         RouteEntry(const Address & addr) : network(addr) { }
00798 
00800         Address GetNetwork() const { return network; }
00801 
00803         Address GetNetMask() const { return net_mask; }
00804 
00806         Address GetDestination() const { return destination; }
00807 
00809         const PString & GetInterface() const { return interfaceName; }
00810 
00812         long GetMetric() const { return metric; }
00813 
00814       protected:
00815         Address network;
00816         Address net_mask;
00817         Address destination;
00818         PString interfaceName;
00819         long    metric;
00820 
00821       friend class PIPSocket;
00822     };
00823 
00824     PLIST(RouteTable, RouteEntry);
00825 
00831     static BOOL GetRouteTable(
00832       RouteTable & table      
00833     );
00834 
00835 
00839     class InterfaceEntry : public PObject
00840     {
00841       PCLASSINFO(InterfaceEntry, PObject)
00842 
00843       public:
00845         InterfaceEntry(
00846           const PString & _name,
00847           const Address & _addr,
00848           const Address & _mask,
00849           const PString & _macAddr
00850 #if P_HAS_IPV6
00851           , const PString & _ip6Addr = PString::Empty()
00852 #endif
00853         );
00854 
00856         virtual void PrintOn(
00857           ostream &strm   // Stream to print the object into.
00858         ) const;
00859 
00861         const PString & GetName() const { return name; }
00862 
00864         Address GetAddress() const { return ipAddr; }
00865 
00866         BOOL HasIP6Address() const
00867 #if ! P_HAS_IPV6
00868         { return FALSE;}
00869 #else
00870         { return !ip6Addr.IsEmpty();}
00871 
00873         Address GetIP6Address() const { return ip6Addr; }
00874 #endif
00875 
00877         Address GetNetMask() const { return netMask; }
00878 
00880         const PString & GetMACAddress() const { return macAddr; }
00881 
00882       protected:
00883         PString name;
00884         Address ipAddr;
00885         Address netMask;
00886         PString macAddr;
00887 #if P_HAS_IPV6
00888         PString ip6Addr;
00889 #endif
00890     };
00891 
00892     PLIST(InterfaceTable, InterfaceEntry);
00893 
00898     static BOOL GetInterfaceTable(
00899       InterfaceTable & table      
00900     );
00901 
00906     static BOOL GetNetworkInterface(PIPSocket::Address & addr);
00907 
00908 #if P_HAS_RECVMSG
00909 
00915     BOOL SetCaptureReceiveToAddress()
00916     { if (!SetOption(IP_PKTINFO, 1, SOL_IP)) return FALSE; catchReceiveToAddr = TRUE; return TRUE; }
00917 
00921     PIPSocket::Address GetLastReceiveToAddress() const
00922     { return lastReceiveToAddr; }
00923 
00924   protected:
00925     void SetLastReceiveAddr(void * addr, int addrLen)
00926     { if (addrLen == sizeof(in_addr)) lastReceiveToAddr = *(in_addr *)addr; }
00927 
00928     PIPSocket::Address lastReceiveToAddr;
00929 
00930 #else
00931 
00937     BOOL SetCaptureReceiveToAddress()
00938     { return FALSE; }
00939 
00943     PIPSocket::Address GetLastReceiveToAddress() const
00944     { return PIPSocket::Address(); }
00945 
00946 #endif
00947 
00948 // Include platform dependent part of class
00949 #ifdef _WIN32
00950 #include "msos/ptlib/ipsock.h"
00951 #else
00952 #include "unix/ptlib/ipsock.h"
00953 #endif
00954 };
00955 
00956 class PIPSocketAddressAndPort
00957 {
00958   public:
00959     PIPSocketAddressAndPort()
00960       : port(0)
00961     { }
00962 
00963     PIPSocketAddressAndPort(const PString & str, WORD defaultPort = 0)
00964                 { Parse(':', str, defaultPort); }
00965 
00966     PIPSocketAddressAndPort(char sep, const PString & str, WORD defaultPort = 0)
00967                 { Parse(sep, str, defaultPort); }
00968 
00969     void Parse(char sep, const PString & str, WORD defaultPort = 0);
00970 
00971     PString AsString() const
00972     { return address.AsString() + ':' + PString(PString::Unsigned, port); }
00973 
00974     PIPSocket::Address address;
00975     WORD port;
00976 };
00977 
00978 typedef std::vector<PIPSocketAddressAndPort> PIPSocketAddressAndPortVector;
00979 
00980 #endif
00981 
00982 
00983 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Feb 29 13:37:09 2008 for PWLib by  doxygen 1.5.5