summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-06-19 21:20:39 +0200
committerChristian Grothoff <christian@grothoff.org>2019-06-19 21:20:39 +0200
commit33e87eb7680148006b7c9fc8f89040ad104597ea (patch)
treebee7bf0101ddd39a1fdeaa2e33d88e52be04e288
parenta31cd73472ac1b4c899a6e1d7e53851c20677f7d (diff)
fix socket cmp, fix compiler warnings about unused args
-rw-r--r--src/nse/gnunet-nse.c38
-rw-r--r--src/nse/nse_api.c43
-rw-r--r--src/util/crypto_random.c84
-rw-r--r--src/util/gnunet-scrypt.c213
-rw-r--r--src/util/gnunet-uri.c84
-rw-r--r--src/util/test_common_logging_dummy.c59
-rw-r--r--src/util/tun.c163
7 files changed, 343 insertions, 341 deletions
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index bf2fe11c3..c8ffa152e 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -46,6 +46,7 @@ static int status;
static void
do_shutdown (void *cls)
{
+ (void) cls;
if (NULL != nse)
{
GNUNET_NSE_disconnect (nse);
@@ -65,12 +66,14 @@ do_shutdown (void *cls)
*/
static void
handle_estimate (void *cls,
- struct GNUNET_TIME_Absolute timestamp,
+ struct GNUNET_TIME_Absolute timestamp,
double estimate,
- double std_dev)
+ double std_dev)
{
+ (void) cls;
status = 0;
- FPRINTF (stdout, "%llu %f %f %f\n",
+ FPRINTF (stdout,
+ "%llu %f %f %f\n",
(unsigned long long) timestamp.abs_value_us,
GNUNET_NSE_log_estimate_to_n (estimate),
estimate,
@@ -92,11 +95,11 @@ run (void *cls,
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
- nse = GNUNET_NSE_connect (cfg,
- &handle_estimate,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
- NULL);
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
+ nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
@@ -106,22 +109,21 @@ run (void *cls,
* @return 0 on success
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
static struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
status = 1;
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc,
- argv,
- "gnunet-nse",
- gettext_noop
- ("Show network size estimates from NSE service."),
- options,
- &run, NULL))
+ argv,
+ "gnunet-nse",
+ gettext_noop (
+ "Show network size estimates from NSE service."),
+ options,
+ &run,
+ NULL))
return 2;
return status;
}
diff --git a/src/nse/nse_api.c b/src/nse/nse_api.c
index e9eaada93..259be75ed 100644
--- a/src/nse/nse_api.c
+++ b/src/nse/nse_api.c
@@ -32,7 +32,7 @@
#include "gnunet_nse_service.h"
#include "nse.h"
-#define LOG(kind,...) GNUNET_log_from (kind, "nse-api",__VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "nse-api", __VA_ARGS__)
/**
* Handle for talking with the NSE service.
@@ -68,7 +68,6 @@ struct GNUNET_NSE_Handle
* Closure to pass to @e recv_cb callback.
*/
void *recv_cb_cls;
-
};
@@ -91,17 +90,15 @@ reconnect (void *cls);
* @param error error code
*/
static void
-mq_error_handler (void *cls,
- enum GNUNET_MQ_Error error)
+mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
{
struct GNUNET_NSE_Handle *h = cls;
+ (void) error;
GNUNET_MQ_destroy (h->mq);
h->mq = NULL;
- h->reconnect_task
- = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay,
- &reconnect,
- h);
+ h->reconnect_task =
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
}
@@ -114,8 +111,7 @@ mq_error_handler (void *cls,
* @param client_msg message received
*/
static void
-handle_estimate (void *cls,
- const struct GNUNET_NSE_ClientMessage *client_msg)
+handle_estimate (void *cls, const struct GNUNET_NSE_ClientMessage *client_msg)
{
struct GNUNET_NSE_Handle *h = cls;
@@ -123,7 +119,7 @@ handle_estimate (void *cls,
h->recv_cb (h->recv_cb_cls,
GNUNET_TIME_absolute_ntoh (client_msg->timestamp),
GNUNET_ntoh_double (client_msg->size_estimate),
- GNUNET_ntoh_double (client_msg->std_deviation));
+ GNUNET_ntoh_double (client_msg->std_deviation));
}
@@ -136,13 +132,12 @@ static void
reconnect (void *cls)
{
struct GNUNET_NSE_Handle *h = cls;
- struct GNUNET_MQ_MessageHandler handlers[] = {
- GNUNET_MQ_hd_fixed_size (estimate,
- GNUNET_MESSAGE_TYPE_NSE_ESTIMATE,
- struct GNUNET_NSE_ClientMessage,
- h),
- GNUNET_MQ_handler_end ()
- };
+ struct GNUNET_MQ_MessageHandler handlers[] =
+ {GNUNET_MQ_hd_fixed_size (estimate,
+ GNUNET_MESSAGE_TYPE_NSE_ESTIMATE,
+ struct GNUNET_NSE_ClientMessage,
+ h),
+ GNUNET_MQ_handler_end ()};
struct GNUNET_MessageHeader *msg;
struct GNUNET_MQ_Envelope *env;
@@ -150,17 +145,11 @@ reconnect (void *cls)
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connecting to network size estimation service.\n");
GNUNET_assert (NULL == h->mq);
- h->mq = GNUNET_CLIENT_connect (h->cfg,
- "nse",
- handlers,
- &mq_error_handler,
- h);
+ h->mq = GNUNET_CLIENT_connect (h->cfg, "nse", handlers, &mq_error_handler, h);
if (NULL == h->mq)
return;
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_NSE_START);
- GNUNET_MQ_send (h->mq,
- env);
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NSE_START);
+ GNUNET_MQ_send (h->mq, env);
}
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 8bb5f0587..71eaab87a 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -28,22 +28,23 @@
#include "gnunet_crypto_lib.h"
#include <gcrypt.h>
-#define LOG(kind,...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__)
+#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-random", __VA_ARGS__)
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-crypto-random", syscall)
+#define LOG_STRERROR(kind, syscall) \
+ GNUNET_log_from_strerror (kind, "util-crypto-random", syscall)
/* TODO: ndurner, move this to plibc? */
/* The code is derived from glibc, obviously */
-#if !HAVE_RANDOM || !HAVE_SRANDOM
+#if ! HAVE_RANDOM || ! HAVE_SRANDOM
#ifdef RANDOM
#undef RANDOM
#endif
#ifdef SRANDOM
#undef SRANDOM
#endif
-#define RANDOM() glibc_weak_rand32()
-#define SRANDOM(s) glibc_weak_srand32(s)
+#define RANDOM() glibc_weak_rand32 ()
+#define SRANDOM(s) glibc_weak_srand32 (s)
#if defined(RAND_MAX)
#undef RAND_MAX
#endif
@@ -105,17 +106,12 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed)
* @param length buffer length
*/
void
-GNUNET_CRYPTO_zero_keys (void *buffer,
- size_t length)
+GNUNET_CRYPTO_zero_keys (void *buffer, size_t length)
{
#if HAVE_MEMSET_S
- memset_s (buffer,
- length,
- 0,
- length);
+ memset_s (buffer, length, 0, length);
#elif HAVE_EXPLICIT_BZERO
- explicit_bzero (buffer,
- length);
+ explicit_bzero (buffer, length);
#else
volatile unsigned char *p = buffer;
while (length--)
@@ -175,8 +171,7 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
* @return a random value in the interval [0,i[.
*/
uint32_t
-GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
- uint32_t i)
+GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
{
#ifdef gcry_fast_random_poll
static unsigned int invokeCount;
@@ -197,18 +192,17 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
ul = UINT32_MAX - (UINT32_MAX % i);
do
{
- gcry_randomize ((unsigned char *) &ret, sizeof (uint32_t),
+ gcry_randomize ((unsigned char *) &ret,
+ sizeof (uint32_t),
GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % i;
case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT32_MAX - (UINT32_MAX % i);
do
{
gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % i;
case GNUNET_CRYPTO_QUALITY_WEAK:
ret = i * get_weak_random ();
@@ -231,8 +225,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
* @return the permutation array (allocated from heap)
*/
unsigned int *
-GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
- unsigned int n)
+GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
{
unsigned int *ret;
unsigned int i;
@@ -262,8 +255,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
* @return random 64-bit number
*/
uint64_t
-GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
- uint64_t max)
+GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
{
uint64_t ret;
uint64_t ul;
@@ -275,18 +267,17 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
- gcry_randomize ((unsigned char *) &ret, sizeof (uint64_t),
+ gcry_randomize ((unsigned char *) &ret,
+ sizeof (uint64_t),
GCRY_STRONG_RANDOM);
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % max;
case GNUNET_CRYPTO_QUALITY_NONCE:
ul = UINT64_MAX - (UINT64_MAX % max);
do
{
gcry_create_nonce (&ret, sizeof (ret));
- }
- while (ret >= ul);
+ } while (ret >= ul);
return ret % max;
case GNUNET_CRYPTO_QUALITY_WEAK:
@@ -319,6 +310,7 @@ w_malloc (size_t n)
static int
w_check (const void *p)
{
+ (void) p;
return 0; /* not secure memory */
}
@@ -326,50 +318,45 @@ w_check (const void *p)
/**
* Initialize libgcrypt.
*/
-void __attribute__ ((constructor))
-GNUNET_CRYPTO_random_init ()
+void __attribute__ ((constructor)) GNUNET_CRYPTO_random_init ()
{
gcry_error_t rc;
if (! gcry_check_version (NEED_LIBGCRYPT_VERSION))
{
- FPRINTF (stderr,
- _("libgcrypt has not the expected version (version %s is required).\n"),
- NEED_LIBGCRYPT_VERSION);
+ FPRINTF (
+ stderr,
+ _ ("libgcrypt has not the expected version (version %s is required).\n"),
+ NEED_LIBGCRYPT_VERSION);
GNUNET_assert (0);
}
/* set custom allocators */
- gcry_set_allocation_handler (&w_malloc,
- &w_malloc,
- &w_check,
- &realloc,
- &free);
+ gcry_set_allocation_handler (&w_malloc, &w_malloc, &w_check, &realloc, &free);
/* Disable use of secure memory */
if ((rc = gcry_control (GCRYCTL_DISABLE_SECMEM, 0)))
FPRINTF (stderr,
"Failed to set libgcrypt option %s: %s\n",
"DISABLE_SECMEM",
- gcry_strerror (rc));
+ gcry_strerror (rc));
/* Otherwise gnunet-ecc takes forever to complete, besides
we are fine with "just" using GCRY_STRONG_RANDOM */
if ((rc = gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0)))
FPRINTF (stderr,
- "Failed to set libgcrypt option %s: %s\n",
- "ENABLE_QUICK_RANDOM",
- gcry_strerror (rc));
+ "Failed to set libgcrypt option %s: %s\n",
+ "ENABLE_QUICK_RANDOM",
+ gcry_strerror (rc));
gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);
gcry_fast_random_poll ();
- GNUNET_CRYPTO_seed_weak_random (time (NULL) ^
- GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
+ GNUNET_CRYPTO_seed_weak_random (
+ time (NULL) ^
+ GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
}
/**
* Nicely shut down libgcrypt.
*/
-void __attribute__ ((destructor))
-GNUNET_CRYPTO_random_fini ()
+void __attribute__ ((destructor)) GNUNET_CRYPTO_random_fini ()
{
gcry_set_progress_handler (NULL, NULL);
#ifdef GCRYCTL_CLOSE_RANDOM_DEVICE
@@ -378,5 +365,4 @@ GNUNET_CRYPTO_random_fini ()
}
-
/* end of crypto_random.c */
diff --git a/src/util/gnunet-scrypt.c b/src/util/gnunet-scrypt.c
index 5e15eb16a..f4149a398 100644
--- a/src/util/gnunet-scrypt.c
+++ b/src/util/gnunet-scrypt.c
@@ -57,15 +57,13 @@ static char *pwfn;
static void
shutdown_task (void *cls)
{
- if (sizeof (proof) !=
- GNUNET_DISK_fn_write (pwfn,
- &proof,
- sizeof (proof),
- GNUNET_DISK_PERM_USER_READ |
- GNUNET_DISK_PERM_USER_WRITE))
- GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
- "write",
- pwfn);
+ (void) cls;
+ if (sizeof (proof) != GNUNET_DISK_fn_write (pwfn,
+ &proof,
+ sizeof (proof),
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", pwfn);
}
@@ -77,17 +75,18 @@ shutdown_task (void *cls)
* @param result where to write the resulting hash
*/
static void
-pow_hash (const void *buf,
- size_t buf_len,
- struct GNUNET_HashCode *result)
+pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
{
- GNUNET_break (0 ==
- gcry_kdf_derive (buf, buf_len,
- GCRY_KDF_SCRYPT,
- 1 /* subalgo */,
- "gnunet-proof-of-work", strlen ("gnunet-proof-of-work"),
- 2 /* iterations; keep cost of individual op small */,
- sizeof (struct GNUNET_HashCode), result));
+ GNUNET_break (
+ 0 == gcry_kdf_derive (buf,
+ buf_len,
+ GCRY_KDF_SCRYPT,
+ 1 /* subalgo */,
+ "gnunet-proof-of-work",
+ strlen ("gnunet-proof-of-work"),
+ 2 /* iterations; keep cost of individual op small */,
+ sizeof (struct GNUNET_HashCode),
+ result));
}
@@ -118,7 +117,7 @@ count_leading_zeroes (const struct GNUNET_HashCode *hash)
static void
find_proof (void *cls)
{
- #define ROUND_SIZE 10
+#define ROUND_SIZE 10
uint64_t counter;
char buf[sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
sizeof (uint64_t)] GNUNET_ALIGN;
@@ -127,12 +126,14 @@ find_proof (void *cls)
struct GNUNET_TIME_Absolute timestamp;
struct GNUNET_TIME_Relative elapsed;
+ (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got Proof of Work %llu\n",
- (unsigned long long) proof);
+ "Got Proof of Work %llu\n",
+ (unsigned long long) proof);
proof_task = NULL;
- GNUNET_memcpy (&buf[sizeof (uint64_t)], &pub,
- sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
+ GNUNET_memcpy (&buf[sizeof (uint64_t)],
+ &pub,
+ sizeof (struct GNUNET_CRYPTO_EddsaPublicKey));
i = 0;
counter = proof;
timestamp = GNUNET_TIME_absolute_get ();
@@ -143,7 +144,8 @@ find_proof (void *cls)
if (nse_work_required <= count_leading_zeroes (&result))
{
proof = counter;
- FPRINTF (stdout, "Proof of work found: %llu!\n",
+ FPRINTF (stdout,
+ "Proof of work found: %llu!\n",
(unsigned long long) proof);
GNUNET_SCHEDULER_shutdown ();
return;
@@ -159,7 +161,8 @@ find_proof (void *cls)
GNUNET_STRINGS_relative_time_to_string (elapsed, 0));
if (proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing proofs currently at %llu\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Testing proofs currently at %llu\n",
(unsigned long long) counter);
/* remember progress every 100 rounds */
proof = counter;
@@ -171,8 +174,9 @@ find_proof (void *cls)
}
proof_task =
GNUNET_SCHEDULER_add_delayed_with_priority (proof_find_delay,
- GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof, NULL);
+ GNUNET_SCHEDULER_PRIORITY_IDLE,
+ &find_proof,
+ NULL);
}
@@ -193,54 +197,46 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
char *pids;
+ (void) cls;
+ (void) args;
+ (void) cfgfile;
cfg = config;
/* load proof of work */
if (NULL == pwfn)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "NSE",
- "PROOFFILE",
- &pwfn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "NSE",
+ "PROOFFILE",
+ &pwfn))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "PROOFFILE");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE");
GNUNET_SCHEDULER_shutdown ();
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Proof of Work file: %s\n",
- pwfn);
- if ( (GNUNET_YES != GNUNET_DISK_file_test (pwfn)) ||
- (sizeof (proof) !=
- GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof))))
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Proof of Work file: %s\n", pwfn);
+ if ((GNUNET_YES != GNUNET_DISK_file_test (pwfn)) ||
+ (sizeof (proof) != GNUNET_DISK_fn_read (pwfn, &proof, sizeof (proof))))
proof = 0;
/* load private key */
if (NULL == pkfn)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "PEER",
- "PRIVATE_KEY",
- &pkfn))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
+ "PEER",
+ "PRIVATE_KEY",
+ &pkfn))
{
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"PEER",
- "PRIVATE_KEY");
+ "PRIVATE_KEY");
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Private Key file: %s\n",
- pkfn);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Private Key file: %s\n", pkfn);
if (NULL == (pk = GNUNET_CRYPTO_eddsa_key_create_from_file (pkfn)))
{
- FPRINTF (stderr,
- _("Loading hostkey from `%s' failed.\n"),
- pkfn);
+ FPRINTF (stderr, _ ("Loading hostkey from `%s' failed.\n"), pkfn);
GNUNET_free (pkfn);
return;
}
@@ -248,32 +244,27 @@ run (void *cls,
GNUNET_CRYPTO_eddsa_key_get_public (pk, &pub);
GNUNET_free (pk);
pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pub);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Peer ID: %s\n",
- pids);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer ID: %s\n", pids);
GNUNET_free (pids);
/* get target bit amount */
if (0 == nse_work_required)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number (cfg,
- "NSE",
- "WORKBITS",
- &nse_work_required))
+ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
+ "NSE",
+ "WORKBITS",
+ &nse_work_required))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS");
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKBITS");
GNUNET_SCHEDULER_shutdown ();
return;
}
if (nse_work_required >= sizeof (struct GNUNET_HashCode) * 8)
{
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "NSE",
- "WORKBITS",
- _("Value is too large.\n"));
+ "NSE",
+ "WORKBITS",
+ _ ("Value is too large.\n"));
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -283,19 +274,16 @@ run (void *cls,
return;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Bits: %llu\n",
- nse_work_required);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Bits: %llu\n", nse_work_required);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Delay between tries: %s\n",
GNUNET_STRINGS_relative_time_to_string (proof_find_delay, 1));
proof_task =
GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
- &find_proof,
- NULL);
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- NULL);
+ &find_proof,
+ NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}
@@ -307,46 +295,51 @@ run (void *cls,
* @return 0 ok, 1 on error
*/
int
-main (int argc,
- char *const *argv)
+main (int argc, char *const *argv)
{
- struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_option_ulong ('b',
- "bits",
- "BITS",
- gettext_noop ("number of bits to require for the proof of work"),
- &nse_work_required),
- GNUNET_GETOPT_option_filename ('k',
- "keyfile",
- "FILE",
- gettext_noop ("file with private key, otherwise default is used"),
- &pkfn),
- GNUNET_GETOPT_option_filename ('o',
- "outfile",
- "FILE",
- gettext_noop ("file with proof of work, otherwise default is used"),
- &pwfn),
- GNUNET_GETOPT_option_relative_time ('t',
- "timeout",
- "TIME",
- gettext_noop ("time to wait between calculations"),
- &proof_find_delay),
- GNUNET_GETOPT_OPTION_END
- };
+ struct GNUNET_GETOPT_CommandLineOption options[] =
+ {GNUNET_GETOPT_option_ulong (
+ 'b',
+ "bits",
+ "BITS",
+ gettext_noop ("number of bits to require for the proof of work"),
+ &nse_work_required),
+ GNUNET_GETOPT_option_filename (
+ 'k',
+ "keyfile",
+ "FILE",
+ gettext_noop ("file with private key, otherwise default is used"),
+ &pkfn),
+ GNUNET_GETOPT_option_filename (
+ 'o',
+ "outfile",
+ "FILE",
+ gettext_noop ("file with proof of work, otherwise default is used"),
+ &pwfn),
+ GNUNET_GETOPT_option_relative_time ('t',
+ "timeout",
+ "TIME",
+ gettext_noop (
+ "time to wait between calculations"),
+ &proof_find_delay),
+ GNUNET_GETOPT_OPTION_END};
int ret;
- if (GNUNET_OK !=
- GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run (argc, argv,
- "gnunet-scrypt [OPTIONS] prooffile",
- gettext_noop ("Manipulate GNUnet proof of work files"),
- options,
- &run,
- NULL)) ? 0 : 1;
- GNUNET_free ((void*) argv);
+ ret =
+ (GNUNET_OK ==
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-scrypt [OPTIONS] prooffile",
+ gettext_noop ("Manipulate GNUnet proof of work files"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free ((void *) argv);
GNUNET_free_non_null (pwfn);
return ret;
}
diff --git a/src/util/gnunet-uri.c b/src/util/gnunet-uri.c
index 58f9e331c..33ff7b1e6 100644
--- a/src/util/gnunet-uri.c
+++ b/src/util/gnunet-uri.c
@@ -53,9 +53,9 @@ maint_child_death (void *cls)
{
enum GNUNET_OS_ProcessStatusType type;
- if ( (GNUNET_OK !=
- GNUNET_OS_process_status (p, &type, &exit_code)) ||
- (type != GNUNET_OS_PROCESS_EXITED) )
+ (void) cls;
+ if ((GNUNET_OK != GNUNET_OS_process_status (p, &type, &exit_code)) ||
+ (type != GNUNET_OS_PROCESS_EXITED))
GNUNET_break (0 == GNUNET_OS_process_kill (p, GNUNET_TERM_SIG));
GNUNET_OS_process_destroy (p);
}
@@ -70,56 +70,60 @@ maint_child_death (void *cls)
* @param cfg configuration
*/
static void
-run (void *cls, char *const *args, const char *cfgfile,
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
const char *uri;
const char *slash;
char *subsystem;
char *program;
- struct GNUNET_SCHEDULER_Task * rt;
+ struct GNUNET_SCHEDULER_Task *rt;
+ (void) cls;
+ (void) cfgfile;
if (NULL == (uri = args[0]))
{
- fprintf (stderr,
- _("No URI specified on command line\n"));
+ fprintf (stderr, _ ("No URI specified on command line\n"));
return;
}
if (0 != strncasecmp ("gnunet://", uri, strlen ("gnunet://")))
{
fprintf (stderr,
- _("Invalid URI: does not start with `%s'\n"),
- "gnunet://");
+ _ ("Invalid URI: does not start with `%s'\n"),
+ "gnunet://");
return;
}
uri += strlen ("gnunet://");
if (NULL == (slash = strchr (uri, '/')))
{
- fprintf (stderr, _("Invalid URI: fails to specify subsystem\n"));
+ fprintf (stderr, _ ("Invalid URI: fails to specify subsystem\n"));
return;
}
subsystem = GNUNET_strndup (uri, slash - uri);
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "uri",
- subsystem,
- &program))
+ GNUNET_CONFIGURATION_get_value_string (cfg, "uri", subsystem, &program))
{
- fprintf (stderr, _("No handler known for subsystem `%s'\n"), subsystem);
+ fprintf (stderr, _ ("No handler known for subsystem `%s'\n"), subsystem);
GNUNET_free (subsystem);
return;
}
GNUNET_free (subsystem);
- rt = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_DISK_pipe_handle (sigpipe,
- GNUNET_DISK_PIPE_END_READ),
- &maint_child_death, NULL);
- p = GNUNET_OS_start_process (GNUNET_NO, 0,
- NULL, NULL, NULL,
- program,
- program,
- args[0],
- NULL);
+ rt = GNUNET_SCHEDULER_add_read_file (
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
+ &maint_child_death,
+ NULL);
+ p = GNUNET_OS_start_process (GNUNET_NO,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ program,
+ program,
+ args[0],
+ NULL);
GNUNET_free (program);
if (NULL == p)
GNUNET_SCHEDULER_cancel (rt);
@@ -134,13 +138,15 @@ static void
sighandler_child_death ()
{
static char c;
- int old_errno = errno; /* back-up errno */
-
- GNUNET_break (1 ==
- GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
- (sigpipe, GNUNET_DISK_PIPE_END_WRITE),
- &c, sizeof (c)));
- errno = old_errno; /* restore errno */
+ int old_errno = errno; /* back-up errno */
+
+ GNUNET_break (
+ 1 ==
+ GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe,
+ GNUNET_DISK_PIPE_END_WRITE),
+ &c,
+ sizeof (c)));
+ errno = old_errno; /* restore errno */
}
@@ -155,8 +161,7 @@ int
main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- GNUNET_GETOPT_OPTION_END
- };
+ GNUNET_GETOPT_OPTION_END};
struct GNUNET_SIGNAL_Context *shc_chld;
int ret;
@@ -166,9 +171,14 @@ main (int argc, char *const *argv)
GNUNET_assert (sigpipe != NULL);
shc_chld =
GNUNET_SIGNAL_handler_install (GNUNET_SIGCHLD, &sighandler_child_death);
- ret = GNUNET_PROGRAM_run (argc, argv, "gnunet-uri URI",
- gettext_noop ("Perform default-actions for GNUnet URIs"),
- options, &run, NULL);
+ ret = GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-uri URI",
+ gettext_noop (
+ "Perform default-actions for GNUnet URIs"),
+ options,
+ &run,
+ NULL);
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
GNUNET_DISK_pipe_close (sigpipe);
diff --git a/src/util/test_common_logging_dummy.c b/src/util/test_common_logging_dummy.c
index b8f2bef91..5c3709206 100644
--- a/src/util/test_common_logging_dummy.c
+++ b/src/util/test_common_logging_dummy.c
@@ -35,12 +35,20 @@
* This must be long enough for us to not to mistake skipped log call
* on a slow machine for a non-skipped one.
*/
-#define OUTPUT_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
+#define OUTPUT_DELAY \
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, 1000)
static void
-my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
- const char *date, const char *msg)
+my_log (void *ctx,
+ enum GNUNET_ErrorType kind,
+ const char *component,
+ const char *date,
+ const char *msg)
{
+ (void) ctx;
+ (void) kind;
+ (void) component;
+ (void) date;
if (strncmp ("test-common-logging-dummy", component, 25) != 0)
return;
FPRINTF (stdout, "%s", msg);
@@ -48,7 +56,7 @@ my_log (void *ctx, enum GNUNET_ErrorType kind, const char *component,
}
-#if !defined(GNUNET_CULL_LOGGING)
+#if ! defined(GNUNET_CULL_LOGGING)
static int
expensive_func ()
{
@@ -57,27 +65,36 @@ expensive_func ()
#endif
-#define pr(kind,lvl) {\
- struct GNUNET_TIME_Absolute t1, t2;\
- t1 = GNUNET_TIME_absolute_get ();\
- GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
- t2 = GNUNET_TIME_absolute_get ();\
- printf ("1%s %llu\n", lvl,\
- (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
-}
+#define pr(kind, lvl) \
+ { \
+ struct GNUNET_TIME_Absolute t1, t2; \
+ t1 = GNUNET_TIME_absolute_get (); \
+ GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
+ t2 = GNUNET_TIME_absolute_get (); \
+ printf ("1%s %llu\n", \
+ lvl, \
+ (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
+ .rel_value_us); \
+ }
+
+#define pr2(kind, lvl) \
+ { \
+ struct GNUNET_TIME_Absolute t1, t2; \
+ t1 = GNUNET_TIME_absolute_get (); \
+ GNUNET_log (kind, "L%s %d\n", lvl, expensive_func ()); \
+ t2 = GNUNET_TIME_absolute_get (); \
+ printf ("2%s %llu\n", \
+ lvl, \
+ (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2) \
+ .rel_value_us); \
+ }
-#define pr2(kind,lvl) {\
- struct GNUNET_TIME_Absolute t1, t2;\
- t1 = GNUNET_TIME_absolute_get ();\
- GNUNET_log (kind, "L%s %d\n", lvl, expensive_func());\
- t2 = GNUNET_TIME_absolute_get ();\
- printf ("2%s %llu\n", lvl,\
- (unsigned long long) GNUNET_TIME_absolute_get_difference (t1, t2).rel_value_us); \
-}
int
main (int argc, char *argv[])
{
+ (void) argc;
+ (void) argv;
/* We set up logging with NULL level - will be overrided by
* GNUNET_LOG or GNUNET_FORCE_LOG at runtime.
*/
@@ -97,6 +114,6 @@ main (int argc, char *argv[])
pr2 (GNUNET_ERROR_TYPE_INFO, "INFO");
pr2 (GNUNET_ERROR_TYPE_DEBUG, "DEBUG");
return 0;
-} /* end of main */
+} /* end of main */
/* end of test_common_logging_dummy.c */
diff --git a/src/util/tun.c b/src/util/tun.c
index 97fbaa83b..e3643d0c6 100644
--- a/src/util/tun.c
+++ b/src/util/tun.c
@@ -44,24 +44,27 @@
*/
void
GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
- uint8_t protocol,
- uint16_t payload_length,
- const struct in_addr *src,
- const struct in_addr *dst)
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in_addr *src,
+ const struct in_addr *dst)
{
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_IPv4Header));
- GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
+ GNUNET_assert (payload_length <=
+ UINT16_MAX - sizeof (struct GNUNET_TUN_IPv4Header));
memset (ip, 0, sizeof (struct GNUNET_TUN_IPv4Header));
- ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
+ ip->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
ip->version = 4;
- ip->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length);
- ip->identification = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- 65536);
+ ip->total_length =
+ htons (sizeof (struct GNUNET_TUN_IPv4Header) + payload_length);
+ ip->identification =
+ (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 65536);
ip->ttl = FRESH_TTL;
ip->protocol = protocol;
ip->source_address = *src;
ip->destination_address = *dst;
- ip->checksum = GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header));
+ ip->checksum =
+ GNUNET_CRYPTO_crc16_n (ip, sizeof (struct GNUNET_TUN_IPv4Header));
}
@@ -76,13 +79,14 @@ GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
- uint8_t protocol,
- uint16_t payload_length,
- const struct in6_addr *src,
- const struct in6_addr *dst)
+ uint8_t protocol,
+ uint16_t payload_length,
+ const struct in6_addr *src,
+ const struct in6_addr *dst)
{
GNUNET_assert (40 == sizeof (struct GNUNET_TUN_IPv6Header));
- GNUNET_assert (payload_length <= UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
+ GNUNET_assert (payload_length <=
+ UINT16_MAX - sizeof (struct GNUNET_TUN_IPv6Header));
memset (ip, 0, sizeof (struct GNUNET_TUN_IPv6Header));
ip->version = 6;
ip->next_header = protocol;
@@ -103,27 +107,29 @@ GNUNET_TUN_initialize_ipv6_header (struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
- struct GNUNET_TUN_TcpHeader *tcp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_TcpHeader *tcp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint16_t tmp;
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
- GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_TcpHeader) ==
- ntohs (ip->total_length));
+ GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) +
+ sizeof (struct GNUNET_TUN_TcpHeader) ==
+ ntohs (ip->total_length));
GNUNET_assert (IPPROTO_TCP == ip->protocol);
tcp->crc = 0;
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in_addr) * 2);
+ &ip->source_address,
+ sizeof (struct in_addr) * 2);
tmp = htons (IPPROTO_TCP);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
tmp = htons (payload_length + sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -139,25 +145,27 @@ GNUNET_TUN_calculate_tcp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
- struct GNUNET_TUN_TcpHeader *tcp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_TcpHeader *tcp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint32_t tmp;
GNUNET_assert (20 == sizeof (struct GNUNET_TUN_TcpHeader));
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_TcpHeader) ==
- ntohs (ip->payload_length));
+ ntohs (ip->payload_length));
GNUNET_assert (IPPROTO_TCP == ip->next_header);
tcp->crc = 0;
- sum = GNUNET_CRYPTO_crc16_step (0, &ip->source_address, 2 * sizeof (struct in6_addr));
+ sum = GNUNET_CRYPTO_crc16_step (0,
+ &ip->source_address,
+ 2 * sizeof (struct in6_addr));
tmp = htonl (sizeof (struct GNUNET_TUN_TcpHeader) + payload_length);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
tmp = htonl (IPPROTO_TCP);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, tcp,
- sizeof (struct GNUNET_TUN_TcpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, tcp, sizeof (struct GNUNET_TUN_TcpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
tcp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -173,36 +181,31 @@ GNUNET_TUN_calculate_tcp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
- struct GNUNET_TUN_UdpHeader *udp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_UdpHeader *udp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint16_t tmp;
GNUNET_assert (8 == sizeof (struct GNUNET_TUN_UdpHeader));
- GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (ip->total_length));
+ GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_IPv4Header) +
+ sizeof (struct GNUNET_TUN_UdpHeader) ==
+ ntohs (ip->total_length));
GNUNET_assert (IPPROTO_UDP == ip->protocol);
- udp->crc = 0; /* technically optional, but we calculate it anyway, just to be sure */
+ udp->crc =
+ 0; /* technically optional, but we calculate it anyway, just to be sure */
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in_addr) * 2);
+ &ip->source_address,
+ sizeof (struct in_addr) * 2);
tmp = htons (IPPROTO_UDP);
- sum = GNUNET_CRYPTO_crc16_step (sum,
- &tmp,
- sizeof (uint16_t));
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length);
- sum = GNUNET_CRYPTO_crc16_step (sum,
- &tmp,
- sizeof (uint16_t));
- sum = GNUNET_CRYPTO_crc16_step (sum,
- udp,
- sizeof (struct GNUNET_TUN_UdpHeader));
- sum = GNUNET_CRYPTO_crc16_step (sum,
- payload,
- payload_length);
+ sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint16_t));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
+ sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -217,28 +220,30 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
*/
void
GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
- struct GNUNET_TUN_UdpHeader *udp,
- const void *payload,
- uint16_t payload_length)
+ struct GNUNET_TUN_UdpHeader *udp,
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
uint32_t tmp;
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (ip->payload_length));
+ ntohs (ip->payload_length));
GNUNET_assert (payload_length + sizeof (struct GNUNET_TUN_UdpHeader) ==
- ntohs (udp->len));
+ ntohs (udp->len));
GNUNET_assert (IPPROTO_UDP == ip->next_header);
udp->crc = 0;
sum = GNUNET_CRYPTO_crc16_step (0,
- &ip->source_address,
- sizeof (struct in6_addr) * 2);
- tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) + payload_length); /* aka udp->len */
+ &ip->source_address,
+ sizeof (struct in6_addr) * 2);
+ tmp = htons (sizeof (struct GNUNET_TUN_UdpHeader) +
+ payload_length); /* aka udp->len */
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
tmp = htons (ip->next_header);
sum = GNUNET_CRYPTO_crc16_step (sum, &tmp, sizeof (uint32_t));
- sum = GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (sum, udp, sizeof (struct GNUNET_TUN_UdpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
udp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -253,16 +258,15 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
*/
void
GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
- const void *payload,
- uint16_t payload_length)
+ const void *payload,
+ uint16_t payload_length)
{
uint32_t sum;
GNUNET_assert (8 == sizeof (struct GNUNET_TUN_IcmpHeader));
icmp->crc = 0;
- sum = GNUNET_CRYPTO_crc16_step (0,
- icmp,
- sizeof (struct GNUNET_TUN_IcmpHeader));
+ sum =
+ GNUNET_CRYPTO_crc16_step (0, icmp, sizeof (struct GNUNET_TUN_IcmpHeader));
sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
icmp->crc = GNUNET_CRYPTO_crc16_finish (sum);
}
@@ -286,21 +290,22 @@ GNUNET_TUN_sockaddr_cmp (const struct sockaddr *sa,
switch (sa->sa_family)
{
- case AF_INET:
- {
- const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
- const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
- return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
- }
- case AF_INET6:
- {
- const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
- const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
-
- return (0 == memcmp(&sa6->sin6_addr,
- &sb6->sin6_addr,
- sizeof (struct in6_addr)));
- }
+ case AF_INET: {
+ const struct sockaddr_in *sa4 = (const struct sockaddr_in *) sa;
+ const struct sockaddr_in *sb4 = (const struct sockaddr_in *) sb;
+ if ((include_port) && (sa4->sin_port != sb4->sin_port))
+ return GNUNET_NO;
+ return (sa4->sin_addr.s_addr == sb4->sin_addr.s_addr);
+ }
+ case AF_INET6: {
+ const struct sockaddr_in6 *sa6 = (const struct sockaddr_in6 *) sa;
+ const struct sockaddr_in6 *sb6 = (const struct sockaddr_in6 *) sb;
+
+ if ((include_port) && (sa6->sin6_port != sb6->sin6_port))
+ return GNUNET_NO;
+ return (
+ 0 == memcmp (&sa6->sin6_addr, &sb6->sin6_addr, sizeof (struct in6_addr)));
+ }
default:
GNUNET_break (0);
return GNUNET_SYSERR;