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
078fe553
Commit
078fe553
authored
Nov 27, 2007
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement parsing of IPv4 addresses and networks.
parent
6d1c55bb
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
6 deletions
+30
-6
util.c
util.c
+30
-6
No files found.
util.c
View file @
078fe553
...
@@ -212,8 +212,17 @@ format_prefix(const unsigned char *prefix, unsigned char plen)
...
@@ -212,8 +212,17 @@ format_prefix(const unsigned char *prefix, unsigned char plen)
int
int
parse_address
(
const
char
*
address
,
unsigned
char
*
addr_r
)
parse_address
(
const
char
*
address
,
unsigned
char
*
addr_r
)
{
{
struct
in_addr
ina
;
struct
in6_addr
ina6
;
struct
in6_addr
ina6
;
int
rc
;
int
rc
;
rc
=
inet_pton
(
AF_INET
,
address
,
&
ina
);
if
(
rc
>
0
)
{
memcpy
(
addr_r
,
v4prefix
,
12
);
memcpy
(
addr_r
+
12
,
&
ina
,
4
);
return
0
;
}
rc
=
inet_pton
(
AF_INET6
,
address
,
&
ina6
);
rc
=
inet_pton
(
AF_INET6
,
address
,
&
ina6
);
if
(
rc
>
0
)
{
if
(
rc
>
0
)
{
memcpy
(
addr_r
,
&
ina6
,
16
);
memcpy
(
addr_r
,
&
ina6
,
16
);
...
@@ -230,6 +239,8 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -230,6 +239,8 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
char
*
slash
,
*
end
;
char
*
slash
,
*
end
;
unsigned
char
prefix
[
16
];
unsigned
char
prefix
[
16
];
long
plen
;
long
plen
;
struct
in_addr
ina
;
struct
in6_addr
ina6
;
int
rc
;
int
rc
;
if
(
strcmp
(
net
,
"default"
)
==
0
)
{
if
(
strcmp
(
net
,
"default"
)
==
0
)
{
...
@@ -247,12 +258,25 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -247,12 +258,25 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
return
-
1
;
return
-
1
;
memcpy
(
buf
,
net
,
slash
-
net
);
memcpy
(
buf
,
net
,
slash
-
net
);
buf
[
slash
-
net
]
=
'\0'
;
buf
[
slash
-
net
]
=
'\0'
;
rc
=
parse_address
(
buf
,
prefix
);
rc
=
inet_pton
(
AF_INET
,
buf
,
&
ina
);
if
(
rc
<
0
)
if
(
rc
>
0
)
{
return
rc
;
memcpy
(
prefix
,
v4prefix
,
12
);
memcpy
(
prefix
+
12
,
&
ina
,
4
);
plen
=
strtol
(
slash
+
1
,
&
end
,
0
);
if
(
*
end
!=
'\0'
||
plen
<
0
||
plen
>
32
)
return
-
1
;
plen
+=
96
;
}
else
{
rc
=
inet_pton
(
AF_INET6
,
buf
,
&
ina6
);
if
(
rc
>
0
)
{
memcpy
(
prefix
,
&
ina6
,
16
);
plen
=
strtol
(
slash
+
1
,
&
end
,
0
);
plen
=
strtol
(
slash
+
1
,
&
end
,
0
);
if
(
*
end
!=
'\0'
||
plen
<
0
||
plen
>
128
)
if
(
*
end
!=
'\0'
||
plen
<
0
||
plen
>
128
)
return
-
1
;
return
-
1
;
}
else
{
return
-
1
;
}
}
}
}
}
}
mask_prefix
(
prefix_r
,
prefix
,
plen
);
mask_prefix
(
prefix_r
,
prefix
,
plen
);
...
...
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