Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
senf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wiback
senf
Commits
d08d652b
Commit
d08d652b
authored
16 years ago
by
dw6
Browse files
Options
Downloads
Patches
Plain Diff
senf::INet4Address::toString() added
parent
700dc3be
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Socket/Protocols/INet/INet4Address.cc
+12
-3
12 additions, 3 deletions
Socket/Protocols/INet/INet4Address.cc
Socket/Protocols/INet/INet4Address.hh
+18
-16
18 additions, 16 deletions
Socket/Protocols/INet/INet4Address.hh
with
30 additions
and
19 deletions
Socket/Protocols/INet/INet4Address.cc
+
12
−
3
View file @
d08d652b
...
@@ -89,11 +89,20 @@ prefix_ senf::INet4Address senf::INet4Address::from_string(std::string const & s
...
@@ -89,11 +89,20 @@ prefix_ senf::INet4Address senf::INet4Address::from_string(std::string const & s
reinterpret_cast
<
in_addr
*>
(
*
(
ent
->
h_addr_list
))
->
s_addr
);
reinterpret_cast
<
in_addr
*>
(
*
(
ent
->
h_addr_list
))
->
s_addr
);
}
}
prefix_
std
::
string
senf
::
INet4Address
::
toString
()
const
{
char
buffer
[
4
*
4
];
::
in_addr
ina
;
ina
.
s_addr
=
(
*
this
).
inaddr
();
::
inet_ntop
(
AF_INET
,
&
ina
,
buffer
,
sizeof
(
buffer
));
buffer
[
sizeof
(
buffer
)
-
1
]
=
0
;
return
buffer
;
}
prefix_
bool
senf
::
INet4Address
::
local
()
prefix_
bool
senf
::
INet4Address
::
local
()
const
const
{
{
address_type
l
(
address
());
address_type
l
(
address
());
return
return
(
l
&
0xFF000000u
)
==
0x0A000000u
||
(
l
&
0xFF000000u
)
==
0x0A000000u
||
(
l
&
0xFFF00000u
)
==
0xAC100000u
||
(
l
&
0xFFF00000u
)
==
0xAC100000u
||
(
l
&
0xFFFF0000u
)
==
0xA9FE0000u
||
(
l
&
0xFFFF0000u
)
==
0xA9FE0000u
||
...
@@ -147,7 +156,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const &
...
@@ -147,7 +156,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const &
char
buffer
[
16
];
char
buffer
[
16
];
ina
.
s_addr
=
addr
.
inaddr
();
ina
.
s_addr
=
addr
.
inaddr
();
::
inet_ntop
(
AF_INET
,
&
ina
,
buffer
,
16
);
::
inet_ntop
(
AF_INET
,
&
ina
,
buffer
,
16
);
buffer
[
15
]
=
0
;
buffer
[
15
]
=
0
;
os
<<
buffer
;
os
<<
buffer
;
return
os
;
return
os
;
}
}
...
@@ -156,7 +165,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const &
...
@@ -156,7 +165,7 @@ prefix_ std::ostream & senf::operator<<(std::ostream & os, INet4Address const &
#undef prefix_
#undef prefix_
//#include "INet4Address.mpp"
//#include "INet4Address.mpp"
// Local Variables:
// Local Variables:
// mode: c++
// mode: c++
// fill-column: 100
// fill-column: 100
...
...
This diff is collapsed.
Click to expand it.
Socket/Protocols/INet/INet4Address.hh
+
18
−
16
View file @
d08d652b
...
@@ -40,9 +40,9 @@
...
@@ -40,9 +40,9 @@
///////////////////////////////hh.p////////////////////////////////////////
///////////////////////////////hh.p////////////////////////////////////////
namespace
senf
{
namespace
senf
{
/** \brief IPv4 Internet address
/** \brief IPv4 Internet address
INet4Address represents a simple IP address. It is modelled as a fixed-size
INet4Address represents a simple IP address. It is modelled as a fixed-size
container/sequence of 4 bytes.
container/sequence of 4 bytes.
...
@@ -50,7 +50,7 @@ namespace senf {
...
@@ -50,7 +50,7 @@ namespace senf {
\code
\code
// Used to construct constant INet4 addresses
// Used to construct constant INet4 addresses
INet4Address(0xD3C2B1A0)
INet4Address(0xD3C2B1A0)
// Construct an INet4 address from it's string representation. All the standard address
// Construct an INet4 address from it's string representation. All the standard address
// representations are supported
// representations are supported
INet4Address::from_string("211.194.177.160")
INet4Address::from_string("211.194.177.160")
...
@@ -87,13 +87,13 @@ namespace senf {
...
@@ -87,13 +87,13 @@ namespace senf {
\ingroup addr_group
\ingroup addr_group
*/
*/
class
INet4Address
class
INet4Address
:
public
boost
::
array
<
boost
::
uint8_t
,
4
>
,
:
public
boost
::
array
<
boost
::
uint8_t
,
4
>
,
public
comparable_safe_bool
<
INet4Address
>
public
comparable_safe_bool
<
INet4Address
>
{
{
public:
public:
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// Types
// Types
typedef
uint32_t
address_type
;
///< Address representation as number in host byte order
typedef
uint32_t
address_type
;
///< Address representation as number in host byte order
typedef
uint32_t
inaddr_type
;
///< Legacy address representation in network byte order
typedef
uint32_t
inaddr_type
;
///< Legacy address representation in network byte order
...
@@ -121,8 +121,8 @@ namespace senf {
...
@@ -121,8 +121,8 @@ namespace senf {
\throws AddressSyntaxException if the address cannot be
\throws AddressSyntaxException if the address cannot be
converted for some reason
converted for some reason
\param[in] s Address literal or hostname */
\param[in] s Address literal or hostname */
template
<
class
InputIterator
>
template
<
class
InputIterator
>
static
INet4Address
from_data
(
InputIterator
i
);
static
INet4Address
from_data
(
InputIterator
i
);
///< Construct address from 4 bytes of raw data
///< Construct address from 4 bytes of raw data
/**< from_data will build an address from 4 bytes of raw
/**< from_data will build an address from 4 bytes of raw
...
@@ -153,12 +153,14 @@ namespace senf {
...
@@ -153,12 +153,14 @@ namespace senf {
bool
boolean_test
()
const
;
///< \c true, if address is non-empty (!= 0.0.0.0)
bool
boolean_test
()
const
;
///< \c true, if address is non-empty (!= 0.0.0.0)
inaddr_type
inaddr
()
const
;
///< Return the raw network byte order address
inaddr_type
inaddr
()
const
;
///< Return the raw network byte order address
/**< This member is used to interact with legacy code.
/**< This member is used to interact with legacy code.
\return */
\return */
address_type
address
()
const
;
///< Return address represented as integer number
address_type
address
()
const
;
///< Return address represented as integer number
/**< This member returns the address as an integer number in
/**< This member returns the address as an integer number in
host byte order. This representation allows simple
host byte order. This representation allows simple
network math operations. */
network math operations. */
std
::
string
toString
()
const
;
///< get the string representation of this INet4Address
////@}
////@}
...
@@ -178,10 +180,10 @@ namespace senf {
...
@@ -178,10 +180,10 @@ namespace senf {
This helper allows to easily and efficiently check an INet4Address against an arbitrary but
This helper allows to easily and efficiently check an INet4Address against an arbitrary but
constant network prefix. The network prefix is represented by
constant network prefix. The network prefix is represented by
\par ""
\par ""
<tt>senf::CheckINet4Network<</tt> <i>addr</i> <tt>,</tt> <i>prefix-len</i> <tt>></tt>
<tt>senf::CheckINet4Network<</tt> <i>addr</i> <tt>,</tt> <i>prefix-len</i> <tt>></tt>
Where \a addr is the v4 Internet address as a 32-bit unsigned integer number in host byte
Where \a addr is the v4 Internet address as a 32-bit unsigned integer number in host byte
order and \a prefix_len is the length of the network prefix. The class exposes a single
order and \a prefix_len is the length of the network prefix. The class exposes a single
static member <tt>match(</tt> <i>addr</i> <tt>)</tt> which matches the INet4Address \a addr
static member <tt>match(</tt> <i>addr</i> <tt>)</tt> which matches the INet4Address \a addr
...
@@ -206,10 +208,10 @@ namespace senf {
...
@@ -206,10 +208,10 @@ namespace senf {
/** \brief IPv4 network prefix
/** \brief IPv4 network prefix
This class represents an IPv4 network prefix in CIDR notation.
This class represents an IPv4 network prefix in CIDR notation.
*/
*/
class
INet4Network
class
INet4Network
:
public
boost
::
equality_comparable
<
INet4Network
>
,
:
public
boost
::
equality_comparable
<
INet4Network
>
,
public
comparable_safe_bool
<
INet4Network
>
public
comparable_safe_bool
<
INet4Network
>
{
{
public:
public:
...
@@ -231,7 +233,7 @@ namespace senf {
...
@@ -231,7 +233,7 @@ namespace senf {
bool
boolean_test
()
const
;
///< \c true, if INet4Network is non-empty
bool
boolean_test
()
const
;
///< \c true, if INet4Network is non-empty
bool
operator
==
(
INet4Network
const
&
other
)
const
;
bool
operator
==
(
INet4Network
const
&
other
)
const
;
///< Compare to networks for equality
///< Compare to networks for equality
bool
match
(
INet4Address
addr
)
const
;
///< \c true, if the network includes \a addr
bool
match
(
INet4Address
addr
)
const
;
///< \c true, if the network includes \a addr
bool
match
(
INet4Network
net
)
const
;
///< \c true, if the network includes \a net
bool
match
(
INet4Network
net
)
const
;
///< \c true, if the network includes \a net
/**< The is true, if \a net is sub-network (or the same as)
/**< The is true, if \a net is sub-network (or the same as)
...
@@ -253,7 +255,7 @@ namespace senf {
...
@@ -253,7 +255,7 @@ namespace senf {
\code
\code
INet4Network("192.168.0.0/16").subnet(111u,24u) == INet4Network("192.168.111.0/24")
INet4Network("192.168.0.0/16").subnet(111u,24u) == INet4Network("192.168.111.0/24")
INet4Network("192.168.111.0/24").subnet(1u,28u) == INet4Network("192.168.111.16/28")
INet4Network("192.168.111.0/24").subnet(1u,28u) == INet4Network("192.168.111.16/28")
\endcode
\endcode
\param[in] net network number
\param[in] net network number
\param[in] prefix_len length of subnet prefix */
\param[in] prefix_len length of subnet prefix */
...
@@ -270,7 +272,7 @@ namespace senf {
...
@@ -270,7 +272,7 @@ namespace senf {
\related INet4Network
\related INet4Network
*/
*/
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
INet4Network
const
&
addr
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
INet4Network
const
&
addr
);
}
}
///////////////////////////////hh.e////////////////////////////////////////
///////////////////////////////hh.e////////////////////////////////////////
...
@@ -279,7 +281,7 @@ namespace senf {
...
@@ -279,7 +281,7 @@ namespace senf {
#include
"INet4Address.cti"
#include
"INet4Address.cti"
#endif
#endif
// Local Variables:
// Local Variables:
// mode: c++
// mode: c++
// fill-column: 100
// fill-column: 100
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment