00001 00014 // SocketAddress.h: interface for the SocketAddress class 00015 00016 #ifndef SOCKETADDRESS_H_ 00017 #define SOCKETADDRESS_H_ 00018 00019 #ifdef _MSC_VER 00020 #pragma once 00021 #endif // MSVC 00022 00023 #include <iosfwd> 00024 #include <string> 00025 00026 #include "SocketIncludes.h" 00027 00028 class IpAddress; 00029 00031 // SocketAddress 00032 00033 class SocketAddress 00034 { 00035 public: 00036 // Construct from port number 00037 SocketAddress( int port = 0 ); 00038 00039 // Construct from the given IpAddress and port number 00040 SocketAddress( const IpAddress& address, int port = 0 ); 00041 00042 00043 // Construct from Berkley Socket sockaddr_in structure 00044 SocketAddress( const sockaddr_in& address ); 00045 00046 // Copy constructor 00047 SocketAddress( const SocketAddress& socket_address ); 00048 00049 // Assignment from a Berkley Socket sockaddr_in structure 00050 SocketAddress& operator=( const sockaddr_in& address ); 00051 00052 // Assignment operator 00053 SocketAddress& operator=( const SocketAddress& address ); 00054 00055 // Comparison to another Socket Address 00056 bool operator==( const SocketAddress& address ) const; 00057 00058 // Comparison to another Socket Address 00059 bool operator<( const SocketAddress& address ) const; 00060 00061 // Standard c++ iostream inserter 00062 std::ostream& operator<<( std::ostream& stream) const; 00063 00064 // Convert to Berkley Socket sockaddr_in structure 00065 operator sockaddr_in() const; 00066 00067 // Port number accessors 00068 int getPort() const; 00069 void setPort( int port ); 00070 00071 // Ip address accessors 00072 IpAddress getIpAddress() const; 00073 void setIpAddress( const IpAddress& address ); 00074 00075 // Address family 00076 // On Win32 this should always be the AF_INET constant 00077 short getAddressFamily() const; 00078 00079 // Validity test for SocketAddress 00080 bool isDefined() const; 00081 00082 // Whether SocketAddress is an IpAddress 00083 bool isIpAddress() const; 00084 00085 // Whether the SocketAddress is path based 00086 bool isPathAddress() const; 00087 00088 00089 protected: 00090 // Convert IpAddress to long 00091 long getIpAddressAsLong() const; 00092 00093 // Set the IpAddress 00094 void setIpAddress(long code); 00095 00096 // Internal information. 00097 int length() const; 00098 00099 // Perfrom address initialization 00100 void initialize(); 00101 00102 private: 00103 // Berkley Sockets socket address structure. 00104 sockaddr_in socketAddress; 00105 }; 00106 00107 #endif // SocketAddress