Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

SocketAddress Class Reference

Represents an IP address and a port, in other words, one side of a TCP connection. More...

#include <SocketAddress.h>

Inheritance diagram for SocketAddress::

BasicObject List of all members.

Public Methods

 SocketAddress ()
 Create a SocketAddress with IP address and port initialized to zero. More...

 SocketAddress (IpAddress, unsigned short)
 Create and initialize the SocketAddress with the given parameters. More...

 SocketAddress (struct sockaddr_in *)
 Create the object with a sockaddr_in structure. More...

 SocketAddress (const SocketAddress &)
 Copy constructor. More...

virtual ~SocketAddress ()
void setSocketAddress (struct sockaddr_in *)
void setSocketAddress (const IpAddress &, unsigned short)
void setIpAddress (const IpAddress &)
void setPort (unsigned short)
void setPort (const char *)
void setPort (string)
sockaddr_in * getSockAddrStruct ()
 Return a pointer to the internal sockaddr_in structure. More...

OS_SPEC_SOCKLEN * getSockAddrStructLen ()
unsigned short getPort ()
IpAddress getIpAddress ()
bool isZero ()
 Return false if the IP address or port is zero. More...

bool read (std::istream &)
 Read in an IP address and port in the form "IP:port". More...

bool read (const char *)
 Does the same thing as read(istream&), but with a char array as input. More...

bool read (string)
 Does the same thing as read(istream&), but with a string as input. More...

virtual void toStream (std::ostream &)
 Print "IP:port". More...

const char * toCStr ()
 Get a C string representation of the SocketAddress. More...


Static Private Methods

void initSockAddr (struct sockaddr_in *sockAddr, unsigned int ipAddr, int port)
 Initialize a sockaddr_in structure. More...


Private Attributes

IpAddress m_ipAddr
unsigned short m_port
sockaddr_in m_sockAddrStruct
OS_SPEC_SOCKLEN m_sockAddrStructLen
char m_cstr [MAX_IP_ADDR_STR+1+5]
 IP address + ":" + port. More...


Detailed Description

Represents an IP address and a port, in other words, one side of a TCP connection.

Definition at line 12 of file SocketAddress.h.


Constructor & Destructor Documentation

SocketAddress::SocketAddress
 

Create a SocketAddress with IP address and port initialized to zero.

Definition at line 12 of file SocketAddress.cpp.

SocketAddress::SocketAddress IpAddress ipAddr,
unsigned short port
 

Create and initialize the SocketAddress with the given parameters.

Definition at line 22 of file SocketAddress.cpp.

SocketAddress::SocketAddress struct sockaddr_in * value
 

Create the object with a sockaddr_in structure.

Definition at line 32 of file SocketAddress.cpp.

SocketAddress::SocketAddress const SocketAddress & value
 

Copy constructor.

Definition at line 41 of file SocketAddress.cpp.

SocketAddress::~SocketAddress [virtual]
 

Definition at line 52 of file SocketAddress.cpp.


Member Function Documentation

IpAddress SocketAddress::getIpAddress
 

Definition at line 139 of file SocketAddress.cpp.

Referenced by LinkLayerInterface::accept(), NodeManagerCommand::addNode(), TcpConnection::connect(), LinkLayerInterface::connect(), NodeManagerCommand::displayNode(), ConnectionManagerCommand::displayNode(), VisualizerFrame::drawNodes(), Node::equals(), UserConfiguration::generateNodeHtmlInterface(), SummaryScreenCommand::getHtmlInterface(), WebServer::handleConnection(), TcpConnection::isConnectedTo(), Catcher::lookup(), LinkLayerInterface::peerConnectImpl(), ConnectionPacket::setSocketAddress(), and VirtualCircuitTableEntry::toStream().

unsigned short SocketAddress::getPort
 

Definition at line 133 of file SocketAddress.cpp.

Referenced by TcpConnection::connect(), NodeManagerCommand::displayNode(), ConnectionManagerCommand::displayNode(), UserConfiguration::generateNodeHtmlInterface(), SummaryScreenCommand::getHtmlInterface(), BasicConfigurationCommand::run(), ConnectionPacket::setSocketAddress(), ProxyCommandProcessor::toStream(), and HttpTestCommandProcessor::toStream().

struct sockaddr_in * SocketAddress::getSockAddrStruct
 

Return a pointer to the internal sockaddr_in structure.

If the struct is modified outside of this object, you must re-sync it with this object by calling setSocketAddress(struct sockaddr_in).

Definition at line 121 of file SocketAddress.cpp.

Referenced by TcpConnection::accept(), and TcpConnection::createListeningSocket().

OS_SPEC_SOCKLEN * SocketAddress::getSockAddrStructLen
 

Definition at line 127 of file SocketAddress.cpp.

Referenced by TcpConnection::createListeningSocket().

void SocketAddress::initSockAddr struct sockaddr_in * sockAddr,
unsigned int ipAddr,
int port
[static, private]
 

Initialize a sockaddr_in structure.

Parameters:
ipAddr   The IP address you want to bind to, INADDR_ANY if you want to bind to loopback.
port   The port number you want, in standard decimal form. Use zero if you want the port to be assigned for you.

Definition at line 63 of file SocketAddress.cpp.

Referenced by setIpAddress(), and setPort().

bool SocketAddress::isZero
 

Return false if the IP address or port is zero.

Definition at line 168 of file SocketAddress.cpp.

bool SocketAddress::read string buf
 

Does the same thing as read(istream&), but with a string as input.

Definition at line 213 of file SocketAddress.cpp.

bool SocketAddress::read const char * buf
 

Does the same thing as read(istream&), but with a char array as input.

Definition at line 203 of file SocketAddress.cpp.

bool SocketAddress::read std::istream & in
 

Read in an IP address and port in the form "IP:port".

It is assumed that the read pointer is placed at the beginning of the IP address. When the function exits the read pointer will be at the end of port.

Returns:
true if the read was successful, false otherwise.

Definition at line 182 of file SocketAddress.cpp.

Referenced by operator>>(), and read().

void SocketAddress::setIpAddress const IpAddress & value
 

Definition at line 72 of file SocketAddress.cpp.

Referenced by SocketAddress(), ConnectionPacket::getSocketAddress(), WebServer::getSocketAddressFromHttp(), and read().

void SocketAddress::setPort string value
 

Definition at line 110 of file SocketAddress.cpp.

void SocketAddress::setPort const char * value
 

Definition at line 104 of file SocketAddress.cpp.

void SocketAddress::setPort unsigned short value
 

Definition at line 94 of file SocketAddress.cpp.

Referenced by SocketAddress(), ConnectionPacket::getSocketAddress(), WebServer::getSocketAddressFromHttp(), read(), and setPort().

void SocketAddress::setSocketAddress const IpAddress & ,
unsigned short
 

void SocketAddress::setSocketAddress struct sockaddr_in * value
 

Definition at line 82 of file SocketAddress.cpp.

Referenced by SocketAddress(), and TcpConnection::accept().

const char * SocketAddress::toCStr
 

Get a C string representation of the SocketAddress.

You may NOT modify the memory returned.

Definition at line 158 of file SocketAddress.cpp.

Referenced by SocketAddress(), TcpConnection::accept(), LinkLayerInterface::connect(), TcpConnection::createListeningSocket(), WebServer::handleConnection(), read(), setIpAddress(), setPort(), and setSocketAddress().

void SocketAddress::toStream std::ostream & out [virtual]
 

Print "IP:port".

Reimplemented from BasicObject.

Definition at line 148 of file SocketAddress.cpp.


Member Data Documentation

char SocketAddress::m_cstr[MAX_IP_ADDR_STR + 1 + 5] [private]
 

IP address + ":" + port.

Definition at line 50 of file SocketAddress.h.

IpAddress SocketAddress::m_ipAddr [private]
 

Definition at line 44 of file SocketAddress.h.

unsigned short SocketAddress::m_port [private]
 

Definition at line 45 of file SocketAddress.h.

struct sockaddr_in SocketAddress::m_sockAddrStruct [private]
 

Definition at line 46 of file SocketAddress.h.

OS_SPEC_SOCKLEN SocketAddress::m_sockAddrStructLen [private]
 

Definition at line 47 of file SocketAddress.h.


The documentation for this class was generated from the following files:
Generated at Thu Jul 11 13:31:59 2002 for Peekabooty by doxygen1.2.9 written by Dimitri van Heesch, © 1997-2001