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

#include <cNetAddr.h>

Public Member Functions

 cNetAddress () noexcept
 
 cNetAddress (sa_family_t nFamily, NET_PORT_t wPort=k_NET_PORT_INVALID) noexcept
 
 cNetAddress (in_addr ip, NET_PORT_t wPort=k_NET_PORT_INVALID) noexcept
 
 cNetAddress (const char *pszAddr, bool bWait=false)
 
 cNetAddress (const char *pszAddr, NET_PORT_t wPortDefault, bool bWait=false)
 
sa_family_t get_Family () const noexcept
 
socklen_t get_AddrLen () const noexcept
 
socklen_t & ref_AddrLen () noexcept
 
const sockaddr & get_Addr () const noexcept
 
const sockaddr & ref_Addr () const noexcept
 
sockaddr & ref_Addr () noexcept
 
bool isAddrValid () const
 
void ResetAddr () noexcept
 
COMPARE_t CompareAddr (const cNetAddress &SocketAddr) const
 
bool operator== (const cNetAddress &SocketAddr) const
 
bool operator!= (const cNetAddress &SocketAddr) const
 
HASHCODE_t get_HashCodeHost () const noexcept
 
HASHCODE_t get_HashCode () const noexcept
 
NET_PORT_t get_PortNumber () const noexcept
 
void put_PortNumber (NET_PORT_t wPort)
 
bool isPortValid () const
 
bool put_PortServiceName (const char *pszPortServiceName)
 
cStringA get_PortServiceName () const
 
const BYTE * get_HostPtr () const
 
BYTE * ref_HostPtr () const
 
size_t get_HostLen () const
 
bool isHostLoopback () const
 
bool isHostPrivate () const
 
bool put_HostLoopback (sa_family_t nFamily=AF_UNSPEC)
 
COMPARE_t CompareHost (const cNetAddress &SocketAddr) const
 
HRESULT SetHostStr (const char *pszHost, bool bWait=false)
 
HRESULT SetHostStrFix (const char *pszAddr, bool bWait=false)
 
cStringA get_HostStr () const
 
cNetHost4 get_HostIp4 () const
 
void put_HostIp4 (in_addr nIP)
 
cNetHost6 get_HostIp6 () const
 
void put_HostIp6 (const in6_addr &addr)
 
bool SetHostData (sa_family_t nFamily, const void *pHostData, size_t nDataSize=sizeof(in_addr))
 
void ResetHost ()
 
void put_Addr (const cNetAddress &rAddr)
 
bool SetAddrData (const sockaddr *pSockAddr, socklen_t nSockAddrLen)
 
cStringA get_AddrStr () const
 
HRESULT put_AddrStr (const char *pszAddr, bool bWait=false)
 
HRESULT SerializeOutput (cStreamOutput &rout)
 
HRESULT SerializeInput (cStreamInput &file)
 
 UNITTEST_FRIEND (cNetAddress)
 

Static Public Member Functions

static char *GRAYCALL FindPortExtPtr (const char *pszAddr)
 

Protected Member Functions

const in_addr & ref_HostIp4 () const
 
in_addr & ref_HostIp4 ()
 
const in6_addr & ref_HostIp6 () const
 
in6_addr & ref_HostIp6 ()
 

Detailed Description

Network Address = (Family + Host + Port) in generic format. Handles an address in any network family: IPv4/AF_INET or IPv6/AF_INET6 or other Similar to MFC CSocketAddr Based on SOCKADDR,SOCKADDR_IN,sockaddr,sockaddr_in

Constructor & Destructor Documentation

◆ cNetAddress() [1/5]

GrayLib::cNetAddress::cNetAddress ( )
inlinenoexcept

sin_family = AF_UNSPEC; // AF_INET, AF_INET6, etc sin_port = k_NET_PORT_INVALID; sin_addr.s_addr = INADDR_NONE;

◆ cNetAddress() [2/5]

GrayLib::cNetAddress::cNetAddress ( sa_family_t  nFamily,
NET_PORT_t  wPort = k_NET_PORT_INVALID 
)
inlinenoexcept

Default to a local/loopback connection

  • nFamily = AF_INET
  • wPort = k_NET_PORT_INVALID (any port)

◆ cNetAddress() [3/5]

GrayLib::cNetAddress::cNetAddress ( in_addr  ip,
NET_PORT_t  wPort = k_NET_PORT_INVALID 
)
inlinenoexcept

IPv4

  • ip = INADDR_ANY

◆ cNetAddress() [4/5]

GrayLib::cNetAddress::cNetAddress ( const char *  pszAddr,
bool  bWait = false 
)
inline

Set the address by string.

  • bWait = wait for asynchronous name DNS resolve (if needed)

◆ cNetAddress() [5/5]

GrayLib::cNetAddress::cNetAddress ( const char *  pszAddr,
NET_PORT_t  wPortDefault,
bool  bWait = false 
)
inline

Set the address by string. + default port. string overrides the port.

  • bWait = wait for asynchronous name DNS resolve (if needed)

Member Function Documentation

◆ CompareAddr()

COMPARE_t GrayLib::cNetAddress::CompareAddr ( const cNetAddress SocketAddr) const
inline
Note
This includes the port. not just the machine node address.

◆ CompareHost()

COMPARE_t GrayLib::cNetAddress::CompareHost ( const cNetAddress SocketAddr) const

Just compare hosts. ignore ports. Might use get_HashCodeHost ??

◆ FindPortExtPtr()

char * GrayLib::cNetAddress::FindPortExtPtr ( const char *  pszAddr)
static

Get the separator for the address and the port.

Note
IPv6 doesn't use : port the same as IPv4
Returns
nullptr if no port. else a pointer to the ':'

◆ get_Addr()

const sockaddr& GrayLib::cNetAddress::get_Addr ( ) const
inlinenoexcept

get pointer to the low level SOCKADDR structure.

◆ get_AddrLen()

socklen_t GrayLib::cNetAddress::get_AddrLen ( ) const
inlinenoexcept

How much of the address is used? or what is the max size allowed to be used.

◆ get_AddrStr()

cStringA GrayLib::cNetAddress::get_AddrStr ( ) const

get Address as a string = "host:port" IP4 = "HTTP://1.2.3.4:80/" IP6 = "HTTP://[2001:0f68:0000:0000:0000:0000:1986:69af]:80/"

◆ get_Family()

sa_family_t GrayLib::cNetAddress::get_Family ( ) const
inlinenoexcept

AF_UNSPEC, AF_INET, AF_INET6, etc

◆ get_HashCode()

HASHCODE_t GrayLib::cNetAddress::get_HashCode ( ) const
inlinenoexcept

◆ get_HashCodeHost()

HASHCODE_t GrayLib::cNetAddress::get_HashCodeHost ( ) const
noexcept

Get a hash code for the host ip address alone. not including port number. cNetHost4, cNetHost6

◆ get_HostIp4()

cNetHost4 GrayLib::cNetAddress::get_HostIp4 ( ) const

◆ get_HostIp6()

cNetHost6 GrayLib::cNetAddress::get_HostIp6 ( ) const

Network order bytes.

◆ get_HostLen()

size_t GrayLib::cNetAddress::get_HostLen ( ) const
inline

Does not include port.

◆ get_HostPtr()

const BYTE* GrayLib::cNetAddress::get_HostPtr ( ) const
inline

Does not include port.

◆ get_HostStr()

cStringA GrayLib::cNetAddress::get_HostStr ( ) const
Returns
the host name, not the port

◆ get_PortNumber()

NET_PORT_t GrayLib::cNetAddress::get_PortNumber ( ) const
inlinenoexcept

Ports have 3 ranges, 1.defined, 2.private, 3.temporary.

Returns
0 = undefined. k_NET_PORT_INVALID
Note
SS_PORT(ssp) works in both ip6 and ip4 ASSUME all sa_family_t support ports. not just AF_INET.

◆ get_PortServiceName()

cStringA GrayLib::cNetAddress::get_PortServiceName ( ) const

◆ isAddrValid()

bool GrayLib::cNetAddress::isAddrValid ( ) const

Is this host address valid?

Note
0 port is OK since it just means bind to arbitrary free port.

◆ isHostLoopback()

bool GrayLib::cNetAddress::isHostLoopback ( ) const

Is this just a loopback to myself?

◆ isHostPrivate()

bool GrayLib::cNetAddress::isHostPrivate ( ) const

Is this address a private LAN address (intra-net) vs. public Internet address ?

◆ isPortValid()

bool GrayLib::cNetAddress::isPortValid ( ) const
inline

ASSUME all sa_family_t support ports. not just AF_INET.

◆ operator!=()

bool GrayLib::cNetAddress::operator!= ( const cNetAddress SocketAddr) const
inline

◆ operator==()

bool GrayLib::cNetAddress::operator== ( const cNetAddress SocketAddr) const
inline

◆ put_Addr()

void GrayLib::cNetAddress::put_Addr ( const cNetAddress rAddr)
inline

◆ put_AddrStr()

HRESULT GrayLib::cNetAddress::put_AddrStr ( const char *  pszAddr,
bool  bWait = false 
)

Set address and port together from a string. leave port if not provided in string.

◆ put_HostIp4()

void GrayLib::cNetAddress::put_HostIp4 ( in_addr  nIP)
inline

Just set host. Leave port unset.

◆ put_HostIp6()

void GrayLib::cNetAddress::put_HostIp6 ( const in6_addr &  addr)
inline

Just set host. Leave port unset.

◆ put_HostLoopback()

bool GrayLib::cNetAddress::put_HostLoopback ( sa_family_t  nFamily = AF_UNSPEC)

Set to local loop-back Address. Leave Port.

  • nFamily = AF_UNSPEC = use the current family. Leave port.

◆ put_PortNumber()

void GrayLib::cNetAddress::put_PortNumber ( NET_PORT_t  wPort)
inline

ASSUME all sa_family_t support ports.

Returns
0 = undefined. k_NET_PORT_INVALID

◆ put_PortServiceName()

bool GrayLib::cNetAddress::put_PortServiceName ( const char *  pszPortServiceName)

find the service name as the port number. (e.g. pszPort = "http","ftp",etc)

◆ ref_Addr() [1/2]

const sockaddr& GrayLib::cNetAddress::ref_Addr ( ) const
inlinenoexcept

get const ref to the low level SOCKADDR structure. supports Windows vs. Unix prototype differences.

◆ ref_Addr() [2/2]

sockaddr& GrayLib::cNetAddress::ref_Addr ( )
inlinenoexcept

get ref to the low level SOCKADDR structure.

◆ ref_AddrLen()

socklen_t& GrayLib::cNetAddress::ref_AddrLen ( )
inlinenoexcept

Berkley sockets functions can set the size this way.

◆ ref_HostIp4() [1/2]

in_addr& GrayLib::cNetAddress::ref_HostIp4 ( )
inlineprotected

◆ ref_HostIp4() [2/2]

const in_addr& GrayLib::cNetAddress::ref_HostIp4 ( ) const
inlineprotected

◆ ref_HostIp6() [1/2]

in6_addr& GrayLib::cNetAddress::ref_HostIp6 ( )
inlineprotected

◆ ref_HostIp6() [2/2]

const in6_addr& GrayLib::cNetAddress::ref_HostIp6 ( ) const
inlineprotected

◆ ref_HostPtr()

BYTE* GrayLib::cNetAddress::ref_HostPtr ( ) const
inline

Does not include port.

◆ ResetAddr()

void GrayLib::cNetAddress::ResetAddr ( )
inlinenoexcept

◆ ResetHost()

void GrayLib::cNetAddress::ResetHost ( )
inline

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

◆ SerializeInput()

HRESULT GrayLib::cNetAddress::SerializeInput ( cStreamInput file)

◆ SerializeOutput()

HRESULT GrayLib::cNetAddress::SerializeOutput ( cStreamOutput rout)

◆ SetAddrData()

bool GrayLib::cNetAddress::SetAddrData ( const sockaddr *  pSockAddr,
socklen_t  nSockAddrLen 
)

set sockaddr directly. usually coming from some sort of hostname resolution. Similar to SetHostData. but from addrinfo May set port or leave it alone. like SetHostData() nSockAddrLen = sizeof(sockaddr)

◆ SetHostData()

bool GrayLib::cNetAddress::SetHostData ( sa_family_t  nFamily,
const void *  pHostData,
size_t  nDataSize = sizeof(in_addr) 
)

set sockaddr directly. Set host address. NOT set port. like SetAddrData()

  • nDataSize = 4 for AF_INET/IPv4

◆ SetHostStr()

HRESULT GrayLib::cNetAddress::SetHostStr ( const char *  pszHost,
bool  bWait = false 
)

Set just the host. ASSUME NO :Port is here. resolve native address without blocking. Must block to lookup hostname.

  • bWait = wait for asynchronous name DNS resolve (if needed)

◆ SetHostStrFix()

HRESULT GrayLib::cNetAddress::SetHostStrFix ( const char *  pszAddr,
bool  bWait = false 
)

Strip the port from the address name.

◆ UNITTEST_FRIEND()

GrayLib::cNetAddress::UNITTEST_FRIEND ( cNetAddress  )

Member Data Documentation

◆ m_SockAddr

sockaddr GrayLib::cNetAddress::m_SockAddr

Address that is family independent. (interchangeable with sockaddr/SOCKADDR/SOCKADDR_IN. NO Port)

◆ m_SockAddr4

sockaddr_in GrayLib::cNetAddress::m_SockAddr4

Address is ipv4 = 16 bytes.

◆ m_SockAddr6

sockaddr_in6 GrayLib::cNetAddress::m_SockAddr6

Address is ipv6 = 28 bytes.


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