Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

Net::IPSocketAddress Class Reference

#include <IPSocketAddress.h>

Inheritance diagram for Net::IPSocketAddress:

Inheritance graph
[legend]
Collaboration diagram for Net::IPSocketAddress:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual String * className (void) const
 Answer receiver class name.
virtual ByteArray * hostAddress (void) const
virtual void hostAddress (ByteArray *addr)
virtual String * hostName (void) const
virtual void hostName (String *name)
virtual unsigned short int port (void)
virtual void port (unsigned short int p)
virtual void printOn (Stream *stream) const
 Print object identification into the stream.

Static Public Member Functions

static IPSocketAddress * hostAddress (ByteArray *addr, unsigned short port)
static IPSocketAddress * hostName (String *name, unsigned short port)
static IPSocketAddress * thisHostAnyPort (void)
static ByteArray * hostAddressByName (String *name)
static String * hostNameByAddress (ByteArray *address)
static String * bytesToName (ByteArray *address)
 Converts numeric IP address representation to string.
static ByteArray * stringToBytes (String *name)
 Converts string IP adrress representation into numeric one.
static ByteArray * thisHost (void)
static unsigned short int anyPort (void)

Protected Attributes

ByteArray * _address
unsigned short int _port

Member Function Documentation

unsigned short IPSocketAddress::anyPort (  void   )  [static]
 

Definition at line 145 of file IPSocketAddress.cc.

Referenced by thisHostAnyPort().

00146 {
00147     return 0;
00148 }

String * IPSocketAddress::bytesToName (  ByteArray *  address  )  [static]
 

Converts numeric IP address representation to string.

It does not resolv the address. Just writes out IP address in common string representation (like 127.0.0.1).

Definition at line 91 of file IPSocketAddress.cc.

References Core::Collection::printSeparatedBy().

Referenced by hostNameByAddress().

00092 {
00093     return address->printSeparatedBy(".");
00094 }

String * IPSocketAddress::className (  void   )  const [virtual]
 

Answer receiver class name.

Because there isn't any standard way to obtain class name this method comes to place.

Every class should rewrite this method but many didn't (yet).

Reimplemented from Core::Object.

Definition at line 41 of file IPSocketAddress.cc.

00042 {
00043     return new String("IPSocketAddress");
00044 }

void IPSocketAddress::hostAddress (  ByteArray *  addr  )  [virtual]
 

Definition at line 113 of file IPSocketAddress.cc.

References _address.

00114 {
00115     _address = addr;
00116 }

ByteArray * IPSocketAddress::hostAddress (  void   )  const [virtual]
 

Definition at line 108 of file IPSocketAddress.cc.

References _address.

Referenced by hostName(), Net::SocketAccessor::myAddress(), Net::SocketAccessor::newTCPclientToHost(), Net::SocketAccessor::newTCPserverAt(), Net::SocketAccessor::newUDPclientToHost(), Net::SocketAccessor::newUDPserverAt(), Net::SocketAccessor::peerAddress(), and thisHostAnyPort().

00109 {
00110     return _address;
00111 }

static IPSocketAddress* Net::IPSocketAddress::hostAddress (  ByteArray *  addr,
unsigned short  port
)  [static]
 

ByteArray * IPSocketAddress::hostAddressByName (  String *  name  )  [static]
 

Definition at line 69 of file IPSocketAddress.cc.

References Core::String::asCString(), nil, and stringToBytes().

Referenced by hostName().

00070 {
00071     struct hostent *ph = NULL;
00072 
00073     ph = gethostbyname(name->asCString());
00074     if (ph != NULL) return new ByteArray(ph->h_addr, 4);
00075 
00076     ByteArray *address = stringToBytes(name);
00077     if (address != nil) return address;
00078     (new UnknownHostError(name, __PRETTY_FUNCTION__))->raise();
00079 }

void IPSocketAddress::hostName (  String *  name  )  [virtual]
 

Definition at line 123 of file IPSocketAddress.cc.

References hostAddress(), and hostAddressByName().

00124 {
00125     hostAddress(hostAddressByName(name));
00126 }

String * IPSocketAddress::hostName (  void   )  const [virtual]
 

Definition at line 118 of file IPSocketAddress.cc.

References hostAddress(), and hostNameByAddress().

Referenced by Net::SocketAccessor::newTCPclientToHost(), Net::SocketAccessor::newUDPclientToHost(), printOn(), and Net::URL::socketAddress().

00119 {
00120     return hostNameByAddress(hostAddress());
00121 }

static IPSocketAddress* Net::IPSocketAddress::hostName (  String *  name,
unsigned short  port
)  [static]
 

String * IPSocketAddress::hostNameByAddress (  ByteArray *  address  )  [static]
 

Definition at line 81 of file IPSocketAddress.cc.

References bytesToName(), Core::ByteArray::rawBytesReadOnly(), and Core::ByteArray::size().

Referenced by hostName().

00082 {
00083     struct hostent *ph = NULL;
00084 
00085     ph = gethostbyaddr(address->rawBytesReadOnly(), address->size(), AF_INET);
00086     if (ph != NULL) return new String(ph->h_name);
00087     return bytesToName(address);
00088 }

void IPSocketAddress::port (  unsigned short int  p  )  [virtual]
 

Definition at line 133 of file IPSocketAddress.cc.

References _port.

00134 {
00135     _port = p;
00136 }

unsigned short int IPSocketAddress::port (  void   )  [virtual]
 

Definition at line 128 of file IPSocketAddress.cc.

References _port.

00129 {
00130     return _port;
00131 }

void IPSocketAddress::printOn (  Stream *  stream  )  const [virtual]
 

Print object identification into the stream.

Object identification is formed from its className() by default. But complicated classes (eg. collections) may print some other information.

  • stream - stream to print to.

Reimplemented from Core::Object.

Definition at line 151 of file IPSocketAddress.cc.

References _port, hostName(), Core::Stream::nextPut(), Core::Stream::nextPutAll(), and Core::Stream::print().

00152 {
00153     Object::printOn(stream);
00154     stream->nextPut('(');
00155     stream->nextPutAll(hostName());
00156     stream->nextPutAll(", ");
00157     stream->print((long) _port);
00158     stream->nextPut(')');
00159 }

ByteArray * IPSocketAddress::stringToBytes (  String *  name  )  [static]
 

Converts string IP adrress representation into numeric one.

It does not resolv the name.

Definition at line 96 of file IPSocketAddress.cc.

References Core::String::asArrayOfSubstringsSeparatedBy(), Core::Array::at(), nil, Core::ByteArray::put(), and Core::Array::size().

Referenced by hostAddressByName().

00097 {
00098     Array *parts = name->asArrayOfSubstringsSeparatedBy(Character::value('.'));
00099     if (parts->size() != 4) return nil;
00100     ByteArray *address = new ByteArray(4);
00101     for (int i = 0; i < 4; i++) {
00102         address->put(i, dynamic_cast<String *>(parts->at(i))->asNumber());
00103     }
00104     return address;
00105 }

ByteArray * IPSocketAddress::thisHost (  void   )  [static]
 

Definition at line 139 of file IPSocketAddress.cc.

Referenced by Net::SocketAccessor::newTCPserverAtPort(), Net::SocketAccessor::newUDPserverAtPort(), and thisHostAnyPort().

00140 {
00141     return new ByteArray("\x00\x00\x00\x00", 4);
00142 }

IPSocketAddress * IPSocketAddress::thisHostAnyPort (  void   )  [static]
 

Definition at line 63 of file IPSocketAddress.cc.

References anyPort(), hostAddress(), and thisHost().

Referenced by Net::SocketAccessor::newTCP(), and Net::SocketAccessor::newUDP().

00064 {
00065     return hostAddress(thisHost(), anyPort());
00066 }


Member Data Documentation

ByteArray* Net::IPSocketAddress::_address [protected]
 

Definition at line 36 of file IPSocketAddress.h.

Referenced by hostAddress().

unsigned short int Net::IPSocketAddress::_port [protected]
 

Definition at line 37 of file IPSocketAddress.h.

Referenced by port(), and printOn().


The documentation for this class was generated from the following files:
Generated on Mon Nov 27 09:52:14 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2