Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
libloc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
libloc
Commits
b074be0b
Commit
b074be0b
authored
Mar 07, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: Implement bit length function for IPv4
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
5559e086
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
src/libloc/private.h
src/libloc/private.h
+22
-1
src/test-network.c
src/test-network.c
+2
-0
No files found.
src/libloc/private.h
View file @
b074be0b
...
@@ -94,7 +94,7 @@ static inline struct in6_addr loc_prefix_to_bitmask(const unsigned int prefix) {
...
@@ -94,7 +94,7 @@ static inline struct in6_addr loc_prefix_to_bitmask(const unsigned int prefix) {
return
bitmask
;
return
bitmask
;
}
}
static
inline
unsigned
int
loc_address
_bit_length
(
const
struct
in6_addr
*
address
)
{
static
inline
unsigned
int
__loc_address6
_bit_length
(
const
struct
in6_addr
*
address
)
{
unsigned
int
length
=
128
;
unsigned
int
length
=
128
;
for
(
int
octet
=
0
;
octet
<=
15
;
octet
++
)
{
for
(
int
octet
=
0
;
octet
<=
15
;
octet
++
)
{
...
@@ -108,6 +108,27 @@ static inline unsigned int loc_address_bit_length(const struct in6_addr* address
...
@@ -108,6 +108,27 @@ static inline unsigned int loc_address_bit_length(const struct in6_addr* address
return
length
;
return
length
;
}
}
static
inline
unsigned
int
__loc_address4_bit_length
(
const
struct
in6_addr
*
address
)
{
unsigned
int
length
=
32
;
for
(
int
octet
=
12
;
octet
<=
15
;
octet
++
)
{
if
(
address
->
s6_addr
[
octet
])
{
length
-=
__builtin_clz
(
address
->
s6_addr
[
octet
])
-
24
;
break
;
}
else
length
-=
8
;
}
return
length
;
}
static
inline
unsigned
int
loc_address_bit_length
(
const
struct
in6_addr
*
address
)
{
if
(
IN6_IS_ADDR_V4MAPPED
(
address
))
return
__loc_address4_bit_length
(
address
);
else
return
__loc_address6_bit_length
(
address
);
}
static
inline
struct
in6_addr
loc_address_and
(
static
inline
struct
in6_addr
loc_address_and
(
const
struct
in6_addr
*
address
,
const
struct
in6_addr
*
bitmask
)
{
const
struct
in6_addr
*
address
,
const
struct
in6_addr
*
bitmask
)
{
struct
in6_addr
a
;
struct
in6_addr
a
;
...
...
src/test-network.c
View file @
b074be0b
...
@@ -311,6 +311,8 @@ int main(int argc, char** argv) {
...
@@ -311,6 +311,8 @@ int main(int argc, char** argv) {
}
bit_length_tests
[]
=
{
}
bit_length_tests
[]
=
{
{
"::/0"
,
0
},
{
"::/0"
,
0
},
{
"2001::/128"
,
126
},
{
"2001::/128"
,
126
},
{
"1.0.0.0/32"
,
25
},
{
"255.255.255.255/32"
,
32
},
{
NULL
,
0
,
},
{
NULL
,
0
,
},
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment