aboutsummaryrefslogtreecommitdiff
path: root/src/hello/address.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-13 00:12:35 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-13 00:12:35 +0000
commit4242db96e6e4dc394cc2d325aff0ec24b8750b50 (patch)
tree2c215d4dcb46afde56a05882fa981a4ec52c0910 /src/hello/address.c
parent3e693f3ceb1b3425b17900423628aecb609f2433 (diff)
downloadgnunet-4242db96e6e4dc394cc2d325aff0ec24b8750b50.tar.gz
gnunet-4242db96e6e4dc394cc2d325aff0ec24b8750b50.zip
-fix
Diffstat (limited to 'src/hello/address.c')
-rw-r--r--src/hello/address.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/src/hello/address.c b/src/hello/address.c
index c159540bb..36f376d5c 100644
--- a/src/hello/address.c
+++ b/src/hello/address.c
@@ -33,17 +33,18 @@
33 * 33 *
34 * @param address the address to check 34 * @param address the address to check
35 * @param option the respective option to check for 35 * @param option the respective option to check for
36 * @return GNUNET_YES or GNUNET_NO 36 * @return #GNUNET_YES or #GNUNET_NO
37 */ 37 */
38int 38int
39GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address * address, 39GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address * address,
40 enum GNUNET_HELLO_AddressInfo option) 40 enum GNUNET_HELLO_AddressInfo option)
41{ 41{
42 if (option == (address->local_info & option)) 42 if (option == (address->local_info & option))
43 return GNUNET_YES; 43 return GNUNET_YES;
44 return GNUNET_NO; 44 return GNUNET_NO;
45} 45}
46 46
47
47/** 48/**
48 * Get the size of an address struct. 49 * Get the size of an address struct.
49 * 50 *
@@ -54,7 +55,7 @@ size_t
54GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address * address) 55GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address * address)
55{ 56{
56 return sizeof (struct GNUNET_HELLO_Address) + address->address_length + 57 return sizeof (struct GNUNET_HELLO_Address) + address->address_length +
57 strlen (address->transport_name) + 1; 58 strlen (address->transport_name) + 1;
58} 59}
59 60
60 61
@@ -70,7 +71,8 @@ GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address * address)
70 */ 71 */
71struct GNUNET_HELLO_Address * 72struct GNUNET_HELLO_Address *
72GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, 73GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
73 const char *transport_name, const void *address, 74 const char *transport_name,
75 const void *address,
74 size_t address_length, 76 size_t address_length,
75 enum GNUNET_HELLO_AddressInfo local_info) 77 enum GNUNET_HELLO_AddressInfo local_info)
76{ 78{
@@ -78,20 +80,21 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
78 size_t slen; 80 size_t slen;
79 char *end; 81 char *end;
80 82
81 GNUNET_assert (transport_name != NULL);
82
83 slen = strlen (transport_name) + 1; 83 slen = strlen (transport_name) + 1;
84 addr = 84 addr = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) +
85 GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) + address_length + 85 address_length + slen);
86 slen);
87 addr->peer = *peer; 86 addr->peer = *peer;
88 addr->address = &addr[1]; 87 addr->address = &addr[1];
89 end = (char *) &addr[1];
90 memcpy (end, address, address_length);
91 addr->address_length = address_length; 88 addr->address_length = address_length;
92 addr->transport_name = &end[address_length];
93 addr->local_info = local_info; 89 addr->local_info = local_info;
94 memcpy (&end[address_length], transport_name, slen); 90 end = (char *) &addr[1];
91 addr->transport_name = &end[address_length];
92 memcpy (end,
93 address,
94 address_length);
95 memcpy (&end[address_length],
96 transport_name,
97 slen);
95 return addr; 98 return addr;
96} 99}
97 100
@@ -105,7 +108,8 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
105struct GNUNET_HELLO_Address * 108struct GNUNET_HELLO_Address *
106GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) 109GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address)
107{ 110{
108 return GNUNET_HELLO_address_allocate (&address->peer, address->transport_name, 111 return GNUNET_HELLO_address_allocate (&address->peer,
112 address->transport_name,
109 address->address, 113 address->address,
110 address->address_length, 114 address->address_length,
111 address->local_info); 115 address->local_info);