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
30f0f0ed
Commit
30f0f0ed
authored
Mar 05, 2022
by
Michael Tremer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
network: Move a couple of helper functions into headers
Signed-off-by:
Michael Tremer
<
michael.tremer@ipfire.org
>
parent
f1fb21bd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
3 deletions
+41
-3
src/libloc/private.h
src/libloc/private.h
+38
-0
src/network.c
src/network.c
+3
-3
No files found.
src/libloc/private.h
View file @
30f0f0ed
...
@@ -78,6 +78,44 @@ static inline void in6_addr_set_bit(struct in6_addr* address, unsigned int i, un
...
@@ -78,6 +78,44 @@ static inline void in6_addr_set_bit(struct in6_addr* address, unsigned int i, un
address
->
s6_addr
[
i
/
8
]
^=
(
-
val
^
address
->
s6_addr
[
i
/
8
])
&
(
1
<<
(
7
-
(
i
%
8
)));
address
->
s6_addr
[
i
/
8
]
^=
(
-
val
^
address
->
s6_addr
[
i
/
8
])
&
(
1
<<
(
7
-
(
i
%
8
)));
}
}
static
inline
struct
in6_addr
loc_prefix_to_bitmask
(
const
unsigned
int
prefix
)
{
struct
in6_addr
bitmask
;
for
(
unsigned
int
i
=
0
;
i
<
16
;
i
++
)
bitmask
.
s6_addr
[
i
]
=
0
;
for
(
int
i
=
prefix
,
j
=
0
;
i
>
0
;
i
-=
8
,
j
++
)
{
if
(
i
>=
8
)
bitmask
.
s6_addr
[
j
]
=
0xff
;
else
bitmask
.
s6_addr
[
j
]
=
0xff
<<
(
8
-
i
);
}
return
bitmask
;
}
static
inline
struct
in6_addr
loc_address_and
(
const
struct
in6_addr
*
address
,
const
struct
in6_addr
*
bitmask
)
{
struct
in6_addr
a
;
// Perform bitwise AND
for
(
unsigned
int
i
=
0
;
i
<
4
;
i
++
)
a
.
s6_addr32
[
i
]
=
address
->
s6_addr32
[
i
]
&
bitmask
->
s6_addr32
[
i
];
return
a
;
}
static
inline
struct
in6_addr
loc_address_or
(
const
struct
in6_addr
*
address
,
const
struct
in6_addr
*
bitmask
)
{
struct
in6_addr
a
;
// Perform bitwise OR
for
(
unsigned
int
i
=
0
;
i
<
4
;
i
++
)
a
.
s6_addr32
[
i
]
=
address
->
s6_addr32
[
i
]
|
~
bitmask
->
s6_addr32
[
i
];
return
a
;
}
static
inline
void
hexdump
(
struct
loc_ctx
*
ctx
,
const
void
*
addr
,
size_t
len
)
{
static
inline
void
hexdump
(
struct
loc_ctx
*
ctx
,
const
void
*
addr
,
size_t
len
)
{
char
buffer_hex
[
16
*
3
+
6
];
char
buffer_hex
[
16
*
3
+
6
];
char
buffer_ascii
[
17
];
char
buffer_ascii
[
17
];
...
...
src/network.c
View file @
30f0f0ed
...
@@ -141,11 +141,11 @@ LOC_EXPORT int loc_network_new(struct loc_ctx* ctx, struct loc_network** network
...
@@ -141,11 +141,11 @@ LOC_EXPORT int loc_network_new(struct loc_ctx* ctx, struct loc_network** network
n
->
prefix
=
prefix
;
n
->
prefix
=
prefix
;
// Convert the prefix into a bitmask
// Convert the prefix into a bitmask
struct
in6_addr
bitmask
=
prefix_to_bitmask
(
n
->
prefix
);
struct
in6_addr
bitmask
=
loc_
prefix_to_bitmask
(
n
->
prefix
);
// Store the first and last address in the network
// Store the first and last address in the network
n
->
first_address
=
make_first_address
(
address
,
&
bitmask
);
n
->
first_address
=
loc_address_and
(
address
,
&
bitmask
);
n
->
last_address
=
make_last_address
(
&
n
->
first_address
,
&
bitmask
);
n
->
last_address
=
loc_address_or
(
&
n
->
first_address
,
&
bitmask
);
// Set family
// Set family
n
->
family
=
loc_address_family
(
&
n
->
first_address
);
n
->
family
=
loc_address_family
(
&
n
->
first_address
);
...
...
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