GNUnet  0.10.x
address.c
Go to the documentation of this file.
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 
26 #include "platform.h"
27 #include "gnunet_hello_lib.h"
28 #include "gnunet_util_lib.h"
29 
30 
38 int
41 {
42  if (option == (address->local_info & option))
43  return GNUNET_YES;
44  return GNUNET_NO;
45 }
46 
47 
54 size_t
56 {
57  return sizeof (struct GNUNET_HELLO_Address) + address->address_length +
58  strlen (address->transport_name) + 1;
59 }
60 
61 
72 struct GNUNET_HELLO_Address *
74  const char *transport_name,
75  const void *address,
76  size_t address_length,
78 {
79  struct GNUNET_HELLO_Address *addr;
80  size_t slen;
81  char *end;
82 
83  slen = strlen (transport_name) + 1;
84  addr = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) +
85  address_length + slen);
86  addr->peer = *peer;
87  addr->address = &addr[1];
89  addr->local_info = local_info;
90  end = (char *) &addr[1];
91  addr->transport_name = &end[address_length];
92  GNUNET_memcpy (end,
93  address,
94  address_length);
95  GNUNET_memcpy (&end[address_length],
96  transport_name,
97  slen);
98  return addr;
99 }
100 
101 
108 struct GNUNET_HELLO_Address *
110 {
111  if (NULL == address)
112  return NULL;
113  return GNUNET_HELLO_address_allocate (&address->peer,
114  address->transport_name,
115  address->address,
116  address->address_length,
117  address->local_info);
118 }
119 
120 
129 int
131  const struct GNUNET_HELLO_Address *a2)
132 {
133  int ret;
134 
135  if ( (NULL == a1) &&
136  (NULL == a2) )
137  return 0;
138  if (NULL == a1)
139  return 1;
140  if (NULL == a2)
141  return -1;
142  ret = strcmp (a1->transport_name, a2->transport_name);
143  if (0 != ret)
144  return ret;
145  if (a1->local_info != a2->local_info)
146  return (((int) a1->local_info) < ((int) a2->local_info)) ? -1 : 1;
147  if (a1->address_length < a2->address_length)
148  return -1;
149  if (a1->address_length > a2->address_length)
150  return 1;
151  return memcmp (a1->address,
152  a2->address,
153  a1->address_length);
154 }
155 
156 
157 /* end of address.c */
size_t address_length
Number of bytes in address.
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
const void * address
Binary representation of the address (plugin-specific).
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
#define GNUNET_NO
Definition: gnunet_common.h:81
static int ret
Final status code.
Definition: gnunet-arm.c:89
int GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address *address, enum GNUNET_HELLO_AddressInfo option)
Check if an address has a local option set.
Definition: address.c:39
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
#define GNUNET_memcpy(dst, src, n)
static char * option
Name of the option.
Definition: gnunet-config.c:38
const char * transport_name
Name of the transport plugin enabling the communication using this address.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
The identity of the host (wraps the signing key of the peer).
An address for communicating with a peer.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
size_t GNUNET_HELLO_address_get_size(const struct GNUNET_HELLO_Address *address)
Get the size of an address struct.
Definition: address.c:55
#define GNUNET_YES
Definition: gnunet_common.h:80
GNUNET_HELLO_AddressInfo
Additional local information about an address.
static char * address
GNS address for this phone.
#define GNUNET_malloc(size)
Wrapper around malloc.