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

Generated on Fri Sep 21 14:40:11 2007 for PWLib by  doxygen 1.5.3