diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-06-25 20:05:25 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-06-25 20:05:25 +0200 |
commit | f895f6c37937c17a73fa2b13211d2d52b94c79e5 (patch) | |
tree | 83bc5237fd6bedbd929a189b15884b57436db161 /src/util | |
parent | 2d22da9b531933db65f80ce12b11dd917a387eeb (diff) | |
download | gnunet-f895f6c37937c17a73fa2b13211d2d52b94c79e5.tar.gz gnunet-f895f6c37937c17a73fa2b13211d2d52b94c79e5.zip |
move hexcode, eliminate redundant test
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/dnsparser.c | 14 | ||||
-rw-r--r-- | src/util/test_hexcoder.c | 54 |
2 files changed, 62 insertions, 6 deletions
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c index 9ed7e4d0e..55475b131 100644 --- a/src/util/dnsparser.c +++ b/src/util/dnsparser.c | |||
@@ -698,7 +698,7 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
698 | if (n > 0) | 698 | if (n > 0) |
699 | { | 699 | { |
700 | p->queries = GNUNET_new_array (n, | 700 | p->queries = GNUNET_new_array (n, |
701 | struct GNUNET_DNSPARSER_Query) ; | 701 | struct GNUNET_DNSPARSER_Query); |
702 | p->num_queries = n; | 702 | p->num_queries = n; |
703 | for (unsigned int i=0;i<n;i++) | 703 | for (unsigned int i=0;i<n;i++) |
704 | if (GNUNET_OK != | 704 | if (GNUNET_OK != |
@@ -750,6 +750,7 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
750 | &off, | 750 | &off, |
751 | &p->additional_records[i])) | 751 | &p->additional_records[i])) |
752 | goto error; | 752 | goto error; |
753 | } | ||
753 | } | 754 | } |
754 | return p; | 755 | return p; |
755 | error: | 756 | error: |
@@ -957,7 +958,6 @@ GNUNET_DNSPARSER_builder_add_cert (char *dst, | |||
957 | struct GNUNET_TUN_DnsCertRecord dcert; | 958 | struct GNUNET_TUN_DnsCertRecord dcert; |
958 | 959 | ||
959 | if ( (cert->cert_type > UINT16_MAX) || | 960 | if ( (cert->cert_type > UINT16_MAX) || |
960 | (cert->cert_tag > UINT16_MAX) || | ||
961 | (cert->algorithm > UINT8_MAX) ) | 961 | (cert->algorithm > UINT8_MAX) ) |
962 | { | 962 | { |
963 | GNUNET_break (0); | 963 | GNUNET_break (0); |
@@ -1045,12 +1045,14 @@ GNUNET_DNSPARSER_builder_add_srv (char *dst, | |||
1045 | sd.prio = htons (srv->priority); | 1045 | sd.prio = htons (srv->priority); |
1046 | sd.weight = htons (srv->weight); | 1046 | sd.weight = htons (srv->weight); |
1047 | sd.port = htons (srv->port); | 1047 | sd.port = htons (srv->port); |
1048 | GNUNET_memcpy (&dst[*off], &sd, sizeof (sd)); | 1048 | GNUNET_memcpy (&dst[*off], |
1049 | &sd, | ||
1050 | sizeof (sd)); | ||
1049 | (*off) += sizeof (sd); | 1051 | (*off) += sizeof (sd); |
1050 | if (GNUNET_OK != (ret = GNUNET_DNSPARSER_builder_add_name (dst, | 1052 | if (GNUNET_OK != (ret = GNUNET_DNSPARSER_builder_add_name (dst, |
1051 | dst_len, | 1053 | dst_len, |
1052 | off, | 1054 | off, |
1053 | srv->target))) | 1055 | srv->target))) |
1054 | return ret; | 1056 | return ret; |
1055 | return GNUNET_OK; | 1057 | return GNUNET_OK; |
1056 | } | 1058 | } |
diff --git a/src/util/test_hexcoder.c b/src/util/test_hexcoder.c new file mode 100644 index 000000000..441d7e200 --- /dev/null +++ b/src/util/test_hexcoder.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2014 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | */ | ||
19 | /** | ||
20 | * @author Christian Grothoff | ||
21 | * @file dns/test_hexcoder.c | ||
22 | * @brief test for #GNUNET_DNSPARSER_hex_to_bin() and | ||
23 | * #GNUNET_DNSPARSER_bin_to_hex() | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_dnsparser_lib.h" | ||
28 | |||
29 | #define TESTSTRING "Hello World!" | ||
30 | |||
31 | |||
32 | int | ||
33 | main (int argc, | ||
34 | char *argv[]) | ||
35 | { | ||
36 | char buf[strlen (TESTSTRING) + 1]; | ||
37 | char *ret; | ||
38 | |||
39 | GNUNET_log_setup ("test-hexcoder", "WARNING", NULL); | ||
40 | ret = GNUNET_DNSPARSER_bin_to_hex (TESTSTRING, | ||
41 | strlen (TESTSTRING) + 1); | ||
42 | GNUNET_assert (NULL != ret); | ||
43 | GNUNET_assert (sizeof (buf) == | ||
44 | GNUNET_DNSPARSER_hex_to_bin (ret, | ||
45 | buf)); | ||
46 | GNUNET_assert (0 == memcmp (TESTSTRING, | ||
47 | buf, | ||
48 | sizeof (buf))); | ||
49 | GNUNET_free (ret); | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | |||
54 | /* end of test_hexcoder.c */ | ||