From d0051cb6683c712cce3473d6b667208e4f61b75a Mon Sep 17 00:00:00 2001 From: ng0 Date: Fri, 6 Sep 2019 23:01:06 +0000 Subject: plibc, commit 2 --- src/hostlist/gnunet-daemon-hostlist_client.c | 530 +++++++++++---------- src/mysql/mysql.c | 2 +- src/nat-auto/gnunet-nat-auto_legacy.c | 208 ++++---- src/transport/gnunet-helper-transport-wlan-dummy.c | 128 ++--- src/transport/gnunet-transport-wlan-receiver.c | 42 +- src/transport/gnunet-transport-wlan-sender.c | 127 ++--- 6 files changed, 527 insertions(+), 510 deletions(-) diff --git a/src/hostlist/gnunet-daemon-hostlist_client.c b/src/hostlist/gnunet-daemon-hostlist_client.c index 539760966..0428e64b8 100644 --- a/src/hostlist/gnunet-daemon-hostlist_client.c +++ b/src/hostlist/gnunet-daemon-hostlist_client.c @@ -34,7 +34,6 @@ #include "gnunet_curl_lib.h" - /** * Number of connections that we must have to NOT download * hostlists anymore. @@ -49,17 +48,20 @@ /** * Time interval hostlists are saved to disk */ -#define SAVING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) +#define SAVING_INTERVAL \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) /** * Time interval between two hostlist tests */ -#define TESTING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) +#define TESTING_INTERVAL \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) /** * Time interval for download dispatcher before a download is re-scheduled */ -#define WAITING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) +#define WAITING_INTERVAL \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) /** * Defines concerning the hostlist quality metric @@ -86,7 +88,6 @@ #define HOSTLIST_SUCCESSFUL_HELLO 1 - /** * A single hostlist obtained by hostlist advertisements */ @@ -136,7 +137,6 @@ struct Hostlist * Number of times the hostlist was successfully obtained */ uint32_t times_used; - }; @@ -321,10 +321,7 @@ static struct GNUNET_PEERINFO_Handle *pi; * @return number of bytes that were processed (always size*nmemb) */ static size_t -callback_download (void *ptr, - size_t size, - size_t nmemb, - void *ctx) +callback_download (void *ptr, size_t size, size_t nmemb, void *ctx) { static char download_buffer[GNUNET_MAX_MESSAGE_SIZE - 1]; const char *cbuf = ptr; @@ -338,13 +335,14 @@ callback_download (void *ptr, stat_bytes_downloaded += total; if ((total == 0) || (stat_bogus_url)) { - return total; /* ok, no data or bogus data */ + return total; /* ok, no data or bogus data */ } GNUNET_STATISTICS_update (stats, - gettext_noop - ("# bytes downloaded from hostlist servers"), - (int64_t) total, GNUNET_NO); + gettext_noop ( + "# bytes downloaded from hostlist servers"), + (int64_t) total, + GNUNET_NO); left = total; while ((left > 0) || (download_pos > 0)) { @@ -362,13 +360,15 @@ callback_download (void *ptr, msize = ntohs (msg->size); if (msize < sizeof (struct GNUNET_MessageHeader)) { - GNUNET_STATISTICS_update (stats, - gettext_noop - ("# invalid HELLOs downloaded from hostlist servers"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Invalid `%s' message received from hostlist at `%s'\n"), - "HELLO", current_url); + _ ("Invalid `%s' message received from hostlist at `%s'\n"), + "HELLO", + current_url); stat_hellos_obtained++; stat_bogus_url = 1; return total; @@ -383,32 +383,34 @@ callback_download (void *ptr, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received valid `%s' message from hostlist server.\n", "HELLO"); - GNUNET_STATISTICS_update (stats, - gettext_noop - ("# valid HELLOs downloaded from hostlist servers"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# valid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); stat_hellos_obtained++; - (void) GNUNET_PEERINFO_add_peer (pi, - (const struct GNUNET_HELLO_Message *) msg, - NULL, - NULL); + (void) + GNUNET_PEERINFO_add_peer (pi, + (const struct GNUNET_HELLO_Message *) msg, + NULL, + NULL); } else { - GNUNET_STATISTICS_update (stats, - gettext_noop - ("# invalid HELLOs downloaded from hostlist servers"), - 1, GNUNET_NO); + GNUNET_STATISTICS_update ( + stats, + gettext_noop ("# invalid HELLOs downloaded from hostlist servers"), + 1, + GNUNET_NO); GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Invalid `%s' message received from hostlist at `%s'\n"), - "HELLO", current_url); + _ ("Invalid `%s' message received from hostlist at `%s'\n"), + "HELLO", + current_url); stat_bogus_url = GNUNET_YES; stat_hellos_obtained++; return total; } - memmove (download_buffer, - &download_buffer[msize], - download_pos - msize); + memmove (download_buffer, &download_buffer[msize], download_pos - msize); download_pos -= msize; } return total; @@ -428,12 +430,14 @@ get_bootstrap_server () size_t urls; size_t pos; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "SERVERS", - &servers)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", + "SERVERS", + &servers)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - "hostlist", "SERVERS"); + "hostlist", + "SERVERS"); return NULL; } @@ -452,7 +456,8 @@ get_bootstrap_server () if (urls == 0) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - "hostlist", "SERVERS"); + "hostlist", + "SERVERS"); GNUNET_free (servers); return NULL; } @@ -514,7 +519,7 @@ download_get_url () return get_bootstrap_server (); } index = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, linked_list_size); counter = 0; pos = linked_list_head; while (counter < index) @@ -522,14 +527,26 @@ download_get_url () pos = pos->next; counter++; } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using learned hostlist `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Using learned hostlist `%s'\n", pos->hostlist_uri); current_hostlist = pos; return GNUNET_strdup (pos->hostlist_uri); } -#define CURL_EASY_SETOPT(c, a, b) do { ret = curl_easy_setopt (c, a, b); if (CURLE_OK != ret) GNUNET_log(GNUNET_ERROR_TYPE_WARNING, _("%s failed at %s:%d: `%s'\n"), "curl_easy_setopt", __FILE__, __LINE__, curl_easy_strerror (ret)); } while (0) +#define CURL_EASY_SETOPT(c, a, b) \ + do \ + { \ + ret = curl_easy_setopt (c, a, b); \ + if (CURLE_OK != ret) \ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, \ + _ ("%s failed at %s:%d: `%s'\n"), \ + "curl_easy_setopt", \ + __FILE__, \ + __LINE__, \ + curl_easy_strerror (ret)); \ + } while (0) /** @@ -549,8 +566,7 @@ save_hostlist_file (int shutdown); * @return result */ static uint64_t -checked_add (uint64_t val1, - uint64_t val2) +checked_add (uint64_t val1, uint64_t val2) { static uint64_t temp; static uint64_t maxv; @@ -573,8 +589,7 @@ checked_add (uint64_t val1, * @return result */ static uint64_t -checked_sub (uint64_t val1, - uint64_t val2) +checked_sub (uint64_t val1, uint64_t val2) { if (val1 <= val2) return 0; @@ -643,20 +658,25 @@ insert_hostlist () /* No free entries available, replace existing entry */ lowest_quality = linked_list_get_lowest_quality (); GNUNET_assert (lowest_quality != NULL); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", - lowest_quality->hostlist_uri, - (unsigned long long) lowest_quality->quality); - GNUNET_CONTAINER_DLL_remove (linked_list_head, linked_list_tail, + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Removing hostlist with URI `%s' which has the worst quality of all (%llu)\n", + lowest_quality->hostlist_uri, + (unsigned long long) lowest_quality->quality); + GNUNET_CONTAINER_DLL_remove (linked_list_head, + linked_list_tail, lowest_quality); linked_list_size--; GNUNET_free (lowest_quality); } - GNUNET_CONTAINER_DLL_insert (linked_list_head, linked_list_tail, + GNUNET_CONTAINER_DLL_insert (linked_list_head, + linked_list_tail, hostlist_to_test); linked_list_size++; - GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"), - linked_list_size, GNUNET_NO); + GNUNET_STATISTICS_set (stats, + gettext_noop ("# advertised hostlist URIs"), + linked_list_size, + GNUNET_NO); stat_testing_hostlist = GNUNET_NO; } @@ -678,14 +698,15 @@ update_hostlist () current_hostlist->hello_count = stat_hellos_obtained; current_hostlist->time_last_usage = GNUNET_TIME_absolute_get (); current_hostlist->quality = - checked_add (current_hostlist->quality, - (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); + checked_add (current_hostlist->quality, + (stat_hellos_obtained * HOSTLIST_SUCCESSFUL_HELLO)); if (GNUNET_YES == stat_download_successful) { current_hostlist->times_used++; current_hostlist->quality = - checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); - GNUNET_asprintf (&stat, gettext_noop ("# advertised URI `%s' downloaded"), + checked_add (current_hostlist->quality, HOSTLIST_SUCCESSFUL_DOWNLOAD); + GNUNET_asprintf (&stat, + gettext_noop ("# advertised URI `%s' downloaded"), current_hostlist->hostlist_uri); GNUNET_STATISTICS_update (stats, stat, 1, GNUNET_YES); @@ -693,7 +714,7 @@ update_hostlist () } else current_hostlist->quality = - checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); + checked_sub (current_hostlist->quality, HOSTLIST_FAILED_DOWNLOAD); } current_hostlist = NULL; /* Alternating the usage of preconfigured and learned hostlists */ @@ -722,14 +743,14 @@ clean_up () { CURLMcode mret; - if ( (stat_testing_hostlist == GNUNET_YES) && - (GNUNET_NO == stat_download_successful) && - (NULL != hostlist_to_test) ) + if ((stat_testing_hostlist == GNUNET_YES) && + (GNUNET_NO == stat_download_successful) && (NULL != hostlist_to_test)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), - hostlist_to_test->hostlist_uri); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ( + "Advertised hostlist with URI `%s' could not be downloaded. Advertised URI gets dismissed.\n"), + hostlist_to_test->hostlist_uri); } if (stat_testing_hostlist == GNUNET_YES) @@ -747,14 +768,20 @@ clean_up () mret = curl_multi_remove_handle (multi, curl); if (mret != CURLM_OK) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_remove_handle", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_remove_handle", + __FILE__, + __LINE__, curl_multi_strerror (mret)); } mret = curl_multi_cleanup (multi); if (mret != CURLM_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_cleanup", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_cleanup", + __FILE__, + __LINE__, curl_multi_strerror (mret)); multi = NULL; } @@ -805,8 +832,11 @@ download_prepare () mret = curl_multi_fdset (multi, &rs, &ws, &es, &max); if (mret != CURLM_OK) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_fdset", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_fdset", + __FILE__, + __LINE__, curl_multi_strerror (mret)); clean_up (); return; @@ -814,26 +844,30 @@ download_prepare () mret = curl_multi_timeout (multi, &timeout); if (mret != CURLM_OK) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_timeout", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_timeout", + __FILE__, + __LINE__, curl_multi_strerror (mret)); clean_up (); return; } - rtime = - GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (end_time), - GNUNET_TIME_relative_multiply - (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); + rtime = GNUNET_TIME_relative_min ( + GNUNET_TIME_absolute_get_remaining (end_time), + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, timeout)); grs = GNUNET_NETWORK_fdset_create (); gws = GNUNET_NETWORK_fdset_create (); GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduling task for hostlist download using cURL\n"); - ti_download = - GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, - rtime, grs, gws, - &task_download, multi); + ti_download = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, + rtime, + grs, + gws, + &task_download, + multi); GNUNET_NETWORK_fdset_destroy (gws); GNUNET_NETWORK_fdset_destroy (grs); } @@ -856,7 +890,7 @@ task_download (void *cls) if (0 == GNUNET_TIME_absolute_get_remaining (end_time).rel_value_us) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Timeout trying to download hostlist from `%s'\n"), + _ ("Timeout trying to download hostlist from `%s'\n"), current_url); update_hostlist (); clean_up (); @@ -870,7 +904,8 @@ task_download (void *cls) if (stat_bytes_downloaded > MAX_BYTES_PER_HOSTLISTS) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Download limit of %u bytes exceeded, stopping download\n"), + _ ( + "Download limit of %u bytes exceeded, stopping download\n"), MAX_BYTES_PER_HOSTLISTS); clean_up (); return; @@ -890,22 +925,22 @@ task_download (void *cls) if ((msg->data.result != CURLE_OK) && (msg->data.result != CURLE_GOT_NOTHING)) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Download of hostlist from `%s' failed: `%s'\n"), + _ ("Download of hostlist from `%s' failed: `%s'\n"), current_url, curl_easy_strerror (msg->data.result)); else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Download of hostlist `%s' completed.\n"), + _ ("Download of hostlist `%s' completed.\n"), current_url); stat_download_successful = GNUNET_YES; update_hostlist (); if (GNUNET_YES == stat_testing_hostlist) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Adding successfully tested hostlist `%s' datastore.\n"), - current_url); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Adding successfully tested hostlist `%s' datastore.\n"), + current_url); insert_hostlist (); hostlist_to_test = NULL; stat_testing_hostlist = GNUNET_NO; @@ -917,16 +952,17 @@ task_download (void *cls) break; } - } - while ((running > 0)); + } while ((running > 0)); } - } - while (mret == CURLM_CALL_MULTI_PERFORM); + } while (mret == CURLM_CALL_MULTI_PERFORM); if (mret != CURLM_OK) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_perform", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_perform", + __FILE__, + __LINE__, curl_multi_strerror (mret)); clean_up (); } @@ -957,7 +993,8 @@ download_hostlist () return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, - _("Bootstrapping using hostlist at `%s'.\n"), current_url); + _ ("Bootstrapping using hostlist at `%s'.\n"), + current_url); stat_download_in_progress = GNUNET_YES; stat_download_successful = GNUNET_NO; @@ -965,7 +1002,8 @@ download_hostlist () stat_bytes_downloaded = 0; GNUNET_STATISTICS_update (stats, - gettext_noop ("# hostlist downloads initiated"), 1, + gettext_noop ("# hostlist downloads initiated"), + 1, GNUNET_NO); if (NULL != proxy) { @@ -991,7 +1029,9 @@ download_hostlist () return; } CURL_EASY_SETOPT (curl, CURLOPT_FOLLOWLOCATION, 1); - CURL_EASY_SETOPT (curl, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); + CURL_EASY_SETOPT (curl, + CURLOPT_REDIR_PROTOCOLS, + CURLPROTO_HTTP | CURLPROTO_HTTPS); CURL_EASY_SETOPT (curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS); CURL_EASY_SETOPT (curl, CURLOPT_MAXREDIRS, 4); /* no need to abort if the above failed */ @@ -1020,13 +1060,19 @@ download_hostlist () mret = curl_multi_add_handle (multi, curl); if (mret != CURLM_OK) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_add_handle", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_add_handle", + __FILE__, + __LINE__, curl_multi_strerror (mret)); mret = curl_multi_cleanup (multi); if (mret != CURLM_OK) - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), - "curl_multi_cleanup", __FILE__, __LINE__, + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("%s failed at %s:%d: `%s'\n"), + "curl_multi_cleanup", + __FILE__, + __LINE__, curl_multi_strerror (mret)); multi = NULL; clean_up (); @@ -1052,8 +1098,9 @@ task_download_dispatcher (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download in progess, have to wait...\n"); ti_download_dispatcher_task = - GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, - &task_download_dispatcher, NULL); + GNUNET_SCHEDULER_add_delayed (WAITING_INTERVAL, + &task_download_dispatcher, + NULL); } } @@ -1073,12 +1120,12 @@ task_check (void *cls) if (stats == NULL) { curl_global_cleanup (); - return; /* in shutdown */ + return; /* in shutdown */ } - if ( (stat_connection_count < MIN_CONNECTIONS) && - (NULL == ti_download_dispatcher_task) ) + if ((stat_connection_count < MIN_CONNECTIONS) && + (NULL == ti_download_dispatcher_task)) ti_download_dispatcher_task = - GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); + GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); delay = hostlist_delay; if (0 == hostlist_delay.rel_value_us) @@ -1088,24 +1135,25 @@ task_check (void *cls) if (hostlist_delay.rel_value_us > GNUNET_TIME_UNIT_HOURS.rel_value_us * (1 + stat_connection_count)) hostlist_delay = - GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, - (1 + stat_connection_count)); + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, + (1 + stat_connection_count)); GNUNET_STATISTICS_set (stats, - gettext_noop - ("# milliseconds between hostlist downloads"), + gettext_noop ( + "# milliseconds between hostlist downloads"), hostlist_delay.rel_value_us / 1000LL, - GNUNET_YES); + GNUNET_YES); if (0 == once) { delay = GNUNET_TIME_UNIT_ZERO; once = 1; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Have %u/%u connections. Will consider downloading hostlist in %s\n"), - stat_connection_count, MIN_CONNECTIONS, - GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); - ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, - &task_check, NULL); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ("Have %u/%u connections. Will consider downloading hostlist in %s\n"), + stat_connection_count, + MIN_CONNECTIONS, + GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); + ti_check_download = GNUNET_SCHEDULER_add_delayed (delay, &task_check, NULL); } @@ -1137,11 +1185,10 @@ task_hostlist_saving (void *cls) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlists will be saved to file again in %s\n", - GNUNET_STRINGS_relative_time_to_string(SAVING_INTERVAL, GNUNET_YES)); + GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, + GNUNET_YES)); ti_saving_task = - GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, - &task_hostlist_saving, - NULL); + GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, &task_hostlist_saving, NULL); } @@ -1154,14 +1201,14 @@ task_hostlist_saving (void *cls) */ static void * handler_connect (void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { GNUNET_assert (stat_connection_count < UINT_MAX); stat_connection_count++; GNUNET_STATISTICS_update (stats, - gettext_noop ("# active connections"), - 1, + gettext_noop ("# active connections"), + 1, GNUNET_NO); return NULL; } @@ -1175,14 +1222,14 @@ handler_connect (void *cls, */ static void handler_disconnect (void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { GNUNET_assert (stat_connection_count > 0); stat_connection_count--; GNUNET_STATISTICS_update (stats, - gettext_noop ("# active connections"), - -1, + gettext_noop ("# active connections"), + -1, GNUNET_NO); } @@ -1201,33 +1248,31 @@ handler_advertisement (const char *uri) uri_size = strlen (uri) + 1; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client recieved advertisement containing URI `%s'\n", - uri); + uri); if (GNUNET_NO != linked_list_contains (uri)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "URI `%s' is already known\n", - uri); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "URI `%s' is already known\n", uri); return; } if (GNUNET_NO == stat_testing_allowed) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Currently not accepting new advertisements: interval between to advertisements is not reached\n"); return; } if (GNUNET_YES == stat_testing_hostlist) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Currently not accepting new advertisements: we are already testing a hostlist\n"); + GNUNET_log ( + GNUNET_ERROR_TYPE_DEBUG, + "Currently not accepting new advertisements: we are already testing a hostlist\n"); return; } hostlist = GNUNET_malloc (sizeof (struct Hostlist) + uri_size); hostlist->hostlist_uri = (const char *) &hostlist[1]; - GNUNET_memcpy (&hostlist[1], - uri, - uri_size); + GNUNET_memcpy (&hostlist[1], uri, uri_size); hostlist->time_creation = GNUNET_TIME_absolute_get (); hostlist->quality = HOSTLIST_INITIAL; hostlist_to_test = hostlist; @@ -1235,18 +1280,17 @@ handler_advertisement (const char *uri) stat_testing_hostlist = GNUNET_YES; stat_testing_allowed = GNUNET_NO; ti_testing_intervall_task = - GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, - &task_testing_intervall_reset, - NULL); + GNUNET_SCHEDULER_add_delayed (TESTING_INTERVAL, + &task_testing_intervall_reset, + NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing new hostlist advertisements is locked for the next %s\n", GNUNET_STRINGS_relative_time_to_string (TESTING_INTERVAL, - GNUNET_YES)); + GNUNET_YES)); ti_download_dispatcher_task = - GNUNET_SCHEDULER_add_now (&task_download_dispatcher, - NULL); + GNUNET_SCHEDULER_add_now (&task_download_dispatcher, NULL); } @@ -1259,8 +1303,7 @@ handler_advertisement (const char *uri) * successfully obtained, #GNUNET_SYSERR if not. */ static void -primary_task (void *cls, - int success) +primary_task (void *cls, int success) { if (NULL != ti_check_download) { @@ -1288,8 +1331,7 @@ stat_timeout_task (void *cls) { GNUNET_STATISTICS_get_cancel (sget); sget = NULL; - ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, - NULL); + ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); } @@ -1337,22 +1379,25 @@ load_hostlist_file () struct GNUNET_BIO_ReadHandle *rh; uri = NULL; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE", - &filename)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, + "HOSTLIST", + "HOSTLISTFILE", + &filename)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - "hostlist", "HOSTLISTFILE"); + "hostlist", + "HOSTLISTFILE"); return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Loading saved hostlist entries from file `%s' \n"), - filename); + _ ("Loading saved hostlist entries from file `%s' \n"), + filename); if (GNUNET_NO == GNUNET_DISK_file_test (filename)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Hostlist file `%s' does not exist\n"), filename); + _ ("Hostlist file `%s' does not exist\n"), + filename); GNUNET_free (filename); return; } @@ -1361,16 +1406,19 @@ load_hostlist_file () if (NULL == rh) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Could not open file `%s' for reading to load hostlists: %s\n"), - filename, STRERROR (errno)); + _ ( + "Could not open file `%s' for reading to load hostlists: %s\n"), + filename, + strerror (errno)); GNUNET_free (filename); return; } counter = 0; while ((GNUNET_OK == GNUNET_BIO_read_string (rh, "url", &uri, MAX_URL_LEN)) && - (NULL != uri) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) - && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && + (NULL != uri) && + (GNUNET_OK == GNUNET_BIO_read_int32 (rh, ×_used)) && + (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &quality)) && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &last_used)) && (GNUNET_OK == GNUNET_BIO_read_int64 (rh, &created)) && (GNUNET_OK == GNUNET_BIO_read_int32 (rh, &hellos_returned))) @@ -1395,14 +1443,16 @@ load_hostlist_file () } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("%u hostlist URIs loaded from file\n"), + _ ("%u hostlist URIs loaded from file\n"), counter); GNUNET_STATISTICS_set (stats, gettext_noop ("# hostlist URIs read from file"), - counter, GNUNET_YES); + counter, + GNUNET_YES); GNUNET_STATISTICS_set (stats, gettext_noop ("# advertised hostlist URIs"), - linked_list_size, GNUNET_NO); + linked_list_size, + GNUNET_NO); GNUNET_free_non_null (uri); emsg = NULL; @@ -1427,12 +1477,14 @@ save_hostlist_file (int shutdown) int ok; uint32_t counter; - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (cfg, "HOSTLIST", "HOSTLISTFILE", - &filename)) + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, + "HOSTLIST", + "HOSTLISTFILE", + &filename)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, - "hostlist", "HOSTLISTFILE"); + "hostlist", + "HOSTLISTFILE"); return; } if (GNUNET_SYSERR == GNUNET_DISK_directory_create_for_file (filename)) @@ -1444,15 +1496,17 @@ save_hostlist_file (int shutdown) if (NULL == wh) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Could not open file `%s' for writing to save hostlists: %s\n"), + _ ( + "Could not open file `%s' for writing to save hostlists: %s\n"), filename, - STRERROR (errno)); + strerror (errno)); GNUNET_free (filename); return; } GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Writing %u hostlist URIs to `%s'\n"), - linked_list_size, filename); + _ ("Writing %u hostlist URIs to `%s'\n"), + linked_list_size, + filename); /* add code to write hostlists to file using bio */ ok = GNUNET_YES; counter = 0; @@ -1475,7 +1529,8 @@ save_hostlist_file (int shutdown) (GNUNET_OK != GNUNET_BIO_write_int32 (wh, pos->hello_count))) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Error writing hostlist URIs to file `%s'\n"), filename); + _ ("Error writing hostlist URIs to file `%s'\n"), + filename); ok = GNUNET_NO; } } @@ -1488,11 +1543,13 @@ save_hostlist_file (int shutdown) } GNUNET_STATISTICS_set (stats, gettext_noop ("# hostlist URIs written to file"), - counter, GNUNET_YES); + counter, + GNUNET_YES); if (GNUNET_OK != GNUNET_BIO_write_close (wh)) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - _("Error writing hostlist URIs to file `%s'\n"), filename); + _ ("Error writing hostlist URIs to file `%s'\n"), + filename); GNUNET_free (filename); } @@ -1532,47 +1589,38 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, /* Read proxy configuration */ pi = GNUNET_PEERINFO_connect (c); if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", - "PROXY", - &proxy)) + GNUNET_CONFIGURATION_get_value_string (cfg, "HOSTLIST", "PROXY", &proxy)) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found proxy host: `%s'\n", - proxy); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found proxy host: `%s'\n", proxy); /* proxy username */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", - "PROXY_USERNAME", - &proxy_username)) + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", + "PROXY_USERNAME", + &proxy_username)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found proxy username name: `%s'\n", - proxy_username); + "Found proxy username name: `%s'\n", + proxy_username); } /* proxy password */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", - "PROXY_PASSWORD", - &proxy_password)) + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", + "PROXY_PASSWORD", + &proxy_password)) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Found proxy password name: `%s'\n", - proxy_password); + "Found proxy password name: `%s'\n", + proxy_password); } /* proxy type */ - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_string (cfg, - "HOSTLIST", - "PROXY_TYPE", - &proxytype_str)) + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, + "HOSTLIST", + "PROXY_TYPE", + &proxytype_str)) { - GNUNET_STRINGS_utf8_toupper (proxytype_str, - proxytype_str); + GNUNET_STRINGS_utf8_toupper (proxytype_str, proxytype_str); proxy_type = CURLPROXY_HTTP; if (0 == strcmp (proxytype_str, "HTTP")) proxy_type = CURLPROXY_HTTP; @@ -1588,9 +1636,11 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, proxy_type = CURLPROXY_SOCKS5_HOSTNAME; else { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), - proxytype_str); + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ( + "Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), + proxytype_str); GNUNET_free (proxytype_str); GNUNET_free (proxy); proxy = NULL; @@ -1618,35 +1668,35 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, { *msgh = &handler_advertisement; GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Learning is enabled on this peer\n")); + _ ("Learning is enabled on this peer\n")); load_hostlist_file (); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlists will be saved to file again in %s\n", - GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, - GNUNET_YES)); - ti_saving_task = - GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, - &task_hostlist_saving, - NULL); + GNUNET_STRINGS_relative_time_to_string (SAVING_INTERVAL, + GNUNET_YES)); + ti_saving_task = GNUNET_SCHEDULER_add_delayed (SAVING_INTERVAL, + &task_hostlist_saving, + NULL); } else { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Learning is not enabled on this peer\n")); + _ ("Learning is not enabled on this peer\n")); *msgh = NULL; - if (GNUNET_OK == - GNUNET_CONFIGURATION_get_value_filename (cfg, - "HOSTLIST", - "HOSTLISTFILE", - &filename)) + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, + "HOSTLIST", + "HOSTLISTFILE", + &filename)) { if (GNUNET_YES == GNUNET_DISK_file_test (filename)) { result = remove (filename); if (0 == result) - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), - filename); + GNUNET_log ( + GNUNET_ERROR_TYPE_INFO, + _ ( + "Since learning is not enabled on this peer, hostlist file `%s' was removed\n"), + filename); else GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "remove", @@ -1657,25 +1707,24 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, } GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading stats value on hostlist download frequency\n"); - sget = GNUNET_STATISTICS_get (stats, "hostlist", - gettext_noop - ("# milliseconds between hostlist downloads"), + sget = GNUNET_STATISTICS_get (stats, + "hostlist", + gettext_noop ( + "# milliseconds between hostlist downloads"), &primary_task, &process_stat, - NULL); + NULL); if (NULL == sget) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics request failed, scheduling hostlist download\n"); - ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, - NULL); + ti_check_download = GNUNET_SCHEDULER_add_now (&task_check, NULL); } else { - ti_check_download - = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, - &stat_timeout_task, - NULL); + ti_check_download = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, + &stat_timeout_task, + NULL); } return GNUNET_OK; } @@ -1687,8 +1736,7 @@ GNUNET_HOSTLIST_client_start (const struct GNUNET_CONFIGURATION_Handle *c, void GNUNET_HOSTLIST_client_stop () { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Hostlist client shutdown\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostlist client shutdown\n"); if (NULL != sget) { GNUNET_STATISTICS_get_cancel (sget); @@ -1703,7 +1751,7 @@ GNUNET_HOSTLIST_client_stop () ti_saving_task = NULL; } if (NULL != ti_download_dispatcher_task) - { + { GNUNET_SCHEDULER_cancel (ti_download_dispatcher_task); ti_download_dispatcher_task = NULL; } diff --git a/src/mysql/mysql.c b/src/mysql/mysql.c index 652d7e7d8..c78fbeb4b 100644 --- a/src/mysql/mysql.c +++ b/src/mysql/mysql.c @@ -208,7 +208,7 @@ get_my_cnf_path (const struct GNUNET_CONFIGURATION_Handle *cfg, "mysql", _ ("Could not access file `%s': %s\n"), cnffile, - STRERROR (errno)); + strerror (errno)); GNUNET_free (cnffile); return NULL; } diff --git a/src/nat-auto/gnunet-nat-auto_legacy.c b/src/nat-auto/gnunet-nat-auto_legacy.c index 4a24223fd..93b544343 100644 --- a/src/nat-auto/gnunet-nat-auto_legacy.c +++ b/src/nat-auto/gnunet-nat-auto_legacy.c @@ -28,9 +28,10 @@ #include "gnunet_nat_lib.h" #include "nat.h" -#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__) -#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) +#define NAT_SERVER_TIMEOUT \ + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) /** * Entry we keep for each incoming connection. @@ -88,7 +89,6 @@ struct ClientActivity * Handle to overall NAT test. */ struct GNUNET_NAT_Test *h; - }; @@ -184,9 +184,7 @@ struct GNUNET_NAT_Test * @param addrlen actual lenght of the @a addr */ static void -reversal_cb (void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen) { struct GNUNET_NAT_Test *h = cls; const struct sockaddr_in *sa; @@ -198,11 +196,10 @@ reversal_cb (void *cls, { LOG (GNUNET_ERROR_TYPE_DEBUG, "Received connection reversal request for wrong port\n"); - return; /* wrong port */ + return; /* wrong port */ } /* report success */ - h->report (h->report_cls, - GNUNET_NAT_ERROR_SUCCESS); + h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS); } @@ -220,22 +217,17 @@ do_udp_read (void *cls) const struct GNUNET_SCHEDULER_TaskContext *tc; tc = GNUNET_SCHEDULER_get_task_context (); - tst->ltask = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, - tst->lsock, - &do_udp_read, - tst); + tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + tst->lsock, + &do_udp_read, + tst); if ((NULL != tc->write_ready) && - (GNUNET_NETWORK_fdset_isset (tc->read_ready, - tst->lsock)) && + (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) && (sizeof (data) == - GNUNET_NETWORK_socket_recv (tst->lsock, - &data, - sizeof (data)))) + GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data)))) { if (data == tst->data) - tst->report (tst->report_cls, - GNUNET_NAT_ERROR_SUCCESS); + tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS); else LOG (GNUNET_ERROR_TYPE_DEBUG, "Received data mismatches expected value\n"); @@ -263,20 +255,14 @@ do_read (void *cls) tc = GNUNET_SCHEDULER_get_task_context (); na->rtask = NULL; tst = na->h; - GNUNET_CONTAINER_DLL_remove (tst->na_head, - tst->na_tail, - na); + GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); if ((NULL != tc->write_ready) && - (GNUNET_NETWORK_fdset_isset (tc->read_ready, - na->sock)) && + (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) && (sizeof (data) == - GNUNET_NETWORK_socket_recv (na->sock, - &data, - sizeof (data)))) + GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data)))) { if (data == tst->data) - tst->report (tst->report_cls, - GNUNET_NAT_ERROR_SUCCESS); + tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS); else LOG (GNUNET_ERROR_TYPE_DEBUG, "Received data does not match expected value\n"); @@ -306,28 +292,22 @@ do_accept (void *cls) tst->lsock, &do_accept, tst); - s = GNUNET_NETWORK_socket_accept (tst->lsock, - NULL, - NULL); + s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL); if (NULL == s) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, - "accept"); - return; /* odd error */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept"); + return; /* odd error */ } LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an inbound connection, waiting for data\n"); wl = GNUNET_new (struct NatActivity); wl->sock = s; wl->h = tst; - wl->rtask = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, - wl->sock, - &do_read, - wl); - GNUNET_CONTAINER_DLL_insert (tst->na_head, - tst->na_tail, - wl); + wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + wl->sock, + &do_read, + wl); + GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl); } @@ -339,15 +319,12 @@ do_accept (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 ClientActivity *ca = cls; struct GNUNET_NAT_Test *tst = ca->h; - GNUNET_CONTAINER_DLL_remove (tst->ca_head, - tst->ca_tail, - ca); + GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, ca); GNUNET_MQ_destroy (ca->mq); GNUNET_free (ca); } @@ -379,15 +356,13 @@ addr_cb (void *cls, if (addrlen != sizeof (struct sockaddr_in)) { LOG (GNUNET_ERROR_TYPE_DEBUG, - "NAT test ignores IPv6 address `%s' returned from NAT library\n", - GNUNET_a2s (addr, - addrlen)); - return; /* ignore IPv6 here */ + "NAT test ignores IPv6 address `%s' returned from NAT library\n", + GNUNET_a2s (addr, addrlen)); + return; /* ignore IPv6 here */ } LOG (GNUNET_ERROR_TYPE_INFO, "Asking gnunet-nat-server to connect to `%s'\n", - GNUNET_a2s (addr, - addrlen)); + GNUNET_a2s (addr, addrlen)); ca = GNUNET_new (struct ClientActivity); ca->h = h; @@ -400,21 +375,17 @@ addr_cb (void *cls, { GNUNET_free (ca); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect to `gnunet-nat-server'\n")); + _ ("Failed to connect to `gnunet-nat-server'\n")); return; } - GNUNET_CONTAINER_DLL_insert (h->ca_head, - h->ca_tail, - ca); + GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); sa = (const struct sockaddr_in *) addr; - env = GNUNET_MQ_msg (msg, - GNUNET_MESSAGE_TYPE_NAT_TEST); + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAT_TEST); msg->dst_ipv4 = sa->sin_addr.s_addr; msg->dport = sa->sin_port; msg->data = h->data; msg->is_tcp = htonl ((uint32_t) h->is_tcp); - GNUNET_MQ_send (ca->mq, - env); + GNUNET_MQ_send (ca->mq, env); } @@ -434,8 +405,8 @@ do_timeout (void *cls) nh->ttask = NULL; nh->report (nh->report_cls, (GNUNET_NAT_ERROR_SUCCESS == nh->status) - ? GNUNET_NAT_ERROR_TIMEOUT - : nh->status); + ? GNUNET_NAT_ERROR_TIMEOUT + : nh->status); } @@ -465,12 +436,8 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, { struct GNUNET_NAT_Test *nh; struct sockaddr_in sa; - const struct sockaddr *addrs[] = { - (const struct sockaddr *) &sa - }; - const socklen_t addrlens[] = { - sizeof (sa) - }; + const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa}; + const socklen_t addrlens[] = {sizeof (sa)}; memset (&sa, 0, sizeof (sa)); sa.sin_family = AF_INET; @@ -489,69 +456,62 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, nh->status = GNUNET_NAT_ERROR_SUCCESS; if (0 == bnd_port) { - nh->nat - = GNUNET_NAT_register (cfg, - is_tcp, - 0, - 0, - NULL, - NULL, - &addr_cb, - &reversal_cb, - nh, - NULL); + nh->nat = GNUNET_NAT_register (cfg, + is_tcp, + 0, + 0, + NULL, + NULL, + &addr_cb, + &reversal_cb, + nh, + NULL); } else { nh->lsock = - GNUNET_NETWORK_socket_create (AF_INET, - (is_tcp == - GNUNET_YES) ? SOCK_STREAM : SOCK_DGRAM, - 0); + GNUNET_NETWORK_socket_create (AF_INET, + (is_tcp == GNUNET_YES) ? SOCK_STREAM + : SOCK_DGRAM, + 0); if ((nh->lsock == NULL) || - (GNUNET_OK != - GNUNET_NETWORK_socket_bind (nh->lsock, - (const struct sockaddr *) &sa, - sizeof (sa)))) + (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock, + (const struct sockaddr *) &sa, + sizeof (sa)))) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Failed to create listen socket bound to `%s' for NAT test: %s\n"), - GNUNET_a2s ((const struct sockaddr *) &sa, - sizeof (sa)), - STRERROR (errno)); + GNUNET_log ( + GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to create listen socket bound to `%s' for NAT test: %s\n"), + GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)), + strerror (errno)); if (NULL != nh->lsock) { GNUNET_NETWORK_socket_close (nh->lsock); nh->lsock = NULL; } nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; - nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, - nh); + nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); return nh; } if (GNUNET_YES == is_tcp) { - GNUNET_break (GNUNET_OK == - GNUNET_NETWORK_socket_listen (nh->lsock, - 5)); - nh->ltask = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, - nh->lsock, - &do_accept, - nh); + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5)); + nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + nh->lsock, + &do_accept, + nh); } else { - nh->ltask = - GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, - nh->lsock, - &do_udp_read, - nh); + nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, + nh->lsock, + &do_udp_read, + nh); } LOG (GNUNET_ERROR_TYPE_INFO, - "NAT test listens on port %u (%s)\n", - bnd_port, - (GNUNET_YES == is_tcp) ? "tcp" : "udp"); + "NAT test listens on port %u (%s)\n", + bnd_port, + (GNUNET_YES == is_tcp) ? "tcp" : "udp"); nh->nat = GNUNET_NAT_register (cfg, is_tcp, adv_port, @@ -565,7 +525,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, if (NULL == nh->nat) { LOG (GNUNET_ERROR_TYPE_INFO, - _("NAT test failed to start NAT library\n")); + _ ("NAT test failed to start NAT library\n")); if (NULL != nh->ltask) { GNUNET_SCHEDULER_cancel (nh->ltask); @@ -577,14 +537,11 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, nh->lsock = NULL; } nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; - nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, - nh); + nh->ttask = GNUNET_SCHEDULER_add_now (&do_timeout, nh); return nh; } } - nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, - &do_timeout, - nh); + nh->ttask = GNUNET_SCHEDULER_add_delayed (timeout, &do_timeout, nh); return nh; } @@ -600,21 +557,16 @@ GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst) struct NatActivity *pos; struct ClientActivity *cpos; - LOG (GNUNET_ERROR_TYPE_DEBUG, - "Stopping NAT test\n"); + LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n"); while (NULL != (cpos = tst->ca_head)) { - GNUNET_CONTAINER_DLL_remove (tst->ca_head, - tst->ca_tail, - cpos); + GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos); GNUNET_MQ_destroy (cpos->mq); GNUNET_free (cpos); } while (NULL != (pos = tst->na_head)) { - GNUNET_CONTAINER_DLL_remove (tst->na_head, - tst->na_tail, - pos); + GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos); GNUNET_SCHEDULER_cancel (pos->rtask); GNUNET_NETWORK_socket_close (pos->sock); GNUNET_free (pos); diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index c7ed1b903..0adf8f6a5 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c @@ -104,13 +104,14 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; GNUNET_memcpy (&macmsg.mac, - (char *) mac, - sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); - macmsg.hdr.size = htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); + (char *) mac, + sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); + macmsg.hdr.size = + htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); GNUNET_memcpy (buffer, - &macmsg, - sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); + &macmsg, + sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); } @@ -126,8 +127,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) * #GNUNET_SYSERR to stop further processing with error */ static int -stdin_send (void *cls, - const struct GNUNET_MessageHeader *hdr) +stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr) { struct SendBuffer *write_pout = cls; const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; @@ -137,16 +137,19 @@ stdin_send (void *cls, sendsize = ntohs (hdr->size); in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; - if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || - (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) + if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || + (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) { fprintf (stderr, "%s", "Received malformed message\n"); exit (1); } - payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); - if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) + payload_size = + sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); + if ((payload_size + + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + + write_pout->size) > MAXLINE * 2) { - fprintf (stderr, "%s", "Packet too big for buffer\n"); + fprintf (stderr, "%s", "Packet too big for buffer\n"); exit (1); } memset (&newheader, 0, sizeof (newheader)); @@ -154,12 +157,10 @@ stdin_send (void *cls, newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); newheader.frame = in->frame; GNUNET_memcpy (write_pout->buf + write_pout->size, - &newheader, - sizeof (newheader)); + &newheader, + sizeof (newheader)); write_pout->size += sizeof (newheader); - GNUNET_memcpy (write_pout->buf + write_pout->size, - &in[1], - payload_size); + GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size); write_pout->size += payload_size; return GNUNET_OK; } @@ -175,8 +176,7 @@ stdin_send (void *cls, * #GNUNET_SYSERR to stop further processing with error */ static int -file_in_send (void *cls, - const struct GNUNET_MessageHeader *hdr) +file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr) { struct SendBuffer *write_std = cls; uint16_t sendsize; @@ -224,45 +224,46 @@ main (int argc, char *argv[]) struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; int first; - if ( (2 != argc) || - ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) + if ((2 != argc) || + ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2")))) { - fprintf (stderr, - "%s", - "This program must be started with the operating mode (1 or 2) as the only argument.\n"); + fprintf ( + stderr, + "%s", + "This program must be started with the operating mode (1 or 2) as the only argument.\n"); return 1; } /* make the fifos if needed */ umask (0); - if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || - (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) + if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || + (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2))) { - fprintf (stderr, - "Failed to create directory for file `%s'\n", - FIFO_FILE1); + fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1); return 1; } - if (0 == strcmp (argv[1], "1") ) + if (0 == strcmp (argv[1], "1")) { if (0 != stat (FIFO_FILE1, &st)) { erg = mkfifo (FIFO_FILE1, 0666); - if ( (0 != erg) && (EEXIST != errno) ) - fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, - strerror (errno)); + if ((0 != erg) && (EEXIST != errno)) + fprintf (stderr, + "Error in mkfifo(%s): %s\n", + FIFO_FILE1, + strerror (errno)); } } else { if (0 != stat (FIFO_FILE2, &st)) { - GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); - if ( (0 != erg) && (EEXIST != errno) ) - fprintf (stderr, + GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); + if ((0 != erg) && (EEXIST != errno)) + fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE2, - strerror (errno)); + strerror (errno)); } } @@ -274,7 +275,7 @@ main (int argc, char *argv[]) { fprintf (stderr, "fopen of read FIFO_FILE1 failed: %s\n", - STRERROR (errno)); + strerror (errno)); goto end; } if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) @@ -286,7 +287,7 @@ main (int argc, char *argv[]) { fprintf (stderr, "fopen of write FIFO_FILE2 failed: %s\n", - STRERROR (errno)); + strerror (errno)); goto end; } } @@ -295,14 +296,14 @@ main (int argc, char *argv[]) first = 0; if (NULL == (fpout = fopen (FIFO_FILE1, "w"))) { - GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); + GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); fpout = fopen (FIFO_FILE1, "w"); } if (NULL == fpout) { fprintf (stderr, "fopen of write FIFO_FILE1 failed: %s\n", - STRERROR (errno)); + strerror (errno)); goto end; } fpin = fopen (FIFO_FILE2, "r"); @@ -310,7 +311,7 @@ main (int argc, char *argv[]) { fprintf (stderr, "fopen of read FIFO_FILE2 failed: %s\n", - STRERROR (errno)); + strerror (errno)); goto end; } } @@ -395,21 +396,22 @@ main (int argc, char *argv[]) continue; if (0 > retval) { - fprintf (stderr, "select failed: %s\n", STRERROR (errno)); + fprintf (stderr, "select failed: %s\n", strerror (errno)); closeprog = 1; break; } if (FD_ISSET (STDOUT_FILENO, &wfds)) { - ret = - write (STDOUT_FILENO, write_std.buf + write_std.pos, - write_std.size - write_std.pos); + ret = write (STDOUT_FILENO, + write_std.buf + write_std.pos, + write_std.size - write_std.pos); if (0 > ret) { closeprog = 1; - fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", - STRERROR (errno)); + fprintf (stderr, + "Write ERROR to STDOUT_FILENO: %s\n", + strerror (errno)); break; } else @@ -426,14 +428,16 @@ main (int argc, char *argv[]) if (FD_ISSET (fdpout, &wfds)) { - ret = - write (fdpout, write_pout.buf + write_pout.pos, - write_pout.size - write_pout.pos); + ret = write (fdpout, + write_pout.buf + write_pout.pos, + write_pout.size - write_pout.pos); if (0 > ret) { closeprog = 1; - fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); + fprintf (stderr, + "Write ERROR to fdpout failed: %s\n", + strerror (errno)); } else { @@ -454,15 +458,17 @@ main (int argc, char *argv[]) if (0 > readsize) { closeprog = 1; - fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", - STRERROR (errno)); + fprintf (stderr, + "Error reading from STDIN_FILENO: %s\n", + strerror (errno)); } else if (0 < readsize) { GNUNET_MST_from_buffer (stdin_mst, - readbuf, readsize, - GNUNET_NO, GNUNET_NO); - + readbuf, + readsize, + GNUNET_NO, + GNUNET_NO); } else { @@ -477,14 +483,16 @@ main (int argc, char *argv[]) if (0 > readsize) { closeprog = 1; - fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); + fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); break; } else if (0 < readsize) { GNUNET_MST_from_buffer (file_in_mst, - readbuf, readsize, - GNUNET_NO, GNUNET_NO); + readbuf, + readsize, + GNUNET_NO, + GNUNET_NO); } else { diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c index 04f30a683..9b31377e7 100644 --- a/src/transport/gnunet-transport-wlan-receiver.c +++ b/src/transport/gnunet-transport-wlan-receiver.c @@ -37,7 +37,7 @@ main (int argc, char *argv[]) time_t akt; ssize_t ret; pid_t pid; - int commpipe[2]; /* This holds the fd for the input & output of the pipe */ + int commpipe[2]; /* This holds the fd for the input & output of the pipe */ if (2 != argc) { @@ -46,34 +46,30 @@ main (int argc, char *argv[]) fprintf (stderr, "Usage: %s interface-name\n" "e.g. %s mon0\n", - argv[0], argv[0]); + argv[0], + argv[0]); return 1; } /* Setup communication pipeline first */ if (pipe (commpipe)) { - fprintf (stderr, - "Failed to create pipe: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); exit (1); } /* Attempt to fork and check for errors */ if ((pid = fork ()) == -1) { - fprintf (stderr, "Failed to fork: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); exit (1); } if (pid) { /* A positive (non-negative) PID indicates the parent process */ - if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ - fprintf (stderr, - "Failed to close fd: %s\n", - strerror (errno)); + if (0 != close (commpipe[1])) /* Close unused side of pipe (in side) */ + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); start = time (NULL); count = 0; while (1) @@ -81,18 +77,18 @@ main (int argc, char *argv[]) ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); if (0 > ret) { - fprintf (stderr, "read failed: %s\n", strerror (errno)); - break; + fprintf (stderr, "read failed: %s\n", strerror (errno)); + break; } count += ret; akt = time (NULL); if (akt - start > 30) { - bytes_per_s = count / (akt - start); - bytes_per_s /= 1024; - printf ("recv %f kb/s\n", bytes_per_s); - start = akt; - count = 0; + bytes_per_s = count / (akt - start); + bytes_per_s /= 1024; + printf ("recv %f kb/s\n", bytes_per_s); + start = akt; + count = 0; } } } @@ -100,13 +96,15 @@ main (int argc, char *argv[]) { /* A zero PID indicates that this is the child process */ (void) close (1); - if (-1 == dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ + if (-1 == + dup2 (commpipe[1], 1)) /* Replace stdin with the in side of the pipe */ fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); (void) close (commpipe[0]); /* Close unused side of pipe (in side) */ /* Replace the child fork with a new process */ - if (execlp - ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", - argv[1], NULL) == -1) + if (execlp ("gnunet-helper-transport-wlan", + "gnunet-helper-transport-wlan", + argv[1], + NULL) == -1) { fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); _exit (1); diff --git a/src/transport/gnunet-transport-wlan-sender.c b/src/transport/gnunet-transport-wlan-sender.c index 36d26f8dc..36273f765 100644 --- a/src/transport/gnunet-transport-wlan-sender.c +++ b/src/transport/gnunet-transport-wlan-sender.c @@ -35,16 +35,16 @@ #define WLAN_LLC_DSAP_FIELD 0x1f #define WLAN_LLC_SSAP_FIELD 0x1f -#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ +#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ -#define IEEE80211_FC0_VERSION_MASK 0x03 -#define IEEE80211_FC0_VERSION_SHIFT 0 -#define IEEE80211_FC0_VERSION_0 0x00 -#define IEEE80211_FC0_TYPE_MASK 0x0c -#define IEEE80211_FC0_TYPE_SHIFT 2 -#define IEEE80211_FC0_TYPE_MGT 0x00 -#define IEEE80211_FC0_TYPE_CTL 0x04 -#define IEEE80211_FC0_TYPE_DATA 0x08 +#define IEEE80211_FC0_VERSION_MASK 0x03 +#define IEEE80211_FC0_VERSION_SHIFT 0 +#define IEEE80211_FC0_VERSION_0 0x00 +#define IEEE80211_FC0_TYPE_MASK 0x0c +#define IEEE80211_FC0_TYPE_SHIFT 2 +#define IEEE80211_FC0_TYPE_MGT 0x00 +#define IEEE80211_FC0_TYPE_CTL 0x04 +#define IEEE80211_FC0_TYPE_DATA 0x08 /** @@ -55,7 +55,7 @@ */ static int getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, - uint16_t size) + uint16_t size) { header->header.size = htons (size); header->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); @@ -75,8 +75,9 @@ getRadiotapHeader (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, */ static int getWlanHeader (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *Header, - const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, - const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, unsigned int size) + const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, + const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac, + unsigned int size) { const int rate = 11000000; @@ -109,21 +110,27 @@ main (int argc, char *argv[]) int i; ssize_t ret; pid_t pid; - int commpipe[2]; /* This holds the fd for the input & output of the pipe */ - int macpipe[2]; /* This holds the fd for the input & output of the pipe */ + int commpipe[2]; /* This holds the fd for the input & output of the pipe */ + int macpipe[2]; /* This holds the fd for the input & output of the pipe */ if (4 != argc) { - fprintf (stderr, - "This program must be started with the interface and the targets and source mac as argument.\n"); + fprintf ( + stderr, + "This program must be started with the interface and the targets and source mac as argument.\n"); fprintf (stderr, "Usage: interface-name mac-DST mac-SRC\n" "e.g. mon0 11-22-33-44-55-66 12-34-56-78-90-ab\n"); return 1; } - if (6 != - SSCANF (argv[2], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], - &temp[3], &temp[4], &temp[5])) + if (6 != SSCANF (argv[2], + "%x-%x-%x-%x-%x-%x", + &temp[0], + &temp[1], + &temp[2], + &temp[3], + &temp[4], + &temp[5])) { fprintf (stderr, "Usage: interface-name mac-DST mac-SRC\n" @@ -132,9 +139,14 @@ main (int argc, char *argv[]) } for (i = 0; i < 6; i++) outmac.mac[i] = temp[i]; - if (6 != - SSCANF (argv[3], "%x-%x-%x-%x-%x-%x", &temp[0], &temp[1], &temp[2], - &temp[3], &temp[4], &temp[5])) + if (6 != SSCANF (argv[3], + "%x-%x-%x-%x-%x-%x", + &temp[0], + &temp[1], + &temp[2], + &temp[3], + &temp[4], + &temp[5])) { fprintf (stderr, "Usage: interface-name mac-DST mac-SRC\n" @@ -148,51 +160,47 @@ main (int argc, char *argv[]) /* Setup communication pipeline first */ if (pipe (commpipe)) { - fprintf (stderr, - "Failed to create pipe: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); exit (1); } if (pipe (macpipe)) { - fprintf (stderr, - "Failed to create pipe: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to create pipe: %s\n", strerror (errno)); exit (1); } /* Attempt to fork and check for errors */ if ((pid = fork ()) == -1) { - fprintf (stderr, "Failed to fork: %s\n", - STRERROR (errno)); + fprintf (stderr, "Failed to fork: %s\n", strerror (errno)); exit (1); } memset (msg_buf, 0x42, sizeof (msg_buf)); if (pid) { /* A positive (non-negative) PID indicates the parent process */ - if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ - fprintf (stderr, - "Failed to close fd: %s\n", - strerror (errno)); - setvbuf (stdout, (char *) NULL, _IONBF, 0); /* Set non-buffered output on stdout */ + if (0 != close (commpipe[0])) /* Close unused side of pipe (in side) */ + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); + setvbuf (stdout, + (char *) NULL, + _IONBF, + 0); /* Set non-buffered output on stdout */ if (0 != close (macpipe[1])) - fprintf (stderr, - "Failed to close fd: %s\n", - strerror (errno)); + fprintf (stderr, "Failed to close fd: %s\n", strerror (errno)); if (sizeof (hcm) != read (macpipe[0], &hcm, sizeof (hcm))) - fprintf (stderr, - "Failed to read hcm...\n"); + fprintf (stderr, "Failed to read hcm...\n"); fprintf (stderr, - "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", - hcm.mac.mac[0], hcm.mac.mac[1], - hcm.mac.mac[2], hcm.mac.mac[3], hcm.mac.mac[4], hcm.mac.mac[5]); + "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n", + hcm.mac.mac[0], + hcm.mac.mac[1], + hcm.mac.mac[2], + hcm.mac.mac[3], + hcm.mac.mac[4], + hcm.mac.mac[5]); radiotap = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) msg_buf; getRadiotapHeader (radiotap, WLAN_MTU); - getWlanHeader (&radiotap->frame, &outmac, &inmac, - WLAN_MTU); + getWlanHeader (&radiotap->frame, &outmac, &inmac, WLAN_MTU); start = time (NULL); count = 0; while (1) @@ -200,18 +208,18 @@ main (int argc, char *argv[]) ret = write (commpipe[1], msg_buf, WLAN_MTU); if (0 > ret) { - fprintf (stderr, "write failed: %s\n", strerror (errno)); - break; + fprintf (stderr, "write failed: %s\n", strerror (errno)); + break; } count += ret; - akt = time (NULL); + akt = time (NULL); if (akt - start > 30) { - bytes_per_s = count / (akt - start); - bytes_per_s /= 1024; - printf ("send %f kbytes/s\n", bytes_per_s); - start = akt; - count = 0; + bytes_per_s = count / (akt - start); + bytes_per_s /= 1024; + printf ("send %f kbytes/s\n", bytes_per_s); + start = akt; + count = 0; } } } @@ -220,16 +228,19 @@ main (int argc, char *argv[]) /* A zero PID indicates that this is the child process */ (void) close (0); (void) close (1); - if (-1 == dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ + if (-1 == + dup2 (commpipe[0], 0)) /* Replace stdin with the in side of the pipe */ fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); - if (-1 == dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ + if (-1 == + dup2 (macpipe[1], 1)) /* Replace stdout with the out side of the pipe */ fprintf (stderr, "dup2 failed: %s\n", strerror (errno)); (void) close (commpipe[1]); /* Close unused side of pipe (out side) */ (void) close (macpipe[0]); /* Close unused side of pipe (in side) */ /* Replace the child fork with a new process */ - if (execlp - ("gnunet-helper-transport-wlan", "gnunet-helper-transport-wlan", - argv[1], NULL) == -1) + if (execlp ("gnunet-helper-transport-wlan", + "gnunet-helper-transport-wlan", + argv[1], + NULL) == -1) { fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); _exit (1); -- cgit v1.2.3