A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
ipv4-address.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2005 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
21
#ifndef IPV4_ADDRESS_H
22
#define IPV4_ADDRESS_H
23
24
#include <stdint.h>
25
#include <ostream>
26
#include "ns3/address.h"
27
#include "ns3/attribute-helper.h"
28
29
namespace
ns3 {
30
31
class
Ipv4Mask;
32
38
class
Ipv4Address
{
39
public
:
40
Ipv4Address
();
45
explicit
Ipv4Address
(uint32_t address);
55
Ipv4Address
(
char
const
*address);
60
uint32_t
Get
(
void
)
const
;
65
void
Set
(uint32_t address);
75
void
Set
(
char
const
*address);
81
bool
IsEqual
(
const
Ipv4Address
&other)
const
82
{
83
return
m_address
== other.
m_address
;
84
}
91
void
Serialize
(uint8_t buf[4])
const
;
98
static
Ipv4Address
Deserialize
(
const
uint8_t buf[4]);
105
void
Print
(std::ostream &os)
const
;
109
bool
IsBroadcast
(
void
)
const
;
113
bool
IsMulticast
(
void
)
const
;
117
bool
IsLocalMulticast
(
void
)
const
;
127
Ipv4Address
CombineMask
(
Ipv4Mask
const
&mask)
const
;
138
Ipv4Address
GetSubnetDirectedBroadcast
(
Ipv4Mask
const
&mask)
const
;
151
bool
IsSubnetDirectedBroadcast
(
Ipv4Mask
const
&mask)
const
;
158
static
bool
IsMatchingType
(
const
Address
&address);
164
operator
Address
()
const
;
173
static
Ipv4Address
ConvertFrom
(
const
Address
&address);
177
static
Ipv4Address
GetZero
(
void
);
181
static
Ipv4Address
GetAny
(
void
);
185
static
Ipv4Address
GetBroadcast
(
void
);
189
static
Ipv4Address
GetLoopback
(
void
);
190
191
private
:
192
Address
ConvertTo
(
void
)
const
;
193
static
uint8_t
GetType
(
void
);
194
uint32_t
m_address
;
195
196
friend
bool
operator ==
(
Ipv4Address
const
&a,
Ipv4Address
const
&b);
197
friend
bool
operator !=
(
Ipv4Address
const
&a,
Ipv4Address
const
&b);
198
friend
bool
operator <
(
Ipv4Address
const
&addrA,
Ipv4Address
const
&addrB);
199
};
200
210
class
Ipv4Mask
{
211
public
:
215
Ipv4Mask
();
221
Ipv4Mask
(uint32_t mask);
225
Ipv4Mask
(
char
const
*mask);
232
bool
IsMatch
(
Ipv4Address
a,
Ipv4Address
b)
const
;
237
bool
IsEqual
(
Ipv4Mask
other)
const
;
242
uint32_t
Get
(
void
)
const
;
247
void
Set
(uint32_t mask);
251
uint32_t
GetInverse
(
void
)
const
;
258
void
Print
(std::ostream &os)
const
;
262
uint16_t
GetPrefixLength
(
void
)
const
;
266
static
Ipv4Mask
GetLoopback
(
void
);
270
static
Ipv4Mask
GetZero
(
void
);
274
static
Ipv4Mask
GetOnes
(
void
);
275
276
private
:
277
uint32_t
m_mask
;
278
};
279
289
ATTRIBUTE_HELPER_HEADER
(
Ipv4Address
);
290
ATTRIBUTE_HELPER_HEADER
(
Ipv4Mask
);
291
292
std::ostream&
operator<<
(std::ostream& os,
Ipv4Address
const
& address);
293
std::ostream&
operator<<
(std::ostream& os,
Ipv4Mask
const
& mask);
294
std::istream &
operator >>
(std::istream &is,
Ipv4Address
&address);
295
std::istream &
operator >>
(std::istream &is,
Ipv4Mask
&mask);
296
297
inline
bool
operator ==
(
const
Ipv4Address
&a,
const
Ipv4Address
&b)
298
{
299
return
(a.
m_address
== b.
m_address
);
300
}
301
inline
bool
operator !=
(
const
Ipv4Address
&a,
const
Ipv4Address
&b)
302
{
303
return
(a.
m_address
!= b.
m_address
);
304
}
305
inline
bool
operator <
(
const
Ipv4Address
&a,
const
Ipv4Address
&b)
306
{
307
return
(a.
m_address
< b.
m_address
);
308
}
309
310
311
class
Ipv4AddressHash
:
public
std::unary_function<Ipv4Address, size_t> {
312
public
:
313
size_t
operator()
(
Ipv4Address
const
&
x
)
const
;
314
};
315
316
bool
operator ==
(
Ipv4Mask
const
&a,
Ipv4Mask
const
&b);
317
bool
operator !=
(
Ipv4Mask
const
&a,
Ipv4Mask
const
&b);
318
319
}
// namespace ns3
320
321
#endif
/* IPV4_ADDRESS_H */
src
network
utils
ipv4-address.h
Generated on Tue Oct 9 2012 16:45:44 for ns-3 by
1.8.1.2