vpr::InetAddrBSD Class Reference

Cross-platform abstraction to Internet address structures. More...

#include <vpr/IO/Socket/InetAddr.h>

Inheritance diagram for vpr::InetAddrBSD:

Inheritance graph
[legend]
Collaboration diagram for vpr::InetAddrBSD:

Collaboration graph
[legend]
List of all members.

Public Types

typedef vpr::InetAddrHash hash

Public Member Functions

 InetAddrBSD ()
 Default constructor.
 InetAddrBSD (const InetAddrBSD &addr)
 Copy constructor.
vpr::ReturnStatus setAddress (const std::string &address)
 Constructs an address object using the given address.
vpr::ReturnStatus setAddress (const std::string &address, const Uint16 port)
 Sets the address for this object using the given address and port number.
vpr::ReturnStatus setAddress (const vpr::Uint32 address, const vpr::Uint16 port)
 Sets the address for this object using the given address and port number.
unsigned char getLength () const
 Gets the length of the address structure (if supported by the host OS).
void setLength (const unsigned char length)
 Sets the length of the address structure (if the host OS allows such an operation).
vpr::SocketTypes::Domain getFamily () const
 Gets the protocol family of this address structure.
void setFamily (const vpr::SocketTypes::Domain family)
 Sets the protocol family of this address structure.
vpr::Uint16 getPort () const
 Gets this address' port in host byte order.
void setPort (const vpr::Uint16 port)
 Sets this address' port.
vpr::Uint32 getAddressValue () const
 Gets this address's Internet address in host byte order.
std::string getAddressString () const
 Get the IP address associated with this structure as a human-readable string.
vpr::ReturnStatus getHostname (std::string &hostname) const
 Returns the fully qualified hostname for this address.
std::vector< std::string > getHostnames () const
 Returns the fully qualified primary hostname for this address and all known aliases.
InetAddrBSDoperator= (const InetAddrBSD &addr)
 Overloaded assignment operator to ensure that assignments work correctly.
bool operator== (const InetAddrBSD &addr) const
 Overloaded equality operator.
bool operator!= (const InetAddrBSD &addr) const
 Overloaded inequality operator.

Static Public Member Functions

static vpr::ReturnStatus getLocalHost (vpr::InetAddrBSD &hostAddr)
 Returns the local host's default address via the given object reference.
static vpr::ReturnStatus getAllLocalAddrs (std::vector< vpr::InetAddrBSD > &hostAddrs, const bool withLoopback=false)
 Retrieves all the IPv4 addresses associated with the local machine, including the loopback address (127.0.0.1) if so indicated.

Static Public Attributes

static const InetAddrBSD AnyAddr

Protected Member Functions

 InetAddrBSD (const struct sockaddr *addr)
 Constructs a vpr::InetAddrBSD object from a pointer to a sockaddr struct.
void copyAddressValue (const char *addrValue)
 Copies the given array of bytes (an A record) into this structure's IP address value.
void setAddressValue (const vpr::Uint32 addrValue)
 Sets this objects's IP address.
size_t size () const
 Gets the size of this object's encapsulated address structure.
size_t addressSize () const
 Gets the size of this object's IP address value.
void setSockaddr (const struct sockaddr *addr)
 Initializes the internal socket address structure using the given sockaddr* object.
sockaddr_in toSockaddrInet ()
 Converts this object to a sockaddr_in struct.
void copy (const InetAddrBSD &addr)
 Makes a copy of the given vpr::InetAddrBSD object in this object.
vpr::ReturnStatus lookupAddress (const std::string &addr)
 Look up the given address and store the address in mAddr.

Protected Attributes

sockaddr_in mAddr
 The Ineternet address structure.

Friends

class vpr::SocketImplBSD
class vpr::SocketDatagramImplBSD
class vpr::SocketStreamImplBSD

Detailed Description

Cross-platform abstraction to Internet address structures.

This is typedef'd to vpr::InetAddr.

Definition at line 70 of file InetAddrBSD.h.


Member Typedef Documentation

typedef vpr::InetAddrHash vpr::InetAddrBSD::hash

Definition at line 75 of file InetAddrBSD.h.


Constructor & Destructor Documentation

vpr::InetAddrBSD::InetAddrBSD (  ) 

Default constructor.

This initializes the memory for the encapsulated address structure.

Postcondition:
The mAddr structure has its memory zeroed, and the port and internet address are set to wildcard values.

Definition at line 79 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, mAddr, setAddressValue(), setFamily(), and setPort().

00080 {
00081    memset(&mAddr, 0, sizeof(mAddr));
00082    setAddressValue(INADDR_ANY);
00083    setPort(0);
00084    setFamily(SocketTypes::INET);
00085 }

vpr::InetAddrBSD::InetAddrBSD ( const InetAddrBSD addr  )  [inline]

Copy constructor.

Postcondition:
A copy of the given vpr::InetAddrBSD object is made in this object.
Parameters:
addr The vpr::InetAddrBSD object to be copied into this object.

Definition at line 94 of file InetAddrBSD.h.

References copy().

00095    {
00096       copy(addr);
00097    }

vpr::InetAddrBSD::InetAddrBSD ( const struct sockaddr *  addr  )  [inline, protected]

Constructs a vpr::InetAddrBSD object from a pointer to a sockaddr struct.

This is not typically useful to users but may be very important internally.

Precondition:
The given pointer points to a valid sockaddr struct.
Postcondition:
The memory pointed to by addr is copied into mAddr.
Parameters:
addr A pointer to a sockaddr struct containing a valid address.

Definition at line 323 of file InetAddrBSD.h.

References setSockaddr().

00324    {
00325       setSockaddr(addr);
00326    }


Member Function Documentation

vpr::ReturnStatus vpr::InetAddrBSD::getLocalHost ( vpr::InetAddrBSD hostAddr  )  [static]

Returns the local host's default address via the given object reference.

Parameters:
hostAddr Storage for the returned address object.
Returns:
vpr::ReturnStatus::Succeed is returned if the local host has an an address. Otherwise, vpr::ReturnStatus::Fail is returned.

Definition at line 87 of file InetAddrBSD.cpp.

References vpr::ReturnStatus::Fail, setAddress(), and vpr::ReturnStatus::setCode().

00088 {
00089    char local_host_name[MAXHOSTNAMELEN + 1];
00090    vpr::ReturnStatus status;
00091 
00092    bzero(local_host_name, sizeof(local_host_name));
00093 
00094    if ( gethostname(local_host_name, MAXHOSTNAMELEN) == 0 )
00095    {
00096       hostAddr.setAddress(std::string(local_host_name), 0);
00097    }
00098    else
00099    {
00100       status.setCode(vpr::ReturnStatus::Fail);
00101    }
00102 
00103    return status;
00104 }

vpr::ReturnStatus vpr::InetAddrBSD::getAllLocalAddrs ( std::vector< vpr::InetAddrBSD > &  hostAddrs,
const bool  withLoopback = false 
) [static]

Retrieves all the IPv4 addresses associated with the local machine, including the loopback address (127.0.0.1) if so indicated.

Postcondition:
hostAddrs contains vpr::InetAddr objetcs holding all the local IPv4 addresses for the local machine.
Parameters:
hostAddrs Storage for the discovered local IPv4 addresses. The vector is cleared before the addresses are added, so any objects currently in the vector are lost.
withLoopback A flag indicating whether to include the loopback address (127.0.0.1) in hostAddrs. This parameter is optional and defaults to false.
Note:
This method currently supports only IPv4.
Returns:
vpr::ReturnStatus::Succeed is returned if the querying of all local addresses completes without error. Otherwise, vpr::ReturnStatus::Fail is returned.
Since:
1.0.2

Definition at line 107 of file InetAddrBSD.cpp.

References vpr::getIfAddrs().

00109 {
00110    return vpr::getIfAddrs(hostAddrs, withLoopback);
00111 }

vpr::ReturnStatus vpr::InetAddrBSD::setAddress ( const std::string &  address  ) 

Constructs an address object using the given address.

It must be of the form address:port where address can be a hostname or a dotted-decimal IP address.

Parameters:
address A string giving the address and port number separated by a colon. The address can be a hostname or a dotted-decimal IP address.

Reimplemented from vpr::InetAddrBase.

Definition at line 118 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, lookupAddress(), setFamily(), and setPort().

Referenced by vpr::getIfAddrs(), getLocalHost(), and vpr::SocketImplBSD::getOption().

00119 {
00120    std::string::size_type pos;
00121    std::string host_addr, host_port;
00122    vpr::Uint16 port;
00123    vpr::ReturnStatus retval;
00124 
00125    // Extract the address and the port number from the given string.
00126    pos       = address.find(":");
00127    host_addr = address.substr(0, pos);
00128    host_port = address.substr(pos + 1);
00129    port      = (Uint16) atoi(host_port.c_str());
00130 
00131    retval = lookupAddress(host_addr);
00132    setPort(port);
00133    setFamily(vpr::SocketTypes::INET);
00134 
00135    return retval;
00136 }

vpr::ReturnStatus vpr::InetAddrBSD::setAddress ( const std::string &  address,
const Uint16  port 
)

Sets the address for this object using the given address and port number.

The address string can be a hostname or a dotted-decimal IP address.

Parameters:
address A string giving the address (either hostname or IP address).
port The port to associate with this IP address.

Reimplemented from vpr::InetAddrBase.

Definition at line 138 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, lookupAddress(), setFamily(), and setPort().

00140 {
00141    vpr::ReturnStatus retval;
00142 
00143    retval = lookupAddress(address);
00144    setPort(port);
00145    setFamily(SocketTypes::INET);
00146 
00147    return retval;
00148 }

vpr::ReturnStatus vpr::InetAddrBSD::setAddress ( const vpr::Uint32  address,
const vpr::Uint16  port 
)

Sets the address for this object using the given address and port number.

The address must be the actual 32-bit integer value.

Parameters:
address A 32-bit integer IP address.
port The port to associate with this IP address.

Reimplemented from vpr::InetAddrBase.

Definition at line 150 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, setAddressValue(), setFamily(), and setPort().

00152 {
00153    setAddressValue(address);
00154    setPort(port);
00155    setFamily(SocketTypes::INET);
00156    return ReturnStatus();
00157 }

unsigned char vpr::InetAddrBSD::getLength (  )  const

Gets the length of the address structure (if supported by the host OS).

Precondition:
None.
Postcondition:
The length of the address structure is returned if the OS supports that feature. Otherwise, 0 is returned.
Returns:
A value greather than 0 is return to indicate the length of the encapsulated address. 0 is returned if the OS does not support address structure length.

Definition at line 159 of file InetAddrBSD.cpp.

References mAddr.

00160 {
00161 #ifdef HAVE_SIN_LEN
00162    return mAddr.sin_len;
00163 #else
00164    return 0;
00165 #endif
00166 }

void vpr::InetAddrBSD::setLength ( const unsigned char  length  ) 

Sets the length of the address structure (if the host OS allows such an operation).

Precondition:
None.
Postcondition:
The address strcture's length is set to the given value if the OS supports it. Otherwise, this is a no-op.
Parameters:
length The length of the address structure.

Definition at line 168 of file InetAddrBSD.cpp.

References mAddr.

00169 {
00170 #ifdef HAVE_SIN_LEN
00171    mAddr.sin_len = length;
00172 #else
00173    boost::ignore_unused_variable_warning(length);
00174 #endif
00175 }

vpr::SocketTypes::Domain vpr::InetAddrBSD::getFamily (  )  const

Gets the protocol family of this address structure.

Precondition:
The protocol family has been properly initialized.
Postcondition:
The protocol family is returned as a vpr::SocketTypes::Domain value.
Returns:
A vpr::SocketTypes::Domain value representing this object's protocol family.

Reimplemented from vpr::InetAddrBase.

Definition at line 180 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, vpr::SocketTypes::INET6, vpr::SocketTypes::LINK, vpr::SocketTypes::LOCAL, and mAddr.

Referenced by vpr::SocketImplNSPR::open(), and vpr::SocketImplBSD::open().

00181 {
00182    vpr::SocketTypes::Domain family;
00183 
00184    switch ( mAddr.sin_family )
00185    {
00186 #ifdef PF_LOCAL
00187       case PF_LOCAL:
00188 #else
00189       case PF_UNIX:
00190 #endif
00191          family = SocketTypes::LOCAL;
00192          break;
00193       case PF_INET:
00194          family = SocketTypes::INET;
00195          break;
00196 #ifdef PF_INET6
00197       case PF_INET6:
00198          family = SocketTypes::INET6;
00199          break;
00200 #endif
00201 #if defined(PF_LINK) || defined(PF_RAW)
00202 #ifdef PF_LINK
00203       case PF_LINK:
00204 #else
00205       case PF_RAW:
00206 #endif
00207          family = SocketTypes::LINK;
00208          break;
00209 #endif
00210       default:
00211          family = SocketTypes::INET;
00212          break;
00213    }
00214 
00215    return family;
00216 }

void vpr::InetAddrBSD::setFamily ( const vpr::SocketTypes::Domain  family  ) 

Sets the protocol family of this address structure.

Precondition:
None.
Postcondition:
The given protocol family (a vpr::SocketTypes::Domain value) is mapped to the appropriate platform-specific protocol family value and stored.
Parameters:
family The protocol family value.

Reimplemented from vpr::InetAddrBase.

Definition at line 221 of file InetAddrBSD.cpp.

References vpr::SocketTypes::INET, vpr::SocketTypes::INET6, vpr::SocketTypes::LINK, vpr::SocketTypes::LOCAL, and mAddr.

Referenced by InetAddrBSD(), and setAddress().

00222 {
00223    switch ( family )
00224    {
00225       case SocketTypes::LOCAL:
00226 #ifdef PF_LOCAL
00227          mAddr.sin_family = PF_LOCAL;
00228 #else
00229          mAddr.sin_family = PF_UNIX;
00230 #endif
00231          break;
00232       case SocketTypes::INET:
00233          mAddr.sin_family = PF_INET;
00234          break;
00235       case SocketTypes::INET6:
00236 #ifdef PF_INET6
00237          mAddr.sin_family = PF_INET6;
00238 #else
00239          fprintf(stderr,
00240                  "[vpr::InetAddrBSD] WARNING: IPv6 not supported on this host!\n");
00241 #endif
00242          break;
00243 #if defined(PF_LINK) || defined(PF_RAW)
00244       case SocketTypes::LINK:
00245 #ifdef PF_LINK
00246          mAddr.sin_family = PF_LINK;
00247 #else
00248          mAddr.sin_family = PF_RAW;
00249 #endif
00250          break;
00251 #endif
00252       default:
00253          fprintf(stderr,
00254                  "[vpr::InetAddrBSD] ERROR: Unknown socket family value %d\n",
00255                  family);
00256          break;
00257    }
00258 }

vpr::Uint16 vpr::InetAddrBSD::getPort (  )  const

Gets this address' port in host byte order.

Precondition:
The port has been initialized properly in network byte order.
Postcondition:
The port associated with this address is returned to the caller in host byte order.
Returns:
An unsigned 16-bit integer giving the port for this address in host byte order.

Reimplemented from vpr::InetAddrBase.

Definition at line 260 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::sim::NetworkNode::addSocket(), vpr::InetAddrHash::operator()(), operator<(), std::operator<<(), vpr::SocketDatagramImplBSD::recvfrom(), vpr::sim::NetworkNode::removeSocket(), and vpr::SocketDatagramImplBSD::sendto().

00261 {
00262    return ntohs(mAddr.sin_port);
00263 }

void vpr::InetAddrBSD::setPort ( const vpr::Uint16  port  ) 

Sets this address' port.

The given port must be in host byte order.

Precondition:
The given port number is in host byte order.
Postcondition:
The given port number is stored in the address.
Parameters:
port An unsigned 16-bit integer port number for this address in host byte order.

Reimplemented from vpr::InetAddrBase.

Definition at line 265 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::SocketStreamImplSIM::accept(), InetAddrBSD(), and setAddress().

00266 {
00267    mAddr.sin_port = htons(port);
00268 }

vpr::Uint32 vpr::InetAddrBSD::getAddressValue (  )  const

Gets this address's Internet address in host byte order.

Precondition:
The IP address has been initialized properly in network byte order.
Postcondition:
The IP address associated with this address structure is returned to the caller in host byte order.
Returns:
An unsigned 32-bit integer giving the IP address for this object in host byte order.

Reimplemented from vpr::InetAddrBase.

Definition at line 270 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::sim::NetworkNode::addSocket(), vpr::InetAddrHash::operator()(), operator<(), vpr::sim::NetworkNode::removeSocket(), and vpr::SocketImplBSD::setOption().

00271 {
00272    return ntohl(mAddr.sin_addr.s_addr);
00273 }

std::string vpr::InetAddrBSD::getAddressString (  )  const

Get the IP address associated with this structure as a human-readable string.

Precondition:
The object contains a valid IP address.
Postcondition:
The integer IP address is converted to dotted-decmial notation and returned as a string.
Returns:
A std::string object containing this structure's IP address in the human-readable "dotted-decimal" notation.

Reimplemented from vpr::InetAddrBase.

Definition at line 279 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::SocketStreamImplBSD::accept(), vpr::SocketImplBSD::connect(), vpr::SocketImplBSD::open(), std::operator<<(), vpr::SocketDatagramImplBSD::recvfrom(), vpr::SocketDatagramImplBSD::sendto(), vpr::SocketImplBSD::SocketImplBSD(), and vpr::SocketImplNSPR::SocketImplNSPR().

00280 {
00281    char ip_addr[sizeof("255.255.255.255")];
00282    std::string ip_str;
00283    union
00284    {
00285       char c[sizeof(vpr::Uint32)];
00286       vpr::Uint32 value;
00287    } addr;
00288 
00289    addr.value = mAddr.sin_addr.s_addr;
00290 
00291    snprintf(ip_addr, sizeof(ip_addr), "%u.%u.%u.%u", (Uint8) addr.c[0],
00292             (Uint8) addr.c[1], (Uint8) addr.c[2], (Uint8) addr.c[3]);
00293    ip_str = ip_addr;
00294 
00295    return ip_str;
00296 }

vpr::ReturnStatus vpr::InetAddrBSD::getHostname ( std::string &  hostname  )  const

Returns the fully qualified hostname for this address.

Reimplemented from vpr::InetAddrBase.

Definition at line 298 of file InetAddrBSD.cpp.

References clrOutBOLD, clrRED, vpr::ReturnStatus::Fail, mAddr, vpr::ReturnStatus::setCode(), vprDBG_CRITICAL_LVL, vprDBG_VPR(), vprDEBUG, and vprDEBUG_FLUSH.

00299 {
00300    vpr::ReturnStatus status;
00301 
00302    socklen_t salen;
00303 #if defined(HAVE_SIN_LEN)
00304    salen = mAddr.sin_len;
00305 #else
00306    salen = sizeof(mAddr);
00307 #endif
00308 
00309    char addr[NI_MAXHOST];
00310    memset((void*) &addr, 0, sizeof(addr));
00311 
00312    int result = getnameinfo((sockaddr*) &mAddr, salen, addr, sizeof(addr),
00313                             NULL, 0, NI_NAMEREQD);
00314 
00315    if ( result == 0 )
00316    {
00317       hostname = addr;
00318    }
00319    else
00320    {
00321       status.setCode(vpr::ReturnStatus::Fail);
00322       vprDEBUG(vprDBG_VPR, vprDBG_CRITICAL_LVL) 
00323          << clrOutBOLD(clrRED, "ERROR")
00324          << ": [vpr::InetAddrBSD::getHostname()] Could not find hostname for "
00325          << inet_ntoa(mAddr.sin_addr) << ": " << gai_strerror(result)
00326          << std::endl << vprDEBUG_FLUSH;
00327    }
00328 
00329    return status;
00330 }

std::vector< std::string > vpr::InetAddrBSD::getHostnames (  )  const

Returns the fully qualified primary hostname for this address and all known aliases.

Reimplemented from vpr::InetAddrBase.

Definition at line 332 of file InetAddrBSD.cpp.

References mAddr.

00333 {
00334    std::vector<std::string> names;
00335    struct hostent* entry;
00336 
00337    entry = gethostbyaddr((const char*) &mAddr.sin_addr,
00338                          sizeof(mAddr.sin_addr), mAddr.sin_family);
00339 
00340    if ( NULL != entry )
00341    {
00342       names.push_back(std::string(entry->h_name));
00343 
00344       for ( char** ptr = entry->h_aliases; *ptr != NULL; ptr++ )
00345       {
00346          names.push_back(std::string(*ptr));
00347       }
00348    }
00349 
00350    return names;
00351 }

InetAddrBSD& vpr::InetAddrBSD::operator= ( const InetAddrBSD addr  )  [inline]

Overloaded assignment operator to ensure that assignments work correctly.

Precondition:
None.
Postcondition:
A copy of the given vpr::InetAddrBSD object is made in this object which is then returned to the caller.
Parameters:
addr The vpr::InetAddrBSD object to be copied into this object.
Returns:
A reference to this object.

Definition at line 289 of file InetAddrBSD.h.

References copy().

00290    {
00291       copy(addr);
00292       return *this;
00293    }

bool vpr::InetAddrBSD::operator== ( const InetAddrBSD addr  )  const

Overloaded equality operator.

Definition at line 354 of file InetAddrBSD.cpp.

References mAddr.

00355 {
00356    return (mAddr.sin_addr.s_addr == addr.mAddr.sin_addr.s_addr) &&
00357           (mAddr.sin_port == addr.mAddr.sin_port) &&
00358           (mAddr.sin_family == addr.mAddr.sin_family);
00359 }

bool vpr::InetAddrBSD::operator!= ( const InetAddrBSD addr  )  const [inline]

Overloaded inequality operator.

Definition at line 303 of file InetAddrBSD.h.

00304    {
00305       return ! (*this == addr);
00306    }

void vpr::InetAddrBSD::copyAddressValue ( const char *  addrValue  )  [protected]

Copies the given array of bytes (an A record) into this structure's IP address value.

The record must be in network byte order. This method is useful when working with host entries returned by gethostname(3).

Precondition:
The given array of bytes represents an A record in network byte order.
Postcondition:
The bytes are copied into this structure's IP address value.
Parameters:
addrValue The A record contianing an IP address in network byte order.

Definition at line 361 of file InetAddrBSD.cpp.

References mAddr, and vprASSERT.

00362 {
00363    vprASSERT(addrValue != NULL);
00364    memcpy((void*) &mAddr.sin_addr.s_addr, (void*) addrValue,
00365           sizeof(mAddr.sin_addr.s_addr));
00366 }

void vpr::InetAddrBSD::setAddressValue ( const vpr::Uint32  addrValue  )  [protected]

Sets this objects's IP address.

The given address must be in host byte order.

Precondition:
The given IP address is in host byte order.
Postcondition:
The given IP address is stored.
Parameters:
addrValue An unsigned 32-bit integer IP address for this object in host byte order.

Definition at line 368 of file InetAddrBSD.cpp.

References mAddr.

Referenced by InetAddrBSD(), and setAddress().

00369 {
00370    mAddr.sin_addr.s_addr = htonl(addrValue);
00371 }

size_t vpr::InetAddrBSD::size (  )  const [protected]

Gets the size of this object's encapsulated address structure.

Precondition:
None.
Postcondition:
The static size of mAddr is returned to the caller.
Returns:
A value of type size_t giving the size of the encapsualted address structure.

Definition at line 373 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::SocketStreamImplBSD::accept(), vpr::SocketImplBSD::bind(), vpr::SocketImplBSD::connect(), vpr::SocketDatagramImplBSD::recvfrom(), and vpr::SocketDatagramImplBSD::sendto().

00374 {
00375    return sizeof(mAddr);
00376 }

size_t vpr::InetAddrBSD::addressSize (  )  const [protected]

Gets the size of this object's IP address value.

Precondition:
None.
Postcondition:
The static size of the IP address is returned to the caller.
Returns:
A value of type size_t giving the size of this object's IP address.

Definition at line 378 of file InetAddrBSD.cpp.

References mAddr.

00379 {
00380    return sizeof(mAddr.sin_addr.s_addr);
00381 }

void vpr::InetAddrBSD::setSockaddr ( const struct sockaddr *  addr  )  [protected]

Initializes the internal socket address structure using the given sockaddr* object.

This will overwrite a previously set address.

Postcondition:
The memory pointed to by the given object is copied into this object's mAddr structure.
Parameters:
addr A pointer to the sockaddr object being used to initialize this object's address.

Definition at line 383 of file InetAddrBSD.cpp.

References mAddr.

Referenced by vpr::SocketImplBSD::connect(), and InetAddrBSD().

00384 {
00385    memcpy((void*) &mAddr, (void*) addr, sizeof(mAddr));
00386 }

struct sockaddr_in vpr::InetAddrBSD::toSockaddrInet (  )  [protected]

Converts this object to a sockaddr_in struct.

Precondition:
None.
Postcondition:
A copy of a sockaddr_in struct equivalent to this object is returned to the caller.

Definition at line 388 of file InetAddrBSD.cpp.

00389 {
00390    return mAddr;
00391 }

void vpr::InetAddrBSD::copy ( const InetAddrBSD addr  )  [protected]

Makes a copy of the given vpr::InetAddrBSD object in this object.

Precondition:
None.
Postcondition:
The memory in mAddr is overwritten with that of the given object's mAddr structure.
Parameters:
addr The vpr::InetAddrBSD object to be copied into this object.

Definition at line 393 of file InetAddrBSD.cpp.

References mAddr.

Referenced by InetAddrBSD(), and operator=().

00394 {
00395    memcpy((void*) &mAddr, (void*) &addr.mAddr, sizeof(mAddr));
00396 }

vpr::ReturnStatus vpr::InetAddrBSD::lookupAddress ( const std::string &  addr  )  [protected]

Look up the given address and store the address in mAddr.

Precondition:
None.
Postcondition:
The given address string is converted into a 32-bit INET address. The mAddr member variable is populated accordingly.
Returns:
vpr::ReturnStatus::Succeed is returned if the address lookup was successful. vpr::ReturnStatus::Fail is returned otherwise.

Definition at line 401 of file InetAddrBSD.cpp.

References clrOutBOLD, clrYELLOW, vpr::ReturnStatus::Fail, mAddr, vpr::ReturnStatus::setCode(), vprDBG_ALL(), vprDBG_WARNING_LVL, vprDEBUG, and vprDEBUG_FLUSH.

Referenced by setAddress().

00402 {
00403    vpr::ReturnStatus retval;
00404    struct addrinfo* addrs;
00405 
00406    struct addrinfo hints;
00407    memset((void*) &hints, 0, sizeof(hints));
00408    hints.ai_flags = AF_INET;
00409 
00410    int result = getaddrinfo(address.c_str(), NULL, &hints, &addrs);
00411 
00412    if ( result == 0 )
00413    {
00414       memcpy((void*) &mAddr, addrs->ai_addr, addrs->ai_addrlen);
00415       freeaddrinfo(addrs);
00416    }
00417    else
00418    {
00419       vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL)
00420          << clrOutBOLD(clrYELLOW, "WARNING")
00421          << ": Could not find address for '" << address << "': "
00422          << gai_strerror(result) << std::endl << vprDEBUG_FLUSH;
00423 
00424       retval.setCode(vpr::ReturnStatus::Fail);
00425    }
00426 
00427    return retval;
00428 }


Friends And Related Function Documentation

friend class vpr::SocketImplBSD [friend]

Definition at line 309 of file InetAddrBSD.h.

friend class vpr::SocketDatagramImplBSD [friend]

Definition at line 310 of file InetAddrBSD.h.

friend class vpr::SocketStreamImplBSD [friend]

Definition at line 311 of file InetAddrBSD.h.


Member Data Documentation

const InetAddrBSD vpr::InetAddrBSD::AnyAddr [static]

Definition at line 73 of file InetAddrBSD.h.

Referenced by vpr::sim::SocketManager::assignToNode(), vpr::sim::SocketManager::connect(), vpr::SocketImplNSPR::connect(), vpr::SocketImplBSD::connect(), and vpr::SocketDatagramImplNSPR::sendto().

struct sockaddr_in vpr::InetAddrBSD::mAddr [protected]

The Ineternet address structure.

Definition at line 420 of file InetAddrBSD.h.

Referenced by vpr::SocketStreamImplBSD::accept(), addressSize(), vpr::SocketImplBSD::bind(), vpr::SocketImplBSD::connect(), copy(), copyAddressValue(), getAddressString(), getAddressValue(), getFamily(), getHostname(), getHostnames(), getLength(), getPort(), InetAddrBSD(), lookupAddress(), operator==(), vpr::SocketDatagramImplBSD::recvfrom(), vpr::SocketDatagramImplBSD::sendto(), setAddressValue(), setFamily(), setLength(), setPort(), setSockaddr(), and size().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:55:33 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1