OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TINetSocketAddress Class Reference

The TINetSocketAddress class encapsulates a Winsock Internet address. More...

#include <owl/wskaddr.h>

Inheritance diagram for owl::TINetSocketAddress:
owl::TSocketAddress

Public Types

enum  TINetClass { ClassA , ClassB , ClassC , ClassUnknown }
 TINetClass is an enumeration that specifies which network class it belongs to. More...
 

Public Member Functions

 TINetSocketAddress ()
 This function constructs an object.
 
 TINetSocketAddress (const sockaddr &src)
 This function constructs an object.
 
 TINetSocketAddress (ushort newPort, ulong newAddress=INADDR_ANY, ushort newFamily=AF_INET)
 This function constructs an object.
 
 TINetSocketAddress (ushort newPort, const char *newAddress, ushort newFamily=AF_INET)
 This function constructs an object.
 
TINetSocketAddressoperator= (const sockaddr &src)
 The argument should be in the same byte ordering (network) as this object.
 
 operator sockaddr_in () const
 This function converts this address to the sockaddr_in structure.
 
TINetClass GetClass () const
 This function uses Windows Sockets macros to get standard class information.
 
ushort GetPort () const
 This function returns the port in network byte ordering.
 
ulong GetNetworkAddress () const
 This function returns an IP binary address in network byte ordering.
 
ulong GetNetwork () const
 This function returns 0 if the network cannot be determined.
 
ulong GetNetwork (ulong subnet) const
 This function returns the network ID masked with the subnet.
 
ulong GetNode () const
 This function returns the node component of the address with the subnet masked out.
 
ulong GetNode (ulong subnet) const
 This function returns the node of this address.
 
void SetAddress (ushort newFamily, ushort newPort, ulong newAddress)
 This function makes an address out of the necessary IP address components.
 
void SetPort (ushort port)
 This function sets the port of the addressing.
 
void SetNetworkAddress (ulong address)
 This function sets the network address.
 
void SetNetworkAddress (const char *addressDottedDecimal)
 This function sets the network address.
 
void SetFiller ()
 This is an internal function used to zero out the unused data of the address.
 
- Public Member Functions inherited from owl::TSocketAddress
 TSocketAddress ()
 Only the family is specified. The rest of the data is currently undefined.
 
 TSocketAddress (const sockaddr &src)
 The argument is a socket address in network byte ordering.
 
 TSocketAddress (const TSocketAddress &src)
 The argument address should be in network byte ordering.
 
 TSocketAddress (ushort family, char *data, short dataLength)
 The argument address should be in network byte ordering.
 
TSocketAddressoperator= (const sockaddr &src)
 The argument address should be in network byte ordering.
 
ushort GetFamily () const
 Returns the family of addressing this address belongs to.
 
void SetFamily (ushort family)
 Sets the family of addressing this address belongs to.
 
void SetAddress (ushort family, const char *data, short dataLength)
 'newFamily' is AF_INET, etc.
 

Static Public Member Functions

static ulong ConvertAddress (const char *address)
 This function accepts a character string IP address (for example, 162.132.211.204) and converts it to an IP address (ulong) if possible.
 
static charConvertAddress (ulong address)
 This function accepts a ulong in the form of an IP binary address and converts it to a character string IP address (for example, 123.213.132.122), if possible.
 
static short IsAddressDottedDecimal (const char *address)
 This function can be used to tell if a character string points to an address in dotted-decimal IP format (for example, 162.132.211.204) or in name format (for example, hilla.nosp@m.ry_c.nosp@m.linto.nosp@m.n@wh.nosp@m..com).
 

Detailed Description

The TINetSocketAddress class encapsulates a Winsock Internet address.

This class stores a complete Internet address, which includes an address family, a port, and a 32 bit (4 byte) IP address. The Internet address-specific information is stored in the sa_data field of the sockaddr.

Todo
What about IPv6?

Definition at line 63 of file wskaddr.h.

Member Enumeration Documentation

◆ TINetClass

TINetClass is an enumeration that specifies which network class it belongs to.

There are three network classes: class A, class B, and class C. The classes determine how many possible hosts there are on the network. Note that these classes are the same when programming Windows Sockets.

An address resolves to a 32-bit value. Each class has a different encoding scheme.

Enumerator
ClassA 

A class net addressing.

ClassB 

B class net addressing.

ClassC 

C class net addressing.

ClassUnknown 

Unknown class net addressing.

Definition at line 73 of file wskaddr.h.

Constructor & Destructor Documentation

◆ TINetSocketAddress() [1/4]

owl::TINetSocketAddress::TINetSocketAddress ( )

This function constructs an object.

It is an empty constructor. It is useful for creating a TInetSocketAddress, but delaying the actual assignment of addressing data until later.

Definition at line 94 of file wskaddr.cpp.

References SetAddress().

◆ TINetSocketAddress() [2/4]

owl::TINetSocketAddress::TINetSocketAddress ( const sockaddr & src)

This function constructs an object.

The argument should be in network byte ordering.

Definition at line 105 of file wskaddr.cpp.

◆ TINetSocketAddress() [3/4]

owl::TINetSocketAddress::TINetSocketAddress ( ushort newPort,
ulong newAddress = INADDR_ANY,
ushort newFamily = AF_INET )

This function constructs an object.

You should pass nNewPort in network byte ordering. lNewAddress is in the format for numerical IP addressing (for example, 132.212.43.1). It cannot be in the form user@place. nNewFamily is in the form AF_INET, etc.

All arguments should be in network byte ordering. newFamily is an enumeration, so there is no specific byte ordering. Note that address can also be INADDR_ANY, INADDR_LOOPBACK, INADDR_BROADCAST, INADDR_NONE. Also note that in winsock.h (1.1), Microsoft defines these addresses in network byte ordering format, so you don't need to convert to network byte ordering upon passing to this function or any other that expects network byte ordering.

Definition at line 125 of file wskaddr.cpp.

References SetAddress().

◆ TINetSocketAddress() [4/4]

owl::TINetSocketAddress::TINetSocketAddress ( ushort newPort,
const char * newAddressStr,
ushort newFamily = AF_INET )

This function constructs an object.

All arguments should be in network byte ordering. nNewFamily is an enumeration, so there is no specific byte ordering.

Note
The address can also be INADDR_ANY, INADDR_LOOPBACK, INADDR_BROADCAST, or INADDR_NONE.

Also note that in Windows Sockets, Microsoft defines these addresses using network byte ordering format. Therefore, you don't need to convert to network byte ordering upon passing to this function, or when passing to any other function that expects network byte ordering.

newPort should be passed in network byte ordering. newAddress is in the format of numerical IP addressing (e.g. "132.212.43.1"). It cannot be in the form of "user\@place" nFamily is in the form of AF_INET, etc.

Definition at line 145 of file wskaddr.cpp.

References ConvertAddress(), and SetAddress().

Member Function Documentation

◆ ConvertAddress() [1/2]

ulong owl::TINetSocketAddress::ConvertAddress ( const char * address)
static

This function accepts a character string IP address (for example, 162.132.211.204) and converts it to an IP address (ulong) if possible.

The returned value is in network byte ordering. It should be INADDR_NONE if there was an error.

Definition at line 166 of file wskaddr.cpp.

References owl::TWinSockDll::inet_addr().

◆ ConvertAddress() [2/2]

char * owl::TINetSocketAddress::ConvertAddress ( ulong address)
static

This function accepts a ulong in the form of an IP binary address and converts it to a character string IP address (for example, 123.213.132.122), if possible.

The lAddress parameter must be given in network byte ordering to work properly. Note that this function returns a character pointer to a string allocated by the system. The caller must immediately copy this data, and cannot modify or deallocate it. This restriction is imposed by Windows Sockets.

Definition at line 179 of file wskaddr.cpp.

References owl::TWinSockDll::inet_ntoa().

◆ GetClass()

TINetSocketAddress::TINetClass owl::TINetSocketAddress::GetClass ( ) const

This function uses Windows Sockets macros to get standard class information.

It does not know about subnetting or any classes beyond class C.

Definition at line 333 of file wskaddr.cpp.

References ClassA, ClassB, ClassC, ClassUnknown, and GetNetworkAddress().

◆ GetNetwork() [1/2]

ulong owl::TINetSocketAddress::GetNetwork ( ) const

This function returns 0 if the network cannot be determined.

Definition at line 252 of file wskaddr.cpp.

References ClassA, ClassB, ClassC, GetClass(), and GetNetwork().

◆ GetNetwork() [2/2]

ulong owl::TINetSocketAddress::GetNetwork ( ulong subnet) const
inline

This function returns the network ID masked with the subnet.

Definition at line 145 of file wskaddr.h.

References GetNetworkAddress().

◆ GetNetworkAddress()

ulong owl::TINetSocketAddress::GetNetworkAddress ( ) const

This function returns an IP binary address in network byte ordering.

Definition at line 242 of file wskaddr.cpp.

◆ GetNode() [1/2]

ulong owl::TINetSocketAddress::GetNode ( ) const

This function returns the node component of the address with the subnet masked out.

Definition at line 275 of file wskaddr.cpp.

References ClassA, ClassB, ClassC, GetClass(), and GetNode().

◆ GetNode() [2/2]

ulong owl::TINetSocketAddress::GetNode ( ulong subnet) const
inline

This function returns the node of this address.

Definition at line 154 of file wskaddr.h.

References GetNetworkAddress().

◆ GetPort()

ushort owl::TINetSocketAddress::GetPort ( ) const

This function returns the port in network byte ordering.

Definition at line 234 of file wskaddr.cpp.

◆ IsAddressDottedDecimal()

short owl::TINetSocketAddress::IsAddressDottedDecimal ( const char * addressStr)
static

This function can be used to tell if a character string points to an address in dotted-decimal IP format (for example, 162.132.211.204) or in name format (for example, hilla.nosp@m.ry_c.nosp@m.linto.nosp@m.n@wh.nosp@m..com).

You could call this function if the user typed in a destination address in one of either of the above formats and you need to know which one it is, so you can convert it to a ulong IP address. If the address is dotted-decimal, you can simply use the TINetSocketAddress::ConvertAddress() function. Otherwise, you need to use one of the HostInfoManager functions. The szAddress is a pointer to a string that can be in any format, but most likely, one of either the dotted-decimal or the name formats mentioned above. This function's job is only to tell you if it is in dotted-decimal format or not. The return value is 1 if in dotted-decimal format, and 0 if not.

Definition at line 206 of file wskaddr.cpp.

References owl::TWinSockDll::inet_addr().

◆ operator sockaddr_in()

owl::TINetSocketAddress::operator sockaddr_in ( ) const
inline

This function converts this address to the sockaddr_in structure.

Definition at line 136 of file wskaddr.h.

◆ operator=()

TINetSocketAddress & owl::TINetSocketAddress::operator= ( const sockaddr & src)

The argument should be in the same byte ordering (network) as this object.

Definition at line 154 of file wskaddr.cpp.

References owl::TSocketAddress::SetAddress().

◆ SetAddress()

void owl::TINetSocketAddress::SetAddress ( ushort newFamily,
ushort newPort,
ulong newAddress )

This function makes an address out of the necessary IP address components.

nNewFamily is an enumeration, for example, AF_INET. nNewPort is in network byte ordering, as is lNewAddress.

Definition at line 222 of file wskaddr.cpp.

References owl::TSocketAddress::SetFamily(), SetFiller(), SetNetworkAddress(), and SetPort().

◆ SetFiller()

void owl::TINetSocketAddress::SetFiller ( )

This is an internal function used to zero out the unused data of the address.

Definition at line 321 of file wskaddr.cpp.

◆ SetNetworkAddress() [1/2]

void owl::TINetSocketAddress::SetNetworkAddress ( const char * addressDottedDecimal)

This function sets the network address.

Definition at line 313 of file wskaddr.cpp.

References ConvertAddress(), and SetNetworkAddress().

◆ SetNetworkAddress() [2/2]

void owl::TINetSocketAddress::SetNetworkAddress ( ulong address)

This function sets the network address.

It expects the argument to be in network byte ordering.

Definition at line 305 of file wskaddr.cpp.

◆ SetPort()

void owl::TINetSocketAddress::SetPort ( ushort port)

This function sets the port of the addressing.

It expects the argument to be in network byte ordering.

Definition at line 296 of file wskaddr.cpp.


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