INET Framework for OMNeT++/OMNEST
inet::IPv4Address Class Reference

IPv4 address. More...

#include <IPv4Address.h>

Public Types

enum  AddressCategory {
  UNSPECIFIED, THIS_NETWORK, LOOPBACK, MULTICAST,
  BROADCAST, IETF, TEST_NET, IPv6_TO_IPv4_RELAY,
  BENCHMARK, RESERVED, LINKLOCAL, PRIVATE_NETWORK,
  GLOBAL
}
 IPv4 address category. More...
 

Public Member Functions

IPv4Addressoperator= (const IPv4Address &obj)
 Assignment. More...
 
bool isUnspecified () const
 True if all four address bytes are zero. More...
 
bool equals (const IPv4Address &toCmp) const
 Returns true if the two addresses are equal. More...
 
IPv4Address doAnd (const IPv4Address &ip) const
 Returns binary AND of the two addresses. More...
 
std::string str (bool printUnspec=true) const
 Returns the string representation of the address (e.g. More...
 
uint32 getInt () const
 Returns the address as an int. More...
 
int getDByte (int i) const
 Returns the corresponding part of the address specified by the index ("[0].[1].[2].[3]") More...
 
char getIPClass () const
 Returns the network class of the address: char 'A', 'B', 'C', 'D', 'E', or '?' (returned when the address begins with at least five 1 bits.) More...
 
AddressCategory getAddressCategory () const
 Get the IPv4 address category. More...
 
bool isLimitedBroadcastAddress () const
 Returns true if this address is the limited broadcast address, i.e. More...
 
bool isMulticast () const
 Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it's a class D address. More...
 
bool isUnicast () const
 Returns true if this address is unicast address. More...
 
bool isLinkLocalMulticast () const
 Returns true if this address is in the range 224.0.0.0 to 224.0.0.255. More...
 
IPv4Address getNetwork () const
 Returns an address with the network part of the address (the bits of the hosts part are to 0). More...
 
IPv4Address getNetworkMask () const
 Returns an address with the network mask corresponding to the address class. More...
 
bool isNetwork (const IPv4Address &toCmp) const
 Indicates if the address is from the same network. More...
 
bool prefixMatches (const IPv4Address &to_cmp, int numbits) const
 Compares the first numbits bits of the two addresses. More...
 
int getNumMatchingPrefixBits (const IPv4Address &to_cmp) const
 Indicates how many bits from the to_cmp address, starting counting from the left, matches the address. More...
 
int getNetmaskLength () const
 Counts 1 bits in a netmask. More...
 
IPv4Address getPrefix (int prefixLength) const
 Get the first prefixLength bits of the address, with the rest set to zero. More...
 
bool isValidNetmask () const
 Returns true if the address is a valid netmask, i.e. More...
 
IPv4Address makeBroadcastAddress (IPv4Address netmask) const
 Returns the broadcast address for the given netmask. More...
 
bool operator== (const IPv4Address &addr1) const
 Returns equals(addr). More...
 
bool operator!= (const IPv4Address &addr1) const
 Returns !equals(addr). More...
 
bool operator< (const IPv4Address &addr1) const
 Compares two IPv4 addresses. More...
 
bool operator<= (const IPv4Address &addr1) const
 
bool operator> (const IPv4Address &addr1) const
 
bool operator>= (const IPv4Address &addr1) const
 
 IPv4Address ()
 name Constructors, destructor More...
 
 IPv4Address (uint32 ip)
 IPv4 address as int. More...
 
 IPv4Address (int i0, int i1, int i2, int i3)
 IPv4 address bytes: "i0.i1.i2.i3" format. More...
 
 IPv4Address (const char *text)
 IPv4 address given as text: "192.66.86.1". More...
 
 IPv4Address (const IPv4Address &obj)
 Copy constructor. More...
 
 ~IPv4Address ()
 
void set (uint32 ip)
 name Setting the address More...
 
void set (int i0, int i1, int i2, int i3)
 IPv4 address bytes: "i0.i1.i2.i3" format. More...
 
void set (const char *t)
 IPv4 address given as text: "192.66.86.1". More...
 

Static Public Member Functions

static bool maskedAddrAreEqual (const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
 Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal. More...
 
static bool isWellFormed (const char *text)
 Returns true if the format of the string corresponds to an IPv4 address with the dotted notation ("192.66.86.1"), and false otherwise. More...
 
static IPv4Address makeNetmask (int length)
 Creates and returns a netmask with the given length. More...
 

Static Public Attributes

Predefined addresses
static const IPv4Address UNSPECIFIED_ADDRESS
 0.0.0.0 More...
 
static const IPv4Address LOOPBACK_ADDRESS
 127.0.0.1 More...
 
static const IPv4Address LOOPBACK_NETMASK
 255.0.0.0 More...
 
static const IPv4Address ALLONES_ADDRESS
 255.255.255.255 More...
 
static const IPv4Address ALL_HOSTS_MCAST
 224.0.0.1 All hosts on a subnet More...
 
static const IPv4Address ALL_ROUTERS_MCAST
 224.0.0.2 All routers on a subnet More...
 
static const IPv4Address ALL_DVMRP_ROUTERS_MCAST
 224.0.0.4 All DVMRP routers More...
 
static const IPv4Address ALL_OSPF_ROUTERS_MCAST
 224.0.0.5 All OSPF routers (DR Others) More...
 
static const IPv4Address ALL_OSPF_DESIGNATED_ROUTERS_MCAST
 224.0.0.6 All OSPF Designated Routers More...
 
static const IPv4Address ALL_IGMPV3_ROUTERS_MCAST
 224.0.0.22 All IGMPv3 routers More...
 
static const IPv4Address LL_MANET_ROUTERS
 224.0.0.109 Manet all designated routers More...
 
static const IPv4Address ALL_RIP_ROUTERS_MCAST
 

Static Protected Member Functions

static bool parseIPAddress (const char *text, unsigned char tobytes[])
 
static void _checkNetmaskLength (int length)
 
static uint32 _makeNetmask (int length)
 

Protected Attributes

uint32 addr
 

Detailed Description

IPv4 address.

Member Enumeration Documentation

IPv4 address category.

RFC 5735 Special Use IPv4 Addresses January 2010

  1. Summary Table

    Address Block Present Use Reference

0.0.0.0/8 "This" Network RFC 1122, Section 3.2.1.3 10.0.0.0/8 Private-Use Networks RFC 1918 127.0.0.0/8 Loopback RFC 1122, Section 3.2.1.3 169.254.0.0/16 Link Local RFC 3927 172.16.0.0/12 Private-Use Networks RFC 1918 192.0.0.0/24 IETF Protocol Assignments RFC 5736 192.0.2.0/24 TEST-NET-1 RFC 5737 192.88.99.0/24 6to4 Relay Anycast RFC 3068 192.168.0.0/16 Private-Use Networks RFC 1918 198.18.0.0/15 Network Interconnect Device Benchmark Testing RFC 2544 198.51.100.0/24 TEST-NET-2 RFC 5737 203.0.113.0/24 TEST-NET-3 RFC 5737 224.0.0.0/4 Multicast RFC 3171 240.0.0.0/4 Reserved for Future Use RFC 1112, Section 4 255.255.255.255/32 Limited Broadcast RFC 919, Section 7; RFC 922, Section 7

Enumerator
UNSPECIFIED 
THIS_NETWORK 
LOOPBACK 
MULTICAST 
BROADCAST 
IETF 
TEST_NET 
IPv6_TO_IPv4_RELAY 
BENCHMARK 
RESERVED 
LINKLOCAL 
PRIVATE_NETWORK 
GLOBAL 
84  {
85  UNSPECIFIED, // 0.0.0.0
86  THIS_NETWORK, // 0.0.0.0/8
87  LOOPBACK, // 127.0.0.0/8
88  MULTICAST, // 224.0.0.0/4
89  BROADCAST, // 255.255.255.255/32
90  IETF, // 192.0.0.0/24
91  TEST_NET, // 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
92  IPv6_TO_IPv4_RELAY, // 192.88.99.0/24
93  BENCHMARK, // 198.18.0.0/15
94  RESERVED, // 240.0.0.0/4
95  LINKLOCAL, // 169.254.0.0/16
96  PRIVATE_NETWORK, // 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
97  GLOBAL
98  };
Definition: IPv4Address.h:88
Definition: IPv4Address.h:89
Definition: IPv4Address.h:87
Definition: IPv4Address.h:93
Definition: IPv4Address.h:85
Definition: IPv4Address.h:91
Definition: IPv4Address.h:96
Definition: IPv4Address.h:95
Definition: IPv4Address.h:94
Definition: IPv4Address.h:90
Definition: IPv4Address.h:86
Definition: IPv4Address.h:97
Definition: IPv4Address.h:92

Constructor & Destructor Documentation

inet::IPv4Address::IPv4Address ( )
inline

name Constructors, destructor

Default constructor, initializes to 0.0.0.0.

Referenced by getNetwork(), and getNetworkMask().

123 { addr = 0; }
uint32 addr
Definition: IPv4Address.h:49
inet::IPv4Address::IPv4Address ( uint32  ip)
inlineexplicit

IPv4 address as int.

128 { addr = ip; }
uint32 addr
Definition: IPv4Address.h:49
inet::IPv4Address::IPv4Address ( int  i0,
int  i1,
int  i2,
int  i3 
)
inline

IPv4 address bytes: "i0.i1.i2.i3" format.

133 { set(i0, i1, i2, i3); }
inet::IPv4Address::IPv4Address ( const char *  text)
inlineexplicit

IPv4 address given as text: "192.66.86.1".

138 { set(text); }
inet::IPv4Address::IPv4Address ( const IPv4Address obj)
inline

Copy constructor.

143 { addr = obj.addr; }
uint32 addr
Definition: IPv4Address.h:49
inet::IPv4Address::~IPv4Address ( )
inline
145 {}

Member Function Documentation

void inet::IPv4Address::_checkNetmaskLength ( int  length)
staticprotected
255 {
256  if (length < 0 || length > 32)
257  throw cRuntimeError("IPv4Address: wrong netmask length %d (not in 0..32)", length);
258 }
static uint32 inet::IPv4Address::_makeNetmask ( int  length)
inlinestaticprotected

Referenced by prefixMatches().

57 { return length >= 32 ? 0xffffffffu : ~(0xffffffffu >> length); }
IPv4Address inet::IPv4Address::doAnd ( const IPv4Address ip) const
inline

Returns binary AND of the two addresses.

Referenced by inet::IPv4NetworkConfigurator::addStaticRoutes(), inet::NetworkInfo::dumpRoutingInfo(), inet::IPv4RoutingTable::updateNetmaskRoutes(), and inet::bgp::BGPRouting::updateSendProcess().

186 { return IPv4Address(addr & ip.addr); }
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::equals ( const IPv4Address toCmp) const
inline

Returns true if the two addresses are equal.

Referenced by inet::DHCPClient::finish().

181 { return addr == toCmp.addr; }
uint32 addr
Definition: IPv4Address.h:49
IPv4Address::AddressCategory inet::IPv4Address::getAddressCategory ( ) const

Get the IPv4 address category.

Referenced by inet::sctp::SCTPAssociation::getAddressLevel().

137 {
138  if (isUnspecified())
139  return UNSPECIFIED; // 0.0.0.0
140  if ((addr & 0xFF000000u) == 0)
141  return THIS_NETWORK; // 0.0.0.0/8
142  if ((addr & 0xFF000000u) == 0x7F000000u)
143  return LOOPBACK; // 127.0.0.0/8
144  if (isMulticast())
145  return MULTICAST; // 224.0.0.0/4
146  if (addr == 0xFFFFFFFFu)
147  return BROADCAST; // 255.255.255.255/32
148  uint32 addr24 = addr & 0xFFFFFF00u;
149  if (addr24 == 0xC0000000u)
150  return IETF; // 192.0.0.0/24
151  if ((addr24 == 0xC0000200u) || (addr24 == 0xC6336400u) || (addr24 == 0xCB007100u))
152  return TEST_NET; // 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24
153  if (addr24 == 0xC0586300u)
154  return IPv6_TO_IPv4_RELAY; // 192.88.99.0/24
155  if ((addr & 0xFFFE0000u) == 0xC6120000u)
156  return BENCHMARK; // 198.18.0.0/15
157  if ((addr & 0xF0000000u) == 0xF0000000u)
158  return RESERVED; // 240.0.0.0/4
159  if ((addr & 0xFFFF0000u) == 0xA9FE0000u)
160  return LINKLOCAL; // 169.254.0.0/16
161  if (((addr & 0xFF000000u) == 0x0A000000u)
162  || ((addr & 0xFFF00000u) == 0xAC100000u)
163  || ((addr & 0xFFFF0000u) == 0xC0A80000u))
164  return PRIVATE_NETWORK; // 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
165  return GLOBAL;
166 }
bool isUnspecified() const
True if all four address bytes are zero.
Definition: IPv4Address.h:176
Definition: IPv4Address.h:88
Definition: IPv4Address.h:89
bool isMulticast() const
Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it&#39;s a class D address.
Definition: IPv4Address.h:226
Definition: IPv4Address.h:87
Definition: IPv4Address.h:93
uint32 addr
Definition: IPv4Address.h:49
Definition: IPv4Address.h:85
Definition: IPv4Address.h:91
Definition: IPv4Address.h:96
uint32_t uint32
Definition: Compat.h:30
Definition: IPv4Address.h:95
Definition: IPv4Address.h:94
Definition: IPv4Address.h:90
Definition: IPv4Address.h:86
Definition: IPv4Address.h:97
Definition: IPv4Address.h:92
uint32 inet::IPv4Address::getInt ( ) const
inline

Returns the address as an int.

Referenced by inet::ospf::Neighbor::addToRetransmissionList(), inet::FlatNetworkConfigurator::assignAddresses(), inet::ospf::Area::calculateShortestPathTree(), inet::IPv4RoutingTable::configureRouterId(), inet::IPv4NetworkConfigurator::createInterfaceInfo(), inet::bgp::BGPRouting::createSession(), inet::bgp::BGPRouting::deleteBGPRoutingEntry(), inet::RSVP::delSession(), inet::serializer::SCTPSerializer::deserialize(), inet::doPacking(), inet::IPv4NetworkConfigurator::findInterfaceOnLinkByNodeAddress(), inet::DHCPServer::getAvailableLease(), getNumMatchingPrefixBits(), inet::tcp::TCP_NSC::handleIpInputMessage(), inet::ExtInterface::handleMessage(), inet::TED::initializeTED(), inet::ospf::Router::installASExternalLSA(), inet::IPv4RoutingTable::internalAddMulticastRoute(), inet::IPv4RoutingTable::internalAddRoute(), inet::bgp::BGPRouting::isInTable(), inet::ospf::Router::lookup(), makeBroadcastAddress(), inet::tcp::TCP_NSC::mapRemote2Nsc(), inet::ospf::Router::notifyAboutRoutingTableChanges(), inet::ospf::operator&(), operator<(), operator<=(), operator>(), operator>=(), inet::ospf::operator|(), inet::ospf::Area::originateRouterLSA(), inet::ICMP::possiblyLocalBroadcast(), inet::LDP::processLDPHello(), inet::LinkStateRouting::processLINK_STATE_MESSAGE(), inet::SimpleClassifier::readItemFromXML(), inet::sctp::SCTPAssociation::sendInit(), inet::serializer::IPv4Serializer::serialize(), inet::HostAutoConfigurator::setupNetworkLayer(), inet::DHCPServer::startApp(), and inet::serializer::Buffer::writeIPv4Address().

197 { return addr; }
uint32 addr
Definition: IPv4Address.h:49
char inet::IPv4Address::getIPClass ( ) const

Returns the network class of the address: char 'A', 'B', 'C', 'D', 'E', or '?' (returned when the address begins with at least five 1 bits.)

Referenced by getNetwork(), and getNetworkMask().

120 {
121  unsigned char buf = getDByte(0);
122  if ((buf & 0x80) == 0x00) // 0xxxx
123  return 'A';
124  else if ((buf & 0xC0) == 0x80) // 10xxx
125  return 'B';
126  else if ((buf & 0xE0) == 0xC0) // 110xx
127  return 'C';
128  else if ((buf & 0xF0) == 0xE0) // 1110x
129  return 'D';
130  else if ((buf & 0xF8) == 0xF0) // 11110
131  return 'E';
132  else
133  return '?';
134 }
int getDByte(int i) const
Returns the corresponding part of the address specified by the index ("[0].[1].[2].[3]")
Definition: IPv4Address.h:203
int inet::IPv4Address::getNetmaskLength ( ) const

Counts 1 bits in a netmask.

E.g. for 255.255.254.0, it will return 23.

Referenced by inet::LDP::rebuildFecList(), inet::visualizer::RoutingTableVisualizerBase::DirectiveResolver::resolveDirective(), inet::InterfaceTable::updateLinkDisplayString(), and inet::bgp::BGPRouting::updateSendProcess().

246 {
247  for (int i = 0; i < 32; i++)
248  if (addr & (1 << i))
249  return 32 - i;
250 
251  return 0;
252 }
uint32 addr
Definition: IPv4Address.h:49
IPv4Address inet::IPv4Address::getNetwork ( ) const

Returns an address with the network part of the address (the bits of the hosts part are to 0).

For D and E class addresses, it returns a null address.

169 {
170  switch (getIPClass()) {
171  case 'A':
172  // Class A: network = 7 bits
173  return IPv4Address(getDByte(0), 0, 0, 0);
174 
175  case 'B':
176  // Class B: network = 14 bits
177  return IPv4Address(getDByte(0), getDByte(1), 0, 0);
178 
179  case 'C':
180  // Class C: network = 21 bits
181  return IPv4Address(getDByte(0), getDByte(1), getDByte(2), 0);
182 
183  default:
184  // Class D or E
185  return IPv4Address();
186  }
187 }
char getIPClass() const
Returns the network class of the address: char &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, or &#39;?&#39; (returned when the add...
Definition: IPv4Address.cc:119
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
int getDByte(int i) const
Returns the corresponding part of the address specified by the index ("[0].[1].[2].[3]")
Definition: IPv4Address.h:203
IPv4Address inet::IPv4Address::getNetworkMask ( ) const

Returns an address with the network mask corresponding to the address class.

For D and E class addresses, it returns a null address.

Referenced by isNetwork().

190 {
191  switch (getIPClass()) {
192  case 'A':
193  // Class A: network = 7 bits
194  return IPv4Address(255, 0, 0, 0);
195 
196  case 'B':
197  // Class B: network = 14 bits
198  return IPv4Address(255, 255, 0, 0);
199 
200  case 'C':
201  // Class C: network = 21 bits
202  return IPv4Address(255, 255, 255, 0);
203 
204  default:
205  // Class D or E: return null address
206  return IPv4Address();
207  }
208 }
char getIPClass() const
Returns the network class of the address: char &#39;A&#39;, &#39;B&#39;, &#39;C&#39;, &#39;D&#39;, &#39;E&#39;, or &#39;?&#39; (returned when the add...
Definition: IPv4Address.cc:119
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
int inet::IPv4Address::getNumMatchingPrefixBits ( const IPv4Address to_cmp) const

Indicates how many bits from the to_cmp address, starting counting from the left, matches the address.

E.g. if the address is 130.206.72.237, and to_cmp 130.206.72.0, 24 will be returned.

Typical usage for comparing IPv4 prefixes.

230 {
231  uint32 addr2 = to_cmp.getInt();
232 
233  uint32 res = addr ^ addr2;
234  // If the bits are equal, there is a 0, so counting
235  // the zeros from the left
236  for (int i = 31; i >= 0; i--) {
237  if (res & (1 << i)) {
238  // 1, means not equal, so stop
239  return 31 - i;
240  }
241  }
242  return 32;
243 }
uint32 addr
Definition: IPv4Address.h:49
uint32_t uint32
Definition: Compat.h:30
IPv4Address inet::IPv4Address::getPrefix ( int  prefixLength) const
inline

Get the first prefixLength bits of the address, with the rest set to zero.

282 { return doAnd(makeNetmask(prefixLength)); }
static IPv4Address makeNetmask(int length)
Creates and returns a netmask with the given length.
Definition: IPv4Address.h:335
IPv4Address doAnd(const IPv4Address &ip) const
Returns binary AND of the two addresses.
Definition: IPv4Address.h:186
bool inet::IPv4Address::isLimitedBroadcastAddress ( ) const
inline

Returns true if this address is the limited broadcast address, i.e.

255.255.255.255.

Referenced by inet::L3Address::isBroadcast(), inet::L3Address::isUnicast(), inet::IPv4::preroutingFinish(), inet::UDP::processUDPPacket(), inet::IPv4::resolveNextHopMacAddress(), and inet::ICMP::sendErrorMessage().

220 { return addr == 0xFFFFFFFF; }
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::isLinkLocalMulticast ( ) const
inline

Returns true if this address is in the range 224.0.0.0 to 224.0.0.255.

These addresses are reserved for local purposes meaning, that routers should not forward these datagrams since the applications that use these addresses do not need the datagrams to go further than one hop.

Referenced by inet::PIMSM::addNewRouteSG(), inet::IPv4::encapsulate(), inet::IPv4::forwardMulticastPacket(), inet::IGMPv2::multicastGroupJoined(), inet::IGMPv2::multicastGroupLeft(), inet::IGMPv3::multicastSourceListChanged(), inet::IPv4::preroutingFinish(), inet::IGMPv3::sendGroupReport(), inet::IGMPv2::sendLeave(), inet::IGMPv2::sendQuery(), and inet::IGMPv2::sendReport().

239 { return (addr & 0xFFFFFF00) == 0xE0000000; }
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::isMulticast ( ) const
inline

Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it's a class D address.

Referenced by inet::IPv4InterfaceData::addMulticastListener(), inet::PIMSM::addNewRouteSG(), inet::IPv4InterfaceData::changeMulticastGroupMembership(), inet::IPv4::datagramLocalOut(), inet::NetworkInfo::dumpRoutingInfo(), inet::IPv4::encapsulate(), inet::IPv4InterfaceData::findHostGroupData(), inet::IPv4InterfaceData::findRouterGroupData(), inet::IPv4::forwardMulticastPacket(), getAddressCategory(), inet::IGMPv2::HostGroupData::HostGroupData(), inet::IGMPv3::HostGroupData::HostGroupData(), inet::IPv4RoutingTable::internalAddMulticastRoute(), inet::L3Address::isMulticast(), inet::L3Address::isUnicast(), inet::MACAddress::makeMulticastAddress(), inet::IGMPv2::multicastGroupJoined(), inet::IGMPv2::multicastGroupLeft(), inet::IPv4::preroutingFinish(), inet::UDP::processUDPPacket(), inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration(), inet::IPv4NetworkConfigurator::readMulticastGroupConfiguration(), inet::LDP::rebuildFecList(), inet::TED::rebuildRoutingTable(), inet::IPv4InterfaceData::removeHostGroupData(), inet::IPv4InterfaceData::removeRouterGroupData(), inet::IPv4::resolveNextHopMacAddress(), inet::IGMPv2::RouterGroupData::RouterGroupData(), inet::IGMPv3::RouterGroupData::RouterGroupData(), inet::ICMP::sendErrorMessage(), inet::IGMPv3::sendGroupReport(), inet::LDP::sendHelloTo(), inet::PIMDM::sendJoinPacket(), inet::IGMPv2::sendLeave(), inet::PIMDM::sendPrunePacket(), inet::IGMPv2::sendQuery(), inet::IGMPv2::sendReport(), inet::IPv4InterfaceData::setMulticastListeners(), and inet::PIMDM::unroutableMulticastPacketArrived().

226 { return (addr & 0xF0000000) == 0xE0000000; }
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::isNetwork ( const IPv4Address toCmp) const

Indicates if the address is from the same network.

211 {
212  IPv4Address netmask = getNetworkMask();
213  if (netmask.isUnspecified())
214  return false; // Class is D or E
215  return maskedAddrAreEqual(*this, toCmp, netmask);
216 }
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
static bool maskedAddrAreEqual(const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: IPv4Address.cc:260
IPv4Address getNetworkMask() const
Returns an address with the network mask corresponding to the address class.
Definition: IPv4Address.cc:189
bool inet::IPv4Address::isUnicast ( ) const
inline

Returns true if this address is unicast address.

231 { return !isMulticast() && !isLimitedBroadcastAddress(); }
bool isMulticast() const
Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it&#39;s a class D address.
Definition: IPv4Address.h:226
bool isLimitedBroadcastAddress() const
Returns true if this address is the limited broadcast address, i.e.
Definition: IPv4Address.h:220
bool inet::IPv4Address::isUnspecified ( ) const
inline

True if all four address bytes are zero.

The null value is customarily used to represent a missing, unspecified or invalid address in the simulation models.

Referenced by inet::PIMSM::addNewRouteSG(), inet::IPv4NetworkConfigurator::addStaticRoutes(), inet::RSVP::allocateResource(), inet::DHCPClient::chooseInterface(), inet::IPv4NetworkConfigurator::createInterfaceInfo(), inet::IPv4NetworkConfigurator::dumpConfig(), inet::NetworkInfo::dumpRoutingInfo(), inet::IPv4::encapsulate(), inet::PIMSM::findRouteSG(), inet::IPv4::fragmentAndSend(), getAddressCategory(), inet::PingApp::getAllAddresses(), inet::DHCPServer::getAvailableLease(), inet::IPv4RoutingTable::getInterfaceByAddress(), inet::L3AddressResolver::getInterfaceIPv4Address(), inet::ospf::Router::getPreferredEntry(), inet::PIMSM::handleNodeStart(), inet::PIMSM::IamDR(), inet::IPv4Route::info(), inet::GlobalARP::initialize(), inet::IPv4RoutingTable::internalAddMulticastRoute(), inet::IPv4RoutingTable::internalAddRoute(), inet::ospf::Router::isDestinationUnreachable(), inet::IPv4RoutingTable::isLocalBroadcastAddress(), isNetwork(), inet::L3Address::isUnspecified(), inet::bgp::BGPRouting::loadSessionConfig(), inet::IPv4MulticastRoute::matches(), inet::operator<<(), inet::RSVP::pathProblem(), inet::ICMP::possiblyLocalBroadcast(), inet::IPv4::preroutingFinish(), inet::IPv4RoutingTable::printMulticastRoutingTable(), inet::IPv4RoutingTable::printRoutingTable(), inet::ARP::processARPPacket(), inet::PIMSM::processAssertPacket(), inet::DHCPServer::processDHCPMessage(), inet::RSVP::processPathMsg(), inet::IGMPv2::processQuery(), inet::IGMPv3::processQuery(), inet::LDP::rebuildFecList(), inet::DHCPClient::recordLease(), inet::DHCPClient::recordOffer(), inet::RSVP::refreshPath(), inet::visualizer::RoutingTableVisualizerBase::DirectiveResolver::resolveDirective(), inet::IPv4NetworkConfigurator::resolveInterfaceAndGateway(), inet::IPv4::routeUnicastPacket(), inet::RSVP::scheduleRefreshTimer(), inet::DHCPServer::sendACK(), inet::ARP::sendARPRequest(), inet::sctp::SCTPNatHook::sendBackError(), inet::IPv4::sendDatagramToOutput(), inet::ICMP::sendErrorMessage(), inet::PIMDM::sendJoinPacket(), inet::DHCPServer::sendNAK(), inet::DHCPServer::sendOffer(), inet::PIMDM::sendPrunePacket(), inet::IGMPv2::sendQuery(), str(), inet::PIMDM::unroutableMulticastPacketArrived(), inet::PIMSM::unroutableMulticastPacketArrived(), and inet::PIMSM::updateDesignatedRouterAddress().

176 { return addr == 0; }
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::isValidNetmask ( ) const
inline

Returns true if the address is a valid netmask, i.e.

ones are contiguous and shifted fully to the left in the binary representation.

Referenced by inet::IPv4RoutingTable::internalAddMulticastRoute(), inet::IPv4RoutingTable::internalAddRoute(), inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration(), and inet::IPv4NetworkConfigurator::readManualRouteConfiguration().

288 { return addr == _makeNetmask(getNetmaskLength()); }
static uint32 _makeNetmask(int length)
Definition: IPv4Address.h:57
uint32 addr
Definition: IPv4Address.h:49
int getNetmaskLength() const
Counts 1 bits in a netmask.
Definition: IPv4Address.cc:245
bool inet::IPv4Address::isWellFormed ( const char *  text)
static

Returns true if the format of the string corresponds to an IPv4 address with the dotted notation ("192.66.86.1"), and false otherwise.

This function can be used to verify an IPv4 address string before assigning it to an IPv4Address object (both its ctor and set() function raises an error if the string has invalid format.)

Referenced by inet::IPv4NetworkConfigurator::parseAddressAndSpecifiedBits(), inet::RoutingTableParser::parseRouting(), inet::IPv4NetworkConfigurator::resolveInterfaceAndGateway(), and inet::L3Address::tryParse().

270 {
271  unsigned char dummy[4];
272  return parseIPAddress(text, dummy);
273 }
static bool parseIPAddress(const char *text, unsigned char tobytes[])
Definition: IPv4Address.cc:59
IPv4Address inet::IPv4Address::makeBroadcastAddress ( IPv4Address  netmask) const

Returns the broadcast address for the given netmask.

Referenced by inet::IPv4RoutingTable::findInterfaceByLocalBroadcastAddress(), inet::IPv4InterfaceData::getNetworkBroadcastAddress(), inet::ospf::Area::getUniqueLinkStateID(), inet::ospf::Router::getUniqueLinkStateID(), and inet::IPv4RoutingTable::isLocalBroadcastAddress().

276 {
277  IPv4Address br(getInt() | ~(netmask.getInt()));
278  return br;
279 }
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
static IPv4Address inet::IPv4Address::makeNetmask ( int  length)
inlinestatic

Creates and returns a netmask with the given length.

For example, for length=23 it will return 255.255.254.0.

Referenced by inet::L3Address::matches(), inet::bgp::BGPRouting::processMessage(), inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration(), inet::IPv4NetworkConfigurator::readManualRouteConfiguration(), inet::IPv4Route::setPrefixLength(), and inet::IPv4MulticastRoute::setPrefixLength().

335 { _checkNetmaskLength(length); return IPv4Address(_makeNetmask(length)); }
IPv4Address()
name Constructors, destructor
Definition: IPv4Address.h:123
static void _checkNetmaskLength(int length)
Definition: IPv4Address.cc:254
static uint32 _makeNetmask(int length)
Definition: IPv4Address.h:57
bool inet::IPv4Address::maskedAddrAreEqual ( const IPv4Address addr1,
const IPv4Address addr2,
const IPv4Address netmask 
)
static
bool inet::IPv4Address::operator!= ( const IPv4Address addr1) const
inline

Returns !equals(addr).

311 { return !equals(addr1); }
bool equals(const IPv4Address &toCmp) const
Returns true if the two addresses are equal.
Definition: IPv4Address.h:181
bool inet::IPv4Address::operator< ( const IPv4Address addr1) const
inline

Compares two IPv4 addresses.

316 { return getInt() < addr1.getInt(); }
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
bool inet::IPv4Address::operator<= ( const IPv4Address addr1) const
inline
317 { return getInt() <= addr1.getInt(); }
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
IPv4Address& inet::IPv4Address::operator= ( const IPv4Address obj)
inline

Assignment.

169 { addr = obj.addr; return *this; }
uint32 addr
Definition: IPv4Address.h:49
bool inet::IPv4Address::operator== ( const IPv4Address addr1) const
inline

Returns equals(addr).

306 { return equals(addr1); }
bool equals(const IPv4Address &toCmp) const
Returns true if the two addresses are equal.
Definition: IPv4Address.h:181
bool inet::IPv4Address::operator> ( const IPv4Address addr1) const
inline
318 { return getInt() > addr1.getInt(); }
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
bool inet::IPv4Address::operator>= ( const IPv4Address addr1) const
inline
319 { return getInt() >= addr1.getInt(); }
uint32 getInt() const
Returns the address as an int.
Definition: IPv4Address.h:197
bool inet::IPv4Address::parseIPAddress ( const char *  text,
unsigned char  tobytes[] 
)
staticprotected

Referenced by isWellFormed(), and set().

60 {
61  if (!text)
62  return false;
63 
64  if (!strcmp(text, "<unspec>")) {
65  tobytes[0] = tobytes[1] = tobytes[2] = tobytes[3] = 0;
66  return true;
67  }
68 
69  const char *s = text;
70  int i = 0;
71  while (true) {
72  if (*s < '0' || *s > '9')
73  return false; // missing number
74 
75  // read and store number
76  int num = 0;
77  while (*s >= '0' && *s <= '9')
78  num = 10 * num + (*s++ - '0');
79  if (num > 255)
80  return false; // number too big
81  tobytes[i++] = (unsigned char)num;
82 
83  if (!*s)
84  break; // end of string
85  if (*s != '.')
86  return false; // invalid char after number
87  if (i == 4)
88  return false; // read 4th number and not yet EOS
89 
90  // skip '.'
91  s++;
92  }
93  return i == 4; // must have all 4 numbers
94 }
value< double, units::s > s
Definition: Units.h:1049
bool inet::IPv4Address::prefixMatches ( const IPv4Address to_cmp,
int  numbits 
) const

Compares the first numbits bits of the two addresses.

Referenced by inet::LDP::lookupLabel(), and inet::MultiFieldClassifier::Filter::matches().

219 {
220  if (length < 1)
221  return true;
222  if (length > 31)
223  return addr == other.addr;
224 
225  uint32 mask = _makeNetmask(length);
226  return (addr & mask) == (other.addr & mask);
227 }
static uint32 _makeNetmask(int length)
Definition: IPv4Address.h:57
uint32 addr
Definition: IPv4Address.h:49
uint32_t uint32
Definition: Compat.h:30
void inet::IPv4Address::set ( uint32  ip)
inline

name Setting the address

IPv4 address as int

Referenced by inet::bgp::BGPRouting::createSession(), inet::doUnpacking(), inet::ospf::operator&(), and inet::ospf::operator|().

153 { addr = ip; }
uint32 addr
Definition: IPv4Address.h:49
void inet::IPv4Address::set ( int  i0,
int  i1,
int  i2,
int  i3 
)

IPv4 address bytes: "i0.i1.i2.i3" format.

55 {
56  addr = (i0 << 24) | (i1 << 16) | (i2 << 8) | i3;
57 }
uint32 addr
Definition: IPv4Address.h:49
void inet::IPv4Address::set ( const char *  t)

IPv4 address given as text: "192.66.86.1".

97 {
98  unsigned char buf[4];
99  if (!text)
100  throw cRuntimeError("IPv4 address string is nullptr");
101 
102  bool ok = parseIPAddress(text, buf);
103  if (!ok)
104  throw cRuntimeError("Invalid IPv4 address string `%s'", text);
105 
106  set(buf[0], buf[1], buf[2], buf[3]);
107 }
static bool parseIPAddress(const char *text, unsigned char tobytes[])
Definition: IPv4Address.cc:59
std::string inet::IPv4Address::str ( bool  printUnspec = true) const

Returns the string representation of the address (e.g.

"152.66.86.92")

Parameters
printUnspecshow 0.0.0.0 as "<unspec>" if true

Referenced by inet::ospf::Area::addAddressRange(), inet::IPv4InterfaceData::addMulticastListener(), inet::DHCPClient::bindLease(), inet::IPv4InterfaceData::changeMulticastGroupMembership(), inet::bgp::BGPRouting::decisionProcess(), inet::ospf::Area::detailedInfo(), inet::IPv4NetworkConfigurator::dumpConfig(), inet::PacketDump::dumpIPv4(), inet::IPv4::encapsulate(), inet::RSVP::evalNextHopInterface(), inet::LDP::findInterfaceFromPeerAddr(), inet::TED::getInterfaceAddrByPeerAddress(), inet::LDP::getPeerSocket(), inet::PIMInterface::info(), inet::ospf::Area::info(), inet::TED::initializeTED(), inet::IPv4RoutingTable::internalAddMulticastRoute(), inet::IPv4RoutingTable::internalAddRoute(), inet::ospf::OSPFConfigReader::loadAreaFromXML(), inet::bgp::BGPRouting::loadConfigFromXML(), inet::ospf::OSPFConfigReader::loadHostRoute(), inet::ospf::OSPFConfigReader::loadInterfaceParameters(), inet::bgp::BGPRouting::loadSessionConfig(), inet::ospf::OSPFConfigReader::loadVirtualLink(), inet::bgp::operator<<(), inet::ospf::operator<<(), inet::operator<<(), inet::TED::peerRemoteInterface(), inet::IPv4RoutingTable::printMulticastRoutingTable(), inet::IPv4RoutingTable::printRoutingTable(), inet::PIMSM::processAssertPacket(), inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration(), inet::IPv4NetworkConfigurator::readManualRouteConfiguration(), inet::IPv4NetworkConfigurator::readMulticastGroupConfiguration(), inet::RoutingTableRecorder::recordInterfaceChange(), inet::visualizer::RoutingTableVisualizerBase::DirectiveResolver::resolveDirective(), inet::rtp::RTP::resolveMTU(), inet::PIMSM::sendPIMJoin(), inet::PIMSM::sendPIMPrune(), inet::IPv4InterfaceData::setMulticastListeners(), inet::HostAutoConfigurator::setupNetworkLayer(), inet::IGMPv2::startHostTimer(), inet::L3Address::str(), and inet::InterfaceTable::updateLinkDisplayString().

110 {
111  if (printUnspec && isUnspecified())
112  return std::string("<unspec>");
113 
114  char buf[IPADDRESS_STRING_SIZE];
115  sprintf(buf, "%u.%u.%u.%u", (addr >> 24) & 255, (addr >> 16) & 255, (addr >> 8) & 255, addr & 255);
116  return std::string(buf);
117 }
bool isUnspecified() const
True if all four address bytes are zero.
Definition: IPv4Address.h:176
uint32 addr
Definition: IPv4Address.h:49

Member Data Documentation

const IPv4Address inet::IPv4Address::ALL_DVMRP_ROUTERS_MCAST
static

224.0.0.4 All DVMRP routers

const IPv4Address inet::IPv4Address::ALL_IGMPV3_ROUTERS_MCAST
static
const IPv4Address inet::IPv4Address::ALL_RIP_ROUTERS_MCAST
static
const IPv4Address inet::IPv4Address::LL_MANET_ROUTERS
static

224.0.0.109 Manet all designated routers

Referenced by inet::IPv4AddressType::getLinkLocalManetRoutersMulticastAddress().

const IPv4Address inet::IPv4Address::LOOPBACK_NETMASK
static

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