Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Knot DNS
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
22
Issues
22
List
Boards
Labels
Service Desk
Milestones
Merge Requests
17
Merge Requests
17
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
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
Knot projects
Knot DNS
Commits
5730745e
Commit
5730745e
authored
Jun 08, 2015
by
Daniel Salzman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
yparser: improve address type detection
parent
cfc790eb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
7 deletions
+31
-7
src/libknot/yparser/yptrafo.c
src/libknot/yparser/yptrafo.c
+31
-7
No files found.
src/libknot/yparser/yptrafo.c
View file @
5730745e
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include <ctype.h>
#include <stdlib.h>
#include <stdlib.h>
#include <inttypes.h>
#include <inttypes.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
...
@@ -293,6 +294,31 @@ static int yp_int_to_txt(
...
@@ -293,6 +294,31 @@ static int yp_int_to_txt(
return
KNOT_EOK
;
return
KNOT_EOK
;
}
}
static
uint8_t
sock_type_guess
(
char
const
*
txt
,
size_t
txt_len
)
{
size_t
dots
=
0
;
size_t
semicolons
=
0
;
size_t
digits
=
0
;
// Analyze the string.
for
(
size_t
i
=
0
;
i
<
txt_len
;
i
++
)
{
if
(
txt
[
i
]
==
'.'
)
dots
++
;
else
if
(
txt
[
i
]
==
':'
)
semicolons
++
;
else
if
(
isdigit
((
int
)
txt
[
i
])
!=
0
)
digits
++
;
}
// Guess socket type.
if
(
semicolons
>=
1
)
{
return
6
;
}
else
if
(
semicolons
==
0
&&
dots
==
3
&&
digits
>=
3
)
{
return
4
;
}
else
{
return
0
;
}
}
static
int
addr_to_bin
(
static
int
addr_to_bin
(
TXT_BIN_PARAMS
,
TXT_BIN_PARAMS
,
bool
allow_unix
)
bool
allow_unix
)
...
@@ -300,20 +326,18 @@ static int addr_to_bin(
...
@@ -300,20 +326,18 @@ static int addr_to_bin(
struct
in_addr
addr4
;
struct
in_addr
addr4
;
struct
in6_addr
addr6
;
struct
in6_addr
addr6
;
uint8_t
type
;
uint8_t
type
=
sock_type_guess
(
txt
,
txt_len
);
size_t
addr_len
;
size_t
addr_len
;
const
void
*
addr
;
const
void
*
addr
;
if
(
inet_pton
(
AF_INET
,
txt
,
&
addr4
)
==
1
)
{
if
(
type
==
4
&&
inet_pton
(
AF_INET
,
txt
,
&
addr4
)
==
1
)
{
type
=
4
;
addr_len
=
sizeof
(
addr4
.
s_addr
);
addr_len
=
sizeof
(
addr4
.
s_addr
);
addr
=
&
(
addr4
.
s_addr
);
addr
=
&
(
addr4
.
s_addr
);
}
else
if
(
inet_pton
(
AF_INET6
,
txt
,
&
addr6
)
==
1
)
{
}
else
if
(
type
==
6
&&
inet_pton
(
AF_INET6
,
txt
,
&
addr6
)
==
1
)
{
type
=
6
;
addr_len
=
sizeof
(
addr6
.
s6_addr
);
addr_len
=
sizeof
(
addr6
.
s6_addr
);
addr
=
&
(
addr6
.
s6_addr
);
addr
=
&
(
addr6
.
s6_addr
);
}
else
if
(
allow_unix
&&
txt_len
>
0
)
{
}
else
if
(
type
==
0
&&
allow_unix
&&
txt_len
>
0
)
{
type
=
0
;
addr_len
=
txt_len
+
1
;
// + trailing zero.
addr_len
=
txt_len
+
1
;
// + trailing zero.
addr
=
txt
;
addr
=
txt
;
}
else
{
}
else
{
...
...
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