GNUnet  0.19.2
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
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 
54 size_t
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 *
64  const char *transport_name,
65  const void *address,
66  size_t address_length,
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];
79  addr->local_info = local_info;
80  end = (char *) &addr[1];
83  address,
87  slen);
88  return addr;
89 }
90 
91 
98 struct GNUNET_HELLO_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
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 */
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static int end
Set if we are to shutdown all services (including ARM).
Definition: gnunet-arm.c:34
static char * address
GNS address for this phone.
Helper library for handling HELLOs.
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:63
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:99
size_t GNUNET_HELLO_address_get_size(const struct GNUNET_HELLO_Address *address)
Get the size of an address struct.
Definition: address.c:55
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
GNUNET_HELLO_AddressInfo
Additional local information about an address.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:112
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_malloc(size)
Wrapper around malloc.
An address for communicating with a peer.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
size_t address_length
Number of bytes in address.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
const void * address
Binary representation of the address (plugin-specific).
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.