ip_address
|
 |
A TCP/IP host has one IP address
for each of its network connections. If a host is connected to more than one
network, the host is designated as multihomed. An IP address is stored as a
32-bit number and is often displayed as four one-byte numbers. When displayed in
text form, IP addresses are usually displayed as four numbers separated by
periods.
An os_ip_address
can be constructed from either a text name or its numeric equivalent. The
operator in_addr() allows an os_ip_address
to be used whenever an in_addr is expected.
Declaration
#include <ospace/network/ipaddr.h>
class os_ip_address
Interface
Constructor
os_ip_address(
unsigned long code )
Constructs
an address that has the encoded IP value code
(default INADDR_ANY ).
Constructor
os_ip_address(
const in_addr& address )
Constructs
an address that has the encoded IP address address
.
Constructor
os_ip_address(
const os_ip_address& address )
Constructs
an address with the same value as address .
Constructor
os_ip_address(
const string& address )
Constructs
an address that has the IP address described by address
. If address does not contain characters other
than ( .0123456789 ), the IP address is assumed
to have the format "ddd.ddd.ddd.ddd
", where ddd is the text form of a
one-byte number, otherwise the IP address is interpreted as the name of a
host. See os_host for more information.
Throws: os_network_toolkit_error
<
bool
operator<( const os_ip_address& address
) const
Returns
true if this address is less than address
.
=
os_ip_address&
operator=( const in_addr& address )
Assigns
this address the value address .
=
os_ip_address&
operator=( const os_ip_address& address
)
Assigns
this address the value address .
==
bool
operator==( const os_ip_address& address
) const
Returns
true if this address is the same as address
.
(in_addr)
operator
in_addr() const
Returns
an in_addr structure.
as_long
unsigned
long as_long() const
Returns
the encoded IP address.
class_type
char
class_type() const
If this address is an A,
B, C, or D class address, returns the
corresponding uppercase letter; otherwise, returns a space character.
defined
bool
defined() const
Returns
true if the encoded value is not zero.
local
bool
local() const
Returns
true if this address represents the local host.
my_address
/*
static */ const os_ip_address& my_address()
Returns
the IP address of host.
Throws: os_network_toolkit_error
print
void
print( ostream& stream )
const
Prints
the IP address to stream .
set_from_long
void
set_from_long( unsigned long code )
Sets
the address from the encoded IP address code .
set_from_numeric
void
set_from_numeric( const string& str )
Sets
the IP address from str , which should be in the
format "ddd.ddd.ddd.ddd", where ddd
is the text form of a one-byte number.
Throws: os_network_toolkit_error
set_from_symbolic
void
set_from_symbolic( const string& host_name
)
Sets
this IP address to the IP address of the host host_name
.
Throws: os_network_toolkit_error
Non-Member Functions
<<
ostream&
operator<<( ostream& stream ,
const os_ip_address& address )
Prints address
to stream .
Universal Streaming Service
#include <ospace/uss/network.h>
<<
os_bstream&
operator<<( os_bstream& stream ,
const os_ip_address& address )
Writes address
to stream .
>>
os_bstream&
operator>>( os_bstream& stream ,
os_ip_address& address )
Reads address
from stream .
Copyright©1994-2026 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.