#include <InetAddress.hpp>
Public Methods | |
InetAddress () | |
InetAddress (const InetAddress &src) | |
const InetAddress & | operator= (const InetAddress &src) |
InetAddress (const char *hostname) | |
const char * | getHostAddress () const |
const char * | getHostName () const |
void | setAddress (const char *hostname) |
const char * | toString () const |
const InetAddress | getByName (const char *host) const |
const InetAddress * | getAllByName (const char *host) const |
bool | equals (const InetAddress &right) const |
bool | operator== (const InetAddress &right) const |
const char * | getAddress () const |
unsigned long | getAddress2 () const |
bool | isMulticastAddress () const |
Static Public Methods | |
InetAddress | InetAddress::getLocalHost () |
Private Attributes | |
in_addr * | ip |
hostent * | h |
|
Definition at line 11 of file InetAddress.cpp. Referenced by getByName().
00012 { 00013 char host[81]; 00014 memset( host, 0, 81 ); 00015 gethostname( host, 80 ); 00016 setAddress( host ); 00017 } |
|
Definition at line 114 of file InetAddress.cpp. 00115 { 00116 setAddress( src.getAddress() ); 00117 } |
|
Definition at line 64 of file InetAddress.cpp. 00065 { 00066 setAddress(hostname); 00067 } |
|
Definition at line 62 of file InetAddress.hpp. 00063 { 00064 static InetAddress I; 00065 return I; 00066 } |
|
Definition at line 125 of file InetAddress.cpp. 00126 { 00127 return (right.getAddress2() == ip->s_addr); 00128 } |
|
Definition at line 135 of file InetAddress.cpp. Referenced by InetAddress(), and operator=().
00136 { 00137 /* 00138 char ret[5]; // 0..4 00139 memcpy( ret, (char*)ip, 4 ); // 0..3 00140 ret[4] = 0; 00141 00142 return ret; // Memory leak ??????? 00143 */ 00144 return (const char*)ip; 00145 } |
|
Definition at line 147 of file InetAddress.cpp. Referenced by TcpServerSocket::TcpServerSocket(), TcpSocket::TcpSocket(), equals(), and operator==().
00148 { 00149 return ip->s_addr; 00150 } |
|
Definition at line 199 of file InetAddress.cpp. 00200 { 00201 InetAddress *ret = NULL; 00202 int n_entries = 0; 00203 int i = 0; 00204 struct hostent *he = gethostbyname(host); 00205 struct in_addr *ip = NULL; 00206 00207 if ( he == NULL ) 00208 { 00209 switch( h_errno ) 00210 { 00211 case HOST_NOT_FOUND: 00212 fprintf( stderr, "Host not found: %s \n", host ); 00213 break; 00214 case NO_DATA: 00215 fprintf( stderr, "Host \"%s\" has no address \n", host ); 00216 break; 00217 case NO_RECOVERY: 00218 fprintf( stderr, "Irrecoverable error while getting address for host %s \n", host ); 00219 break; 00220 case TRY_AGAIN: 00221 fprintf( stderr, "Temporary error condition, try again", host ); 00222 break; 00223 default: 00224 fprintf( stderr, "Unknown error occured. %d : %s \n", h_errno, strerror( h_errno ) ); 00225 } 00226 return NULL; 00227 } 00228 00229 // BUG ???????? ........................\/ 00230 for(i=0;*he->h_addr_list[i] != '\0';i++); // count number of addresses 00231 00232 n_entries = i; 00233 ret = new InetAddress[i+1]; 00234 00235 for(i=0;i < n_entries;i++) 00236 { 00237 ip = (struct in_addr *)he->h_addr_list[i]; // get the address number i 00238 ret[i].setAddress(inet_ntoa(*ip)); // create a new InetAddress object 00239 // from a struct in_addr 00240 } 00241 00242 // DELETE ??!? Memory leak 00243 00244 return ret; 00245 } |
|
Definition at line 192 of file InetAddress.cpp. 00193 { 00194 return InetAddress( host ); 00195 } |
|
Definition at line 69 of file InetAddress.cpp. 00070 { 00071 return inet_ntoa(*ip); 00072 } |
|
Definition at line 74 of file InetAddress.cpp. Referenced by TcpSocket::getHost().
00075 { 00076 // char * ret = (char *) malloc(strlen(h->h_name)); // Memory leak! 00077 // strcpy(ret,h->h_name); 00078 00079 // Might memory leak too? 00080 return strdup( h->h_name ); //ret; 00081 } |
|
Definition at line 153 of file InetAddress.cpp. 00154 { 00155 return ((ntohl(ip->s_addr) & 0x80000000) == 0x80000000); 00156 } |
|
Definition at line 119 of file InetAddress.cpp. 00120 { 00121 setAddress( src.getAddress() ); 00122 return *this; 00123 } |
|
Definition at line 130 of file InetAddress.cpp. 00131 { 00132 return (right.getAddress2() == ip->s_addr); 00133 } |
|
Definition at line 83 of file InetAddress.cpp. Referenced by InetAddress(), getAllByName(), and operator=().
00084 { 00085 h = gethostbyname( hostname ); 00086 if( h == NULL ) 00087 { 00088 switch(h_errno) 00089 { 00090 case HOST_NOT_FOUND: 00091 fprintf( stderr, "Host not found: %s\n", hostname ); 00092 break; 00093 case NO_ADDRESS: 00094 fprintf( stderr, "Host %s has no address \n", hostname ); 00095 break; 00096 case NO_RECOVERY: 00097 fprintf( stderr, "Irrecoverable error while getting address for host %s \n", hostname ); 00098 break; 00099 case TRY_AGAIN: 00100 fprintf( stderr, "Temporary errorcondition, try again %s \n", hostname ); 00101 break; 00102 default: 00103 fprintf( stderr, "Unknown error occured. %d : %s \n", h_errno, strerror( h_errno ) ); 00104 } 00105 00106 } // End if 00107 00108 ip = (in_addr*)( h->h_addr ); 00109 } |
|
Definition at line 167 of file InetAddress.cpp. 00168 { 00169 return inet_ntoa( *ip ); 00170 } |
|
Definition at line 71 of file InetAddress.hpp. |
|
Definition at line 70 of file InetAddress.hpp. |