Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
GrayLib::cNetAddrName Class Reference

#include <cNetAddrName.h>

Public Member Functions

 cNetAddrName (NET_PORT_t wPortDefault=k_NET_PORT_INVALID)
 
 cNetAddrName (const char *pszHostAndPort, bool bWait=false)
 
 cNetAddrName (const char *pszHostAndMaybePort, NET_PORT_t wPortDefault, bool bWait=false)
 
 cNetAddrName (in_addr ip, NET_PORT_t wPort)
 
HRESULT UpdateHostAddrFromName (bool bWait)
 
HRESULT UpdateHostNameFromAddr (bool bWait)
 
bool isAddrValid () const
 
const cNetAddressget_Addr () const
 
cNetAddressref_Addr ()
 
HRESULT SetAddr (const cNetAddress &rAddr, bool bWait=false)
 
NET_PORT_t get_AddrPort () const
 
void SetAddrPort (NET_PORT_t wPort, bool bHasNonDefaultPort=false)
 
bool MakeValidHostAddr ()
 
bool isEmptyAddrName () const
 
void SetEmptyAddrName ()
 
cStringA get_AddrName () const
 
HRESULT SetAddrName (cStringA sAddr, bool bWait=false)
 
cStringA get_HostName () const
 
HRESULT SetHostName (const char *pszHost, bool bWait=false)
 
HRESULT SetHostNameLocal (bool bWait)
 
void ResetHost ()
 
 UNITTEST_FRIEND (cNetAddrName)
 

Static Public Member Functions

static bool IsValidHostNameChar (char ch)
 

Protected Member Functions

void FixAddrName ()
 

Protected Attributes

cStringA m_sAddrName
 This can be "hostname:port" or just "hostname". use NI_MAXHOST. More...
 
NET_PORT_t m_wPortDefault
 This default port might (need not) be in name string. m_sAddrName. More...
 
cNetAddress m_Addr
 resolved/Converted to native binary format. (NOTE: this may just be the first in a list resolved from DNS) More...
 

Detailed Description

the resolved net address + port from the original DNS host name (or ip address) string (plus port). the IP for the host name may change (or have multiple values). we can re-resolve the host name via DNS later. This can be "hostname:port" or "IP:port" may or may not have a port.

Note
address name and binary address should always be in sync unless one is null and is to be filled in later.

k_NET_HOSTNAME_MAX = NI_MAXHOST = max length of a host name. (was MAXHOSTNAMELEN?) Windows = 255 or 1024 ? Solaris = 256 characters OLD UNIX version code = 99 HP-UX = 64 characters

Constructor & Destructor Documentation

◆ cNetAddrName() [1/4]

GrayLib::cNetAddrName::cNetAddrName ( NET_PORT_t  wPortDefault = k_NET_PORT_INVALID)
inline

invalid address.

◆ cNetAddrName() [2/4]

GrayLib::cNetAddrName::cNetAddrName ( const char *  pszHostAndPort,
bool  bWait = false 
)
inline

◆ cNetAddrName() [3/4]

GrayLib::cNetAddrName::cNetAddrName ( const char *  pszHostAndMaybePort,
NET_PORT_t  wPortDefault,
bool  bWait = false 
)
inline

Set the address by hostname.

  • wPortDefault = supply a default port in case the port is not in the string.

◆ cNetAddrName() [4/4]

GrayLib::cNetAddrName::cNetAddrName ( in_addr  ip,
NET_PORT_t  wPort 
)
inline

IPv4 = cNetHost4

Member Function Documentation

◆ FixAddrName()

void GrayLib::cNetAddrName::FixAddrName ( )
protected

Strip port from the m_sAddrName text if its the default port else leave it in.

◆ get_Addr()

const cNetAddress& GrayLib::cNetAddrName::get_Addr ( ) const
inline

◆ get_AddrName()

cStringA GrayLib::cNetAddrName::get_AddrName ( ) const
inline

◆ get_AddrPort()

NET_PORT_t GrayLib::cNetAddrName::get_AddrPort ( ) const
inline

◆ get_HostName()

cStringA GrayLib::cNetAddrName::get_HostName ( ) const
Returns
just the hostname. strip out port if it has one.

◆ isAddrValid()

bool GrayLib::cNetAddrName::isAddrValid ( ) const
inline

◆ isEmptyAddrName()

bool GrayLib::cNetAddrName::isEmptyAddrName ( ) const
inline

◆ IsValidHostNameChar()

static bool GrayLib::cNetAddrName::IsValidHostNameChar ( char  ch)
inlinestatic

◆ MakeValidHostAddr()

bool GrayLib::cNetAddrName::MakeValidHostAddr ( )
inline

Update IP address from name only if needed. Leave port.

Note
This is a blocking call !!!!

◆ ref_Addr()

cNetAddress& GrayLib::cNetAddrName::ref_Addr ( )
inline

for use with cNetHostAsync::AsyncComplete

◆ ResetHost()

void GrayLib::cNetAddrName::ResetHost ( )
inline

Reset just host (so it will re-resolve) but not the port.

◆ SetAddr()

HRESULT GrayLib::cNetAddrName::SetAddr ( const cNetAddress rAddr,
bool  bWait = false 
)
inline

◆ SetAddrName()

HRESULT GrayLib::cNetAddrName::SetAddrName ( cStringA  sAddr,
bool  bWait = false 
)

set the host and port by name.

  • pszAddr = may contain port number or not. no port = leave old port.
  • bWait= false = look up the IP address later with a call to UpdateHostFromAddrName().

◆ SetAddrPort()

void GrayLib::cNetAddrName::SetAddrPort ( NET_PORT_t  wPort,
bool  bHasNonDefaultPort = false 
)

Set just the port. Reflect this back to the AddrName if not default port.

◆ SetEmptyAddrName()

void GrayLib::cNetAddrName::SetEmptyAddrName ( )
inline

◆ SetHostName()

HRESULT GrayLib::cNetAddrName::SetHostName ( const char *  pszHost,
bool  bWait = false 
)

strip out port if it has one.

◆ SetHostNameLocal()

HRESULT GrayLib::cNetAddrName::SetHostNameLocal ( bool  bWait)

Set this to the local host name. port is not set. lookup my actual IP if they want me to (and possible).

Returns
true = OK
Note
Assume cNetSystem was init.

◆ UNITTEST_FRIEND()

GrayLib::cNetAddrName::UNITTEST_FRIEND ( cNetAddrName  )

◆ UpdateHostAddrFromName()

HRESULT GrayLib::cNetAddrName::UpdateHostAddrFromName ( bool  bWait)

Update IP address from name. port will not change. sometimes the IP address will change for the same host name over time! DNS lease expires, etc.

  • bWait = This is a blocking call.

◆ UpdateHostNameFromAddr()

HRESULT GrayLib::cNetAddrName::UpdateHostNameFromAddr ( bool  bWait)

Find the best DNS host name for the IP address. port not effected.

  • bWait = This is a blocking call.

Member Data Documentation

◆ m_Addr

cNetAddress GrayLib::cNetAddrName::m_Addr
protected

resolved/Converted to native binary format. (NOTE: this may just be the first in a list resolved from DNS)

◆ m_sAddrName

cStringA GrayLib::cNetAddrName::m_sAddrName
protected

This can be "hostname:port" or just "hostname". use NI_MAXHOST.

Save the address name (hostname:port) that will be converted to an IP:port.

◆ m_wPortDefault

NET_PORT_t GrayLib::cNetAddrName::m_wPortDefault
protected

This default port might (need not) be in name string. m_sAddrName.


The documentation for this class was generated from the following files: