diff options
Diffstat (limited to 'src/lib/hello/address.c')
-rw-r--r-- | src/lib/hello/address.c | 139 |
1 files changed, 0 insertions, 139 deletions
diff --git a/src/lib/hello/address.c b/src/lib/hello/address.c deleted file mode 100644 index 6a1b68029..000000000 --- a/src/lib/hello/address.c +++ /dev/null | |||
@@ -1,139 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file hello/address.c | ||
23 | * @brief helper functions for handling addresses | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_hello_lib.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | |||
31 | /** | ||
32 | * Check if an address has a local option set | ||
33 | * | ||
34 | * @param address the address to check | ||
35 | * @param option the respective option to check for | ||
36 | * @return #GNUNET_YES or #GNUNET_NO | ||
37 | */ | ||
38 | int | ||
39 | GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address, | ||
40 | enum GNUNET_HELLO_AddressInfo option) | ||
41 | { | ||
42 | if (option == (address->local_info & option)) | ||
43 | return GNUNET_YES; | ||
44 | return GNUNET_NO; | ||
45 | } | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Get the size of an address struct. | ||
50 | * | ||
51 | * @param address address | ||
52 | * @return the size | ||
53 | */ | ||
54 | size_t | ||
55 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) | ||
56 | { | ||
57 | return sizeof(struct GNUNET_HELLO_Address) + address->address_length | ||
58 | + strlen (address->transport_name) + 1; | ||
59 | } | ||
60 | |||
61 | |||
62 | struct GNUNET_HELLO_Address * | ||
63 | GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | ||
64 | const char *transport_name, | ||
65 | const void *address, | ||
66 | size_t address_length, | ||
67 | enum GNUNET_HELLO_AddressInfo local_info) | ||
68 | { | ||
69 | struct GNUNET_HELLO_Address *addr; | ||
70 | size_t slen; | ||
71 | char *end; | ||
72 | |||
73 | slen = strlen (transport_name) + 1; | ||
74 | addr = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Address) | ||
75 | + address_length + slen); | ||
76 | addr->peer = *peer; | ||
77 | addr->address = &addr[1]; | ||
78 | addr->address_length = address_length; | ||
79 | addr->local_info = local_info; | ||
80 | end = (char *) &addr[1]; | ||
81 | addr->transport_name = &end[address_length]; | ||
82 | GNUNET_memcpy (end, | ||
83 | address, | ||
84 | address_length); | ||
85 | GNUNET_memcpy (&end[address_length], | ||
86 | transport_name, | ||
87 | slen); | ||
88 | return addr; | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Copy an address struct. | ||
94 | * | ||
95 | * @param address address to copy | ||
96 | * @return a copy of the address struct | ||
97 | */ | ||
98 | struct GNUNET_HELLO_Address * | ||
99 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) | ||
100 | { | ||
101 | if (NULL == address) | ||
102 | return NULL; | ||
103 | return GNUNET_HELLO_address_allocate (&address->peer, | ||
104 | address->transport_name, | ||
105 | address->address, | ||
106 | address->address_length, | ||
107 | address->local_info); | ||
108 | } | ||
109 | |||
110 | |||
111 | int | ||
112 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | ||
113 | const struct GNUNET_HELLO_Address *a2) | ||
114 | { | ||
115 | int ret; | ||
116 | |||
117 | if ((NULL == a1) && | ||
118 | (NULL == a2)) | ||
119 | return 0; | ||
120 | if (NULL == a1) | ||
121 | return 1; | ||
122 | if (NULL == a2) | ||
123 | return -1; | ||
124 | ret = strcmp (a1->transport_name, a2->transport_name); | ||
125 | if (0 != ret) | ||
126 | return ret; | ||
127 | if (a1->local_info != a2->local_info) | ||
128 | return (((int) a1->local_info) < ((int) a2->local_info)) ? -1 : 1; | ||
129 | if (a1->address_length < a2->address_length) | ||
130 | return -1; | ||
131 | if (a1->address_length > a2->address_length) | ||
132 | return 1; | ||
133 | return memcmp (a1->address, | ||
134 | a2->address, | ||
135 | a1->address_length); | ||
136 | } | ||
137 | |||
138 | |||
139 | /* end of address.c */ | ||