Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
8ad5e44c
Commit
8ad5e44c
authored
6 years ago
by
Martine Lenders
Browse files
Options
Downloads
Patches
Plain Diff
sock_dns: remove some magic numbers
parent
2840b382
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sys/include/net/dns.h
+42
-0
42 additions, 0 deletions
sys/include/net/dns.h
sys/net/application_layer/dns/dns.c
+8
-6
8 additions, 6 deletions
sys/net/application_layer/dns/dns.c
with
50 additions
and
6 deletions
sys/include/net/dns.h
0 → 100644
+
42
−
0
View file @
8ad5e44c
/*
* Copyright (C) 2019 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_dns DNS defines
* @ingroup net
* @brief Generic DNS values
* @{
*
* @file
* @brief Generic DNS values
*
* @author Martine Lenders <m.lenders@fu-berlin.de>
*/
#ifndef NET_DNS_H
#define NET_DNS_H
#ifdef __cplusplus
extern
"C"
{
#endif
/**
* @name Field lengths
* @{
*/
#define RR_TYPE_LENGTH (2U)
#define RR_CLASS_LENGTH (2U)
#define RR_TTL_LENGTH (4U)
#define RR_RDLENGTH_LENGTH (2U)
/** @} */
#ifdef __cplusplus
}
#endif
#endif
/* NET_DNS_H */
/** @} */
This diff is collapsed.
Click to expand it.
sys/net/application_layer/dns/dns.c
+
8
−
6
View file @
8ad5e44c
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
#include
<string.h>
#include
<string.h>
#include
<stdio.h>
#include
<stdio.h>
#include
"net/dns.h"
#include
"net/sock/udp.h"
#include
"net/sock/udp.h"
#include
"net/sock/dns.h"
#include
"net/sock/dns.h"
...
@@ -114,7 +115,8 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
...
@@ -114,7 +115,8 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
return
tmp
;
return
tmp
;
}
}
bufpos
+=
tmp
;
bufpos
+=
tmp
;
bufpos
+=
4
;
/* skip type and class of query */
/* skip type and class of query */
bufpos
+=
(
RR_TYPE_LENGTH
+
RR_CLASS_LENGTH
);
}
}
for
(
unsigned
n
=
0
;
n
<
ntohs
(
hdr
->
ancount
);
n
++
)
{
for
(
unsigned
n
=
0
;
n
<
ntohs
(
hdr
->
ancount
);
n
++
)
{
...
@@ -123,14 +125,14 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
...
@@ -123,14 +125,14 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
return
tmp
;
return
tmp
;
}
}
bufpos
+=
tmp
;
bufpos
+=
tmp
;
if
((
bufpos
+
2
+
2
+
4
)
>=
buflim
)
{
if
((
bufpos
+
RR_TYPE_LENGTH
+
RR_CLASS_LENGTH
+
RR_TTL_LENGTH
)
>=
buflim
)
{
return
-
EBADMSG
;
return
-
EBADMSG
;
}
}
uint16_t
_type
=
ntohs
(
_get_short
(
bufpos
));
uint16_t
_type
=
ntohs
(
_get_short
(
bufpos
));
bufpos
+=
2
;
bufpos
+=
RR_TYPE_LENGTH
;
uint16_t
class
=
ntohs
(
_get_short
(
bufpos
));
uint16_t
class
=
ntohs
(
_get_short
(
bufpos
));
bufpos
+=
2
;
bufpos
+=
RR_CLASS_LENGTH
;
bufpos
+=
4
;
/* skip ttl */
bufpos
+=
RR_TTL_LENGTH
;
/* skip ttl */
unsigned
addrlen
=
ntohs
(
_get_short
(
bufpos
));
unsigned
addrlen
=
ntohs
(
_get_short
(
bufpos
));
/* skip unwanted answers */
/* skip unwanted answers */
...
@@ -154,7 +156,7 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
...
@@ -154,7 +156,7 @@ static int _parse_dns_reply(uint8_t *buf, size_t len, void* addr_out, int family
(
family
==
AF_UNSPEC
)))
{
(
family
==
AF_UNSPEC
)))
{
return
-
EBADMSG
;
return
-
EBADMSG
;
}
}
bufpos
+=
2
;
bufpos
+=
RR_RDLENGTH_LENGTH
;
if
((
bufpos
+
addrlen
)
>=
buflim
)
{
if
((
bufpos
+
addrlen
)
>=
buflim
)
{
return
-
EBADMSG
;
return
-
EBADMSG
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment