A Discrete-Event Network Simulator
API
ns3::Ipv4Address Class Reference

Ipv4 addresses are stored in host order in this class. More...

#include "ipv4-address.h"

+ Collaboration diagram for ns3::Ipv4Address:

Public Member Functions

 Ipv4Address ()
 
 Ipv4Address (char const *address)
 Constructs an Ipv4Address by parsing a the input C-string. More...
 
 Ipv4Address (uint32_t address)
 input address is in host order. More...
 
Ipv4Address CombineMask (Ipv4Mask const &mask) const
 Combine this address with a network mask. More...
 
uint32_t Get (void) const
 Get the host-order 32-bit IP address. More...
 
Ipv4Address GetSubnetDirectedBroadcast (Ipv4Mask const &mask) const
 Generate subnet-directed broadcast address corresponding to mask. More...
 
bool IsAny (void) const
 
bool IsBroadcast (void) const
 
bool IsInitialized (void) const
 
bool IsLocalhost (void) const
 
bool IsLocalMulticast (void) const
 
bool IsMulticast (void) const
 
bool IsSubnetDirectedBroadcast (Ipv4Mask const &mask) const
 Generate subnet-directed broadcast address corresponding to mask. More...
 
 operator Address () const
 Convert an instance of this class to a polymorphic Address instance. More...
 
void Print (std::ostream &os) const
 Print this address to the given output stream. More...
 
void Serialize (uint8_t buf[4]) const
 Serialize this address to a 4-byte buffer. More...
 
void Set (char const *address)
 Sets an Ipv4Address by parsing a the input C-string. More...
 
void Set (uint32_t address)
 input address is in host order. More...
 

Static Public Member Functions

static Ipv4Address ConvertFrom (const Address &address)
 
static Ipv4Address Deserialize (const uint8_t buf[4])
 
static Ipv4Address GetAny (void)
 
static Ipv4Address GetBroadcast (void)
 
static Ipv4Address GetLoopback (void)
 
static Ipv4Address GetZero (void)
 
static bool IsMatchingType (const Address &address)
 

Private Member Functions

Address ConvertTo (void) const
 Convert to an Address type. More...
 

Static Private Member Functions

static uint8_t GetType (void)
 Get the underlying address type (automatically assigned). More...
 

Private Attributes

uint32_t m_address
 IPv4 address. More...
 
bool m_initialized
 IPv4 address has been explicitly initialized to a valid value. More...
 

Friends

bool operator!= (Ipv4Address const &a, Ipv4Address const &b)
 Not equal to operator. More...
 
bool operator< (Ipv4Address const &a, Ipv4Address const &b)
 Less than to operator. More...
 
bool operator== (Ipv4Address const &a, Ipv4Address const &b)
 Equal to operator. More...
 

Detailed Description

Ipv4 addresses are stored in host order in this class.

See also
Ipv4Address Attribute

Definition at line 41 of file ipv4-address.h.

Constructor & Destructor Documentation

◆ Ipv4Address() [1/3]

ns3::Ipv4Address::Ipv4Address ( )

Definition at line 195 of file ipv4-address.cc.

References NS_LOG_FUNCTION.

Referenced by CombineMask(), and GetSubnetDirectedBroadcast().

+ Here is the caller graph for this function:

◆ Ipv4Address() [2/3]

ns3::Ipv4Address::Ipv4Address ( uint32_t  address)
explicit

input address is in host order.

Parameters
addressThe host order 32-bit address

Definition at line 200 of file ipv4-address.cc.

References first::address, m_address, m_initialized, and NS_LOG_FUNCTION.

◆ Ipv4Address() [3/3]

ns3::Ipv4Address::Ipv4Address ( char const *  address)

Constructs an Ipv4Address by parsing a the input C-string.

Input address is in format: hhh.xxx.xxx.lll where h is the high byte and l the low byte

Parameters
addressC-string containing the address as described above

Definition at line 206 of file ipv4-address.cc.

References first::address, ns3::AsciiToIpv4Host(), m_address, m_initialized, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

Member Function Documentation

◆ CombineMask()

Ipv4Address ns3::Ipv4Address::CombineMask ( Ipv4Mask const &  mask) const

◆ ConvertFrom()

Ipv4Address ns3::Ipv4Address::ConvertFrom ( const Address address)
static

◆ ConvertTo()

Address ns3::Ipv4Address::ConvertTo ( void  ) const
private

Convert to an Address type.

Returns
the Address corresponding to this object.

Definition at line 361 of file ipv4-address.cc.

References GetType(), NS_LOG_FUNCTION, and Serialize().

+ Here is the call graph for this function:

◆ Deserialize()

Ipv4Address ns3::Ipv4Address::Deserialize ( const uint8_t  buf[4])
static

◆ Get()

◆ GetAny()

Ipv4Address ns3::Ipv4Address::GetAny ( void  )
static
Returns
the 0.0.0.0 address

Definition at line 395 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::DhcpClient::DhcpClient(), ns3::Ipv4RawSocketImpl::Ipv4RawSocketImpl(), ns3::NoBackhaulEpcHelper::NoBackhaulEpcHelper(), ns3::QKDAppHelper::QKDAppHelper(), Tunnel::Tunnel(), ns3::Ipv4EndPointDemux::Allocate(), ns3::Ipv4RawSocketImpl::Bind(), ns3::TcpSocketBase::Bind(), ns3::UdpSocketImpl::Bind(), BuildAppsTest(), ns3::QKDKeyManagerSystemApplication::ConnectToSDNController(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::RoutingProtocol::DoInitialize(), ns3::TcpGeneralTest::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), ns3::Rip::DoSendRouteUpdate(), ns3::UdpSocketImpl::DoSendTo(), experiment(), ns3::Ipv4RawSocketImpl::ForwardUp(), ns3::Ipv4RawSocketImpl::GetPeerName(), ns3::Rip::HandleRequests(), InstallPacketSink(), ns3::Ipv4L3Protocol::IpMulticastForward(), ns3::Ipv4EndPointDemux::Lookup(), ns3::dsdv::RoutingProtocol::NotifyAddAddress(), ns3::dsdv::RoutingProtocol::NotifyInterfaceUp(), ns3::dsdv::RoutingProtocol::NotifyRemoveAddress(), ns3::QKDSDNController::PrepareSinkSocket(), ns3::QKDApp004::PrepareSinkSocketFromKMS(), ns3::QKDApp014::PrepareSinkSocketFromKMS(), Experiment::Run(), ns3::Ipv4L3Protocol::Send(), ns3::Rip::SendRouteRequest(), ns3::Ipv4RawSocketImpl::SendTo(), ns3::QKDAppHelper::SetSettings(), ns3::Ipv4EndPointDemux::SimpleLookup(), ns3::QKDPostprocessingApplication::StartApplication(), ns3::UdpEchoServer::StartApplication(), ns3::UdpServer::StartApplication(), ns3::DhcpClient::StartApplication(), ns3::DhcpServer::StartApplication(), ns3::V4Ping::StartApplication(), ns3::V4TraceRoute::StartApplication(), and ns3::BsmApplication::StartApplication().

+ Here is the caller graph for this function:

◆ GetBroadcast()

Ipv4Address ns3::Ipv4Address::GetBroadcast ( void  )
static
Returns
the 255.255.255.255 address

Definition at line 402 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS.

Referenced by ns3::ArpL3Protocol::SendArpRequest(), and ns3::aodv::RoutingProtocol::SendRerrMessage().

+ Here is the caller graph for this function:

◆ GetLoopback()

◆ GetSubnetDirectedBroadcast()

Ipv4Address ns3::Ipv4Address::GetSubnetDirectedBroadcast ( Ipv4Mask const &  mask) const

Generate subnet-directed broadcast address corresponding to mask.

The subnet-directed broadcast address has the host bits set to all ones. If this method is called with a mask of 255.255.255.255, (i.e., the address is a /32 address), the program will assert, since there is no subnet associated with a /32 address.

Parameters
maska network mask
Returns
a broadcast address for the subnet.

Definition at line 242 of file ipv4-address.cc.

References Ipv4Address(), Get(), ns3::Ipv4Mask::GetInverse(), ns3::Ipv4Mask::GetOnes(), NS_ASSERT_MSG, and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4FlowProbe::DropLogger(), and ns3::olsr::RoutingProtocol::SendPacket().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetType()

uint8_t ns3::Ipv4Address::GetType ( void  )
staticprivate

Get the underlying address type (automatically assigned).

Returns
the address type

Definition at line 380 of file ipv4-address.cc.

References NS_LOG_FUNCTION_NOARGS, and ns3::Address::Register().

Referenced by ConvertFrom(), ConvertTo(), and IsMatchingType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetZero()

◆ IsAny()

bool ns3::Ipv4Address::IsAny ( void  ) const
Returns
true if address is 0.0.0.0; false otherwise

Definition at line 273 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::Rip::Lookup(), and ns3::Ipv4L3Protocol::Send().

+ Here is the caller graph for this function:

◆ IsBroadcast()

◆ IsInitialized()

bool ns3::Ipv4Address::IsInitialized ( void  ) const
Returns
true if address is initialized (i.e., set to something), false otherwise

Definition at line 266 of file ipv4-address.cc.

References m_initialized, and NS_LOG_FUNCTION.

◆ IsLocalhost()

bool ns3::Ipv4Address::IsLocalhost ( void  ) const
Returns
true if address is 127.0.0.1; false otherwise

Definition at line 280 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

◆ IsLocalMulticast()

bool ns3::Ipv4Address::IsLocalMulticast ( void  ) const
Returns
true only if address is in local multicast address scope, 224.0.0.0/24

Definition at line 305 of file ipv4-address.cc.

References m_address, and NS_LOG_FUNCTION.

Referenced by ns3::Rip::Lookup(), ns3::Ipv4StaticRouting::LookupStatic(), and ns3::Ipv4L3Protocol::Send().

+ Here is the caller graph for this function:

◆ IsMatchingType()

bool ns3::Ipv4Address::IsMatchingType ( const Address address)
static
Parameters
addressan address to compare type with
Returns
true if the type of the address stored internally is compatible with the type of the input address, false otherwise.

Definition at line 350 of file ipv4-address.cc.

References first::address, GetType(), and NS_LOG_FUNCTION.

Referenced by ns3::TcpHeader::CalculateHeaderChecksum(), ns3::UdpHeader::CalculateHeaderChecksum(), ns3::UdpSocketImpl::DoSend(), ns3::UdpSocketImpl::GetPeerName(), ns3::ThreeGppHttpClient::OpenConnection(), ns3::UdpEchoClient::Send(), ns3::TcpL4Protocol::SendPacket(), ns3::UdpTraceClient::SendPacket(), ns3::ThreeGppHttpServer::StartApplication(), ns3::UdpClient::StartApplication(), ns3::UdpEchoClient::StartApplication(), and ns3::UdpTraceClient::StartApplication().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ IsMulticast()

◆ IsSubnetDirectedBroadcast()

bool ns3::Ipv4Address::IsSubnetDirectedBroadcast ( Ipv4Mask const &  mask) const

Generate subnet-directed broadcast address corresponding to mask.

The subnet-directed broadcast address has the host bits set to all ones. If this method is called with a mask of 255.255.255.255, (i.e., the address is a /32 address), the program will assert, since there is no subnet associated with a /32 address.

Parameters
maska network mask
Returns
true if the address, when combined with the input mask, has all of its host bits set to one

Definition at line 253 of file ipv4-address.cc.

References Get(), ns3::Ipv4Mask::GetInverse(), ns3::Ipv4Mask::GetOnes(), and NS_LOG_FUNCTION.

Referenced by ns3::Ipv4L3Protocol::IsUnicast(), ns3::Ipv4L3Protocol::LocalDeliver(), ns3::Ipv4Interface::Send(), and ns3::Ipv4L3Protocol::Send().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator Address()

ns3::Ipv4Address::operator Address ( ) const

Convert an instance of this class to a polymorphic Address instance.

Returns
a new Address instance

Definition at line 355 of file ipv4-address.cc.

◆ Print()

◆ Serialize()

void ns3::Ipv4Address::Serialize ( uint8_t  buf[4]) const

◆ Set() [1/2]

void ns3::Ipv4Address::Set ( char const *  address)

Sets an Ipv4Address by parsing a the input C-string.

Input address is in format: hhh.xxx.xxx.lll where h is the high byte and l the low byte

Parameters
addressC-string containing the address as described above

Definition at line 227 of file ipv4-address.cc.

References first::address, ns3::AsciiToIpv4Host(), m_address, m_initialized, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Set() [2/2]

void ns3::Ipv4Address::Set ( uint32_t  address)

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( Ipv4Address const &  a,
Ipv4Address const &  b 
)
friend

Not equal to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the operands are not equal.

Definition at line 382 of file ipv4-address.h.

◆ operator<

bool operator< ( Ipv4Address const &  a,
Ipv4Address const &  b 
)
friend

Less than to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the first operand is less than the second.

Definition at line 387 of file ipv4-address.h.

◆ operator==

bool operator== ( Ipv4Address const &  a,
Ipv4Address const &  b 
)
friend

Equal to operator.

Parameters
athe first operand.
bthe first operand.
Returns
true if the operands are equal.

Definition at line 377 of file ipv4-address.h.

Member Data Documentation

◆ m_address

uint32_t ns3::Ipv4Address::m_address
private

◆ m_initialized

bool ns3::Ipv4Address::m_initialized
private

IPv4 address has been explicitly initialized to a valid value.

Definition at line 215 of file ipv4-address.h.

Referenced by Ipv4Address(), Deserialize(), IsInitialized(), and Set().


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