Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
babeld
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
babeld
Commits
d6b3ab99
Commit
d6b3ab99
authored
Jun 12, 2013
by
Matthieu Boutier
Committed by
Juliusz Chroboczek
Jul 18, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add function to compare prefixes, with an enumeration.
parent
740e8228
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
0 deletions
+38
-0
util.c
util.c
+28
-0
util.h
util.h
+10
-0
No files found.
util.c
View file @
d6b3ab99
...
...
@@ -28,6 +28,7 @@ THE SOFTWARE.
#include <stdio.h>
#include <unistd.h>
#include <limits.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/socket.h>
...
...
@@ -488,3 +489,30 @@ daemonise()
return
1
;
}
enum
prefix_status
prefix_cmp
(
const
unsigned
char
*
p1
,
unsigned
char
plen1
,
const
unsigned
char
*
p2
,
unsigned
char
plen2
)
{
int
min
=
MIN
(
plen1
,
plen2
);
unsigned
char
mask
=
0xFF
;
int
i
=
0
;
while
(
i
<
min
/
8
)
{
if
(
p1
[
i
]
!=
p2
[
i
])
return
PST_DISJOINT
;
i
++
;
}
min
-=
i
*
8
;
if
(
min
!=
0
)
{
mask
<<=
8
-
min
;
if
((
p1
[
i
]
&
mask
)
!=
(
p2
[
i
]
&
mask
))
return
PST_DISJOINT
;
}
if
(
plen1
<
plen2
)
return
PST_LESS_SPECIFIC
;
if
(
plen1
>
plen2
)
return
PST_MORE_SPECIFIC
;
return
PST_EQUALS
;
}
util.h
View file @
d6b3ab99
...
...
@@ -112,6 +112,16 @@ int v4mapped(const unsigned char *address) ATTRIBUTE ((pure));
void
v4tov6
(
unsigned
char
*
dst
,
const
unsigned
char
*
src
);
int
daemonise
(
void
);
enum
prefix_status
{
PST_DISJOINT
=
1
<<
0
,
PST_EQUALS
=
1
<<
1
,
PST_MORE_SPECIFIC
=
1
<<
2
,
PST_LESS_SPECIFIC
=
1
<<
3
,
};
enum
prefix_status
prefix_cmp
(
const
unsigned
char
*
p1
,
unsigned
char
plen1
,
const
unsigned
char
*
p2
,
unsigned
char
plen2
);
/* If debugging is disabled, we want to avoid calling format_address
for every omitted debugging message. So debug is a macro. But
vararg macros are not portable. */
...
...
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