Nebula
Loading...
Searching...
No Matches
Win32::Win32IpAddress Class Reference

#include <win32ipaddress.h>

Detailed Description

Represents an IP address, consisting of a IPv4 host address and a port number.

Performs automatic name lookup on the host name. Can extract address information from an URI and
automatically converts host names to addresses, and offers the special hostnames "localhost", "any", "broadcast", "self" and "inetself" where:

  • "localhost" will translate to 127.0.0.1
  • "any" will translate to INADDR_ANY, which is 0.0.0.0
  • "broadcast" will translate to INADDR_BROADCAST, which is 255.255.255.255
  • "self" will translate to the first valid tcp/ip address for this host (there may be more then one address bound to the host)
  • "inetself" will translate to the first host address which is not a LAN address (which is not a class A, B, or C network) if none such exists the address will fall back to "self"

Public Member Functions

 Win32IpAddress ()
 default constructor
 
 Win32IpAddress (const Win32IpAddress &rhs)
 copy constructor
 
 Win32IpAddress (const IO::URI &uri)
 construct from URI
 
 Win32IpAddress (const Util::String &hostName, ushort portNumber)
 construct from host name and port number
 
bool operator== (const Win32IpAddress &rhs) const
 equality operator
 
bool operator< (const Win32IpAddress &rhs) const
 less-then operator
 
bool operator> (const Win32IpAddress &rhs) const
 greater-then operator
 
void ExtractFromUri (const IO::URI &uri)
 extract host name and port number from URI
 
void SetHostName (const Util::String &hostName)
 set host name
 
const Util::StringGetHostName () const
 get host name
 
void SetPort (ushort port)
 set port number
 
ushort GetPort () const
 get port number
 
const Util::StringGetHostAddr () const
 get the ip address resulting from the host name as string
 

Private Member Functions

 Win32IpAddress (const sockaddr_in &addr)
 construct from sockaddr_in struct
 
void SetSockAddr (const sockaddr_in &addr)
 set sockaddr_in directly
 
const sockaddr_in & GetSockAddr () const
 get sockaddr_in field
 

Static Private Member Functions

static bool GetHostByName (const Util::String &hostName, in_addr &outAddr)
 perform address resolution, understands special host names
 
static bool IsInetAddr (const in_addr *addr)
 return true if an address is an internet address (not class A,B,C)
 

Private Attributes

Util::String hostName
 
Util::String addrAsString
 
sockaddr_in addr
 

Friends

class Win32Socket
 

Constructor & Destructor Documentation

◆ Win32IpAddress() [1/5]

Win32::Win32IpAddress::Win32IpAddress ( )

default constructor

◆ Win32IpAddress() [2/5]

Win32::Win32IpAddress::Win32IpAddress ( const Win32IpAddress & rhs)

copy constructor

◆ Win32IpAddress() [3/5]

Win32::Win32IpAddress::Win32IpAddress ( const IO::URI & uri)

construct from URI

◆ Win32IpAddress() [4/5]

Win32::Win32IpAddress::Win32IpAddress ( const Util::String & hostName,
ushort portNumber )

construct from host name and port number

◆ Win32IpAddress() [5/5]

Win32::Win32IpAddress::Win32IpAddress ( const sockaddr_in & addr)
private

construct from sockaddr_in struct

Member Function Documentation

◆ ExtractFromUri()

void Win32::Win32IpAddress::ExtractFromUri ( const IO::URI & uri)

extract host name and port number from URI

Extract the host name and optionally the port number from the provided URI.

If no port number is set in the URI, the current port number will be left as is. If the host name is empty, it will be set to "localhost".

◆ GetHostAddr()

const String & Win32::Win32IpAddress::GetHostAddr ( ) const

get the ip address resulting from the host name as string

Return the in address as string.

◆ GetHostByName()

bool Win32::Win32IpAddress::GetHostByName ( const Util::String & hostName,
in_addr & outAddr )
staticprivate

perform address resolution, understands special host names

This resolves a host name into a IPv4 ip address.

The ip address is returned in network byte order in the hostAddress argument. The return value indicates whether the operation was successful. The following special hostnames can be defined:

  • "any" resolves to INADDR_ANY (0.0.0.0)
  • "broadcast" resolves to INADDR_BROADCAST (255.255.255.255)
  • "localhost" resolves to 127.0.0.1
  • "self" resolves to the first address of this host
  • "inetself" resolves to the first address which is not a LAN address

An empty host name is invalid. A hostname can also be an address string of the form xxx.yyy.zzz.www.

NOTE: resolving host names and host addresses is not supported on the Xbox360, this basically means that an Xbox360 devkit can function as a server, but not as a client (this is fine for most debugging purposes).

◆ GetHostName()

const String & Win32::Win32IpAddress::GetHostName ( ) const

get host name

Get the host name.

◆ GetPort()

ushort Win32::Win32IpAddress::GetPort ( ) const

get port number

Get the port number in host byte order.

◆ GetSockAddr()

const sockaddr_in & Win32::Win32IpAddress::GetSockAddr ( ) const
private

get sockaddr_in field

Get the sockaddr_in struct, which has either been set directly with SetSockAddr() or indirectly through host name, port number or from an URI.

◆ IsInetAddr()

bool Win32::Win32IpAddress::IsInetAddr ( const in_addr * addr)
staticprivate

return true if an address is an internet address (not class A,B,C)

This method checks if the provided address is an "internet" address, not a LAN address (not a class A, B or C network address).

◆ operator<()

bool Win32::Win32IpAddress::operator< ( const Win32IpAddress & rhs) const
inline

less-then operator

◆ operator==()

bool Win32::Win32IpAddress::operator== ( const Win32IpAddress & rhs) const
inline

equality operator

◆ operator>()

bool Win32::Win32IpAddress::operator> ( const Win32IpAddress & rhs) const
inline

greater-then operator

◆ SetHostName()

void Win32::Win32IpAddress::SetHostName ( const Util::String & hostName)

set host name

Set the host name, and immediately convert it to an ip address.

This accepts the special hostnames "any", "broadcast", "localhost", "self" and "inetself". The result ip address can be returned in string form with the method GetAddrAsString().

◆ SetPort()

void Win32::Win32IpAddress::SetPort ( ushort port)

set port number

Set the port number.

Will be translated to network byte order internally.

◆ SetSockAddr()

void Win32::Win32IpAddress::SetSockAddr ( const sockaddr_in & sa)
private

set sockaddr_in directly

Set the address directly from a sockaddr_in struct.

This will set the host name to the string representation of the host address.

Friends And Related Symbol Documentation

◆ Win32Socket

friend class Win32Socket
friend

Member Data Documentation

◆ addr

sockaddr_in Win32::Win32IpAddress::addr
private

◆ addrAsString

Util::String Win32::Win32IpAddress::addrAsString
private

◆ hostName

Util::String Win32::Win32IpAddress::hostName
private

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