Evo C++ Library v0.5.1
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
SocketAddressIp Struct Reference

#include <evo/iosock.h>

Inheritance diagram for SocketAddressIp:
Inheritance graph
[legend]

Detailed Description

TCP/IP socket address.

Public Member Functions

 SocketAddressIp ()
 Default constructor sets as empty/invalid. More...
 
 SocketAddressIp (const SocketAddressIp &src)
 Copy constructor. More...
 
 SocketAddressIp (struct sockaddr_in *ptr)
 Constructor to copy from an IPv4 address. More...
 
 SocketAddressIp (struct sockaddr_in6 *ptr)
 Constructor to copy from an IPv6 address. More...
 
 SocketAddressIp (ushort port, bool ip6=false)
 Constructor for wildcard address. More...
 
 SocketAddressIp (struct addrinfo *ptr)
 Constructor to copy from addrinfo structure. More...
 
 SocketAddressIp (struct sockaddr *ptr)
 Constructor to copy IP address from sockaddr structure. More...
 
SocketAddressIp & clear ()
 Clear current address. More...
 
bool format (String &str) const
 Format IP address to given string (appended). More...
 
bool parse (const SubString &str, ushort port=0, int family=AF_UNSPEC)
 
SocketAddressIp & set (const SocketAddressIp &src)
 Set as copy of IP address. More...
 
SocketAddressIp & set (struct sockaddr_in *ptr)
 Set as copy of an IPv4 address. More...
 
SocketAddressIp & set (struct sockaddr_in6 *ptr)
 Set as copy of an IPv6 address. More...
 
SocketAddressIp & set (struct addrinfo *ptr)
 Set to address from addrinfo structure. More...
 
void set_maxsize ()
 Set addrlen to max size for socket address. More...
 
SocketAddressIp & setany4 (ushort port=0)
 Set as wildcard IPv4 address. More...
 
SocketAddressIp & setany6 (ushort port=0)
 Set as wildcard IPv6 address. More...
 
SocketAddressIp & setport (ushort port)
 Set port on current address. More...
 
bool valid () const
 Get whether valid. More...
 

Static Public Member Functions

static bool check (struct sockaddr *addr)
 Check if address struct holds a supported IP address type. More...
 
static bool format_addr (String &str, const SocketAddressBase *address)
 Format IP address to given string (appended). More...
 

Public Attributes

union {
   struct sockaddr   addr
 Generic address structure. More...
 
   struct sockaddr_in   addr_ip4
 IPv4 address structure (union with addr) More...
 
   struct sockaddr_in6   addr_ip6
 IPv6 address structure (union with addr) More...
 
}; 
 
socklen_t addrlen
 Address length. More...
 

Static Public Attributes

static const uint MAX_INET4_STRLEN = 22
 Max IPv4 string length with port num + terminator. More...
 
static const uint MAX_INET6_STRLEN = 65
 Max IPv6 string length with IPv4 tunneling, brackets, zone/scope ID, and port num + terminator. More...
 
static const socklen_t MAX_SIZE = sizeof(sockaddr_in6)
 Max socket address size used here. More...
 

Constructor & Destructor Documentation

◆ SocketAddressIp() [1/7]

SocketAddressIp ( )
inline

Default constructor sets as empty/invalid.

◆ SocketAddressIp() [2/7]

SocketAddressIp ( const SocketAddressIp &  src)
inline

Copy constructor.

Parameters
srcSource IP address to copy

◆ SocketAddressIp() [3/7]

SocketAddressIp ( struct sockaddr_in *  ptr)
inline

Constructor to copy from an IPv4 address.

Parameters
ptrIP address pointer

◆ SocketAddressIp() [4/7]

SocketAddressIp ( struct sockaddr_in6 *  ptr)
inline

Constructor to copy from an IPv6 address.

Parameters
ptrIP address pointer

◆ SocketAddressIp() [5/7]

SocketAddressIp ( ushort  port,
bool  ip6 = false 
)
inline

Constructor for wildcard address.

Parameters
portPort number
ip6Whether to use IPv6, false for IPv4

◆ SocketAddressIp() [6/7]

SocketAddressIp ( struct addrinfo *  ptr)
inline

Constructor to copy from addrinfo structure.

Parameters
ptrAddress info pointer to get IP address

◆ SocketAddressIp() [7/7]

SocketAddressIp ( struct sockaddr *  ptr)
inline

Constructor to copy IP address from sockaddr structure.

  • This is set to null if ptr isn't a valid and supported IP address
Parameters
ptrAddress pointer to get IP address

Member Function Documentation

◆ check()

static bool check ( struct sockaddr *  addr)
inlinestatic

Check if address struct holds a supported IP address type.

Parameters
addrAddress pointer, NULL for none
Returns
Whether addr is valid and is a supported IP address type

◆ clear()

SocketAddressIp& clear ( )
inline

Clear current address.

Returns
This

◆ format()

bool format ( String &  str) const
inline

Format IP address to given string (appended).

Parameters
strString to format to, unchanged if IP not valid
Returns
Whether successful, false if IP not valid

◆ format_addr()

static bool format_addr ( String &  str,
const SocketAddressBase *  address 
)
inlinestatic

Format IP address to given string (appended).

Parameters
strString to format to, unchanged if IP not valid
addressAddress to format
Returns
Whether successful, false if not a valid IP address

◆ parse()

bool parse ( const SubString &  str,
ushort  port = 0,
int  family = AF_UNSPEC 
)
inline

◆ set() [1/4]

SocketAddressIp& set ( const SocketAddressIp &  src)
inline

Set as copy of IP address.

Parameters
srcSource IP address to copy
Returns
This

◆ set() [2/4]

SocketAddressIp& set ( struct sockaddr_in *  ptr)
inline

Set as copy of an IPv4 address.

Parameters
ptrIP address pointer
Returns
This

◆ set() [3/4]

SocketAddressIp& set ( struct sockaddr_in6 *  ptr)
inline

Set as copy of an IPv6 address.

Parameters
ptrIP address pointer
Returns
This

◆ set() [4/4]

SocketAddressIp& set ( struct addrinfo *  ptr)
inline

Set to address from addrinfo structure.

Parameters
ptrAddress info pointer to get IP address
Returns
This

◆ set_maxsize()

void set_maxsize ( )
inlinevirtual

Set addrlen to max size for socket address.

  • Low-level socket functions that store a socket address need to know the max socket address length
  • Derived class must implement this and set the proper max size

Reimplemented from SocketAddressBase.

◆ setany4()

SocketAddressIp& setany4 ( ushort  port = 0)
inline

Set as wildcard IPv4 address.

Parameters
portPort number
Returns
This

◆ setany6()

SocketAddressIp& setany6 ( ushort  port = 0)
inline

Set as wildcard IPv6 address.

Parameters
portPort number
Returns
This

◆ setport()

SocketAddressIp& setport ( ushort  port)
inline

Set port on current address.

  • This is ignored if no address is set
Parameters
portPort number
Returns
This

◆ valid()

bool valid ( ) const
inline

Get whether valid.

Returns
Whether valid

Member Data Documentation

◆ @1

union { ... }

◆ addr

struct sockaddr addr

Generic address structure.

◆ addr_ip4

struct sockaddr_in addr_ip4

IPv4 address structure (union with addr)

◆ addr_ip6

struct sockaddr_in6 addr_ip6

IPv6 address structure (union with addr)

◆ addrlen

socklen_t addrlen
inherited

Address length.

◆ MAX_INET4_STRLEN

const uint MAX_INET4_STRLEN = 22
static

Max IPv4 string length with port num + terminator.

◆ MAX_INET6_STRLEN

const uint MAX_INET6_STRLEN = 65
static

Max IPv6 string length with IPv4 tunneling, brackets, zone/scope ID, and port num + terminator.

◆ MAX_SIZE

const socklen_t MAX_SIZE = sizeof(sockaddr_in6)
static

Max socket address size used here.


The documentation for this struct was generated from the following file: