OWLNext 7.0
Borland's Object Windows Library for the modern age
|
The TINetSocketAddress class encapsulates a Winsock Internet address. More...
#include <owl/wskaddr.h>
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. | |
TINetSocketAddress & | operator= (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. | |
TSocketAddress & | operator= (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 char * | ConvertAddress (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). | |
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.
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. |
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().
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.
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().
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.
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().
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().
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().
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().
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().
This function returns the network ID masked with the subnet.
Definition at line 145 of file wskaddr.h.
References 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.
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().
This function returns the node of this address.
Definition at line 154 of file wskaddr.h.
References GetNetworkAddress().
ushort owl::TINetSocketAddress::GetPort | ( | ) | const |
This function returns the port in network byte ordering.
Definition at line 234 of file wskaddr.cpp.
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().
|
inline |
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().
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().
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.
This function sets the network address.
Definition at line 313 of file wskaddr.cpp.
References ConvertAddress(), and SetNetworkAddress().
This function sets the network address.
It expects the argument to be in network byte ordering.
Definition at line 305 of file wskaddr.cpp.
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.