Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
iproute2
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
iproute2
Commits
4b270b17
Commit
4b270b17
authored
Dec 11, 2007
by
Stephen Hemminger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix dotted quad for bit order
Signed-off-by:
Stephen Hemminger
<
shemminger@linux-foundation.org
>
parent
5a0d1cbf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
lib/utils.c
lib/utils.c
+14
-7
No files found.
lib/utils.c
View file @
4b270b17
...
...
@@ -47,7 +47,7 @@ int get_integer(int *val, const char *arg, int base)
return
0
;
}
/* a valid netmask must be 2^n - 1
(n = 1..31)
*/
/* a valid netmask must be 2^n - 1 */
static
int
is_valid_netmask
(
const
inet_prefix
*
addr
)
{
uint32_t
host
;
...
...
@@ -60,6 +60,17 @@ static int is_valid_netmask(const inet_prefix *addr)
return
(
host
&
(
host
+
1
))
==
0
;
}
static
unsigned
cidr
(
const
inet_prefix
*
addr
)
{
unsigned
bits
=
0
;
u_int32_t
mask
;
for
(
mask
=
ntohl
(
addr
->
data
[
0
]);
mask
;
mask
<<=
1
)
++
bits
;
return
bits
;
}
static
int
get_netmask
(
unsigned
*
val
,
const
char
*
arg
,
int
base
)
{
inet_prefix
addr
;
...
...
@@ -69,14 +80,10 @@ static int get_netmask(unsigned *val, const char *arg, int base)
/* try coverting dotted quad to CIDR */
if
(
!
get_addr_1
(
&
addr
,
arg
,
AF_INET
))
{
u_int32_t
mask
;
*
val
=
0
;
for
(
mask
=
addr
.
data
[
0
];
mask
;
mask
>>=
1
)
(
*
val
)
++
;
if
(
is_valid_netmask
(
&
addr
))
return
0
;
*
val
=
cidr
(
&
addr
);
}
return
-
1
;
...
...
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