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
4430aaca
Commit
4430aaca
authored
Feb 11, 2008
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return address family from parse_ip and _net.
parent
8337aaee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
5 deletions
+13
-5
util.c
util.c
+10
-3
util.h
util.h
+3
-2
No files found.
util.c
View file @
4430aaca
...
@@ -210,7 +210,7 @@ format_prefix(const unsigned char *prefix, unsigned char plen)
...
@@ -210,7 +210,7 @@ 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
,
int
*
af_r
)
{
{
struct
in_addr
ina
;
struct
in_addr
ina
;
struct
in6_addr
ina6
;
struct
in6_addr
ina6
;
...
@@ -220,12 +220,14 @@ parse_address(const char *address, unsigned char *addr_r)
...
@@ -220,12 +220,14 @@ parse_address(const char *address, unsigned char *addr_r)
if
(
rc
>
0
)
{
if
(
rc
>
0
)
{
memcpy
(
addr_r
,
v4prefix
,
12
);
memcpy
(
addr_r
,
v4prefix
,
12
);
memcpy
(
addr_r
+
12
,
&
ina
,
4
);
memcpy
(
addr_r
+
12
,
&
ina
,
4
);
if
(
af_r
)
*
af_r
=
AF_INET
;
return
0
;
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
);
if
(
af_r
)
*
af_r
=
AF_INET6
;
return
0
;
return
0
;
}
}
...
@@ -233,12 +235,14 @@ parse_address(const char *address, unsigned char *addr_r)
...
@@ -233,12 +235,14 @@ parse_address(const char *address, unsigned char *addr_r)
}
}
int
int
parse_net
(
const
char
*
net
,
unsigned
char
*
prefix_r
,
unsigned
char
*
plen_r
)
parse_net
(
const
char
*
net
,
unsigned
char
*
prefix_r
,
unsigned
char
*
plen_r
,
int
*
af_r
)
{
{
char
buf
[
INET6_ADDRSTRLEN
];
char
buf
[
INET6_ADDRSTRLEN
];
char
*
slash
,
*
end
;
char
*
slash
,
*
end
;
unsigned
char
prefix
[
16
];
unsigned
char
prefix
[
16
];
long
plen
;
long
plen
;
int
af
;
struct
in_addr
ina
;
struct
in_addr
ina
;
struct
in6_addr
ina6
;
struct
in6_addr
ina6
;
int
rc
;
int
rc
;
...
@@ -249,7 +253,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -249,7 +253,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
}
else
{
}
else
{
slash
=
strchr
(
net
,
'/'
);
slash
=
strchr
(
net
,
'/'
);
if
(
slash
==
NULL
)
{
if
(
slash
==
NULL
)
{
rc
=
parse_address
(
net
,
prefix
);
rc
=
parse_address
(
net
,
prefix
,
&
af
);
if
(
rc
<
0
)
if
(
rc
<
0
)
return
rc
;
return
rc
;
plen
=
128
;
plen
=
128
;
...
@@ -266,6 +270,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -266,6 +270,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
if
(
*
end
!=
'\0'
||
plen
<
0
||
plen
>
32
)
if
(
*
end
!=
'\0'
||
plen
<
0
||
plen
>
32
)
return
-
1
;
return
-
1
;
plen
+=
96
;
plen
+=
96
;
af
=
AF_INET
;
}
else
{
}
else
{
rc
=
inet_pton
(
AF_INET6
,
buf
,
&
ina6
);
rc
=
inet_pton
(
AF_INET6
,
buf
,
&
ina6
);
if
(
rc
>
0
)
{
if
(
rc
>
0
)
{
...
@@ -273,6 +278,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -273,6 +278,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
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
;
af
=
AF_INET6
;
}
else
{
}
else
{
return
-
1
;
return
-
1
;
}
}
...
@@ -281,6 +287,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
...
@@ -281,6 +287,7 @@ parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r)
}
}
mask_prefix
(
prefix_r
,
prefix
,
plen
);
mask_prefix
(
prefix_r
,
prefix
,
plen
);
*
plen_r
=
plen
;
*
plen_r
=
plen
;
if
(
af_r
)
*
af_r
=
af
;
return
0
;
return
0
;
}
}
...
...
util.h
View file @
4430aaca
...
@@ -46,8 +46,9 @@ const unsigned char *mask_prefix(unsigned char *ret,
...
@@ -46,8 +46,9 @@ const unsigned char *mask_prefix(unsigned char *ret,
unsigned
char
plen
);
unsigned
char
plen
);
const
char
*
format_address
(
const
unsigned
char
*
address
);
const
char
*
format_address
(
const
unsigned
char
*
address
);
const
char
*
format_prefix
(
const
unsigned
char
*
address
,
unsigned
char
prefix
);
const
char
*
format_prefix
(
const
unsigned
char
*
address
,
unsigned
char
prefix
);
int
parse_address
(
const
char
*
address
,
unsigned
char
*
addr_r
);
int
parse_address
(
const
char
*
address
,
unsigned
char
*
addr_r
,
int
*
af_r
);
int
parse_net
(
const
char
*
net
,
unsigned
char
*
prefix_r
,
unsigned
char
*
plen_r
);
int
parse_net
(
const
char
*
net
,
unsigned
char
*
prefix_r
,
unsigned
char
*
plen_r
,
int
*
af_r
);
int
wait_for_fd
(
int
direction
,
int
fd
,
int
msecs
);
int
wait_for_fd
(
int
direction
,
int
fd
,
int
msecs
);
int
martian_prefix
(
const
unsigned
char
*
prefix
,
int
plen
);
int
martian_prefix
(
const
unsigned
char
*
prefix
,
int
plen
);
int
v4mapped
(
const
unsigned
char
*
address
);
int
v4mapped
(
const
unsigned
char
*
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