* Cached data.
*/
struct GNUNET_DNSPARSER_Record *record;
-
};
* tail of a double linked list containing the lookup results
*/
struct RecordListEntry *records_tail;
-
};
* is currently pending, undefined otherwise.
*/
uint16_t dns_id;
-
};
while (NULL != (pos = rc->records_head))
{
- GNUNET_CONTAINER_DLL_remove (rc->records_head,
- rc->records_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos);
GNUNET_DNSPARSER_free_record (pos->record);
GNUNET_free (pos->record);
GNUNET_free (pos);
}
GNUNET_free_non_null (rc->hostname);
- GNUNET_CONTAINER_DLL_remove (cache_head,
- cache_tail,
- rc);
+ GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, rc);
cache_size--;
GNUNET_free (rc);
}
while (NULL != (pos = rc->records_head))
{
- GNUNET_CONTAINER_DLL_remove (rc->records_head,
- rc->records_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos);
GNUNET_DNSPARSER_free_record (pos->record);
GNUNET_free (pos->record);
GNUNET_free (pos);
}
GNUNET_free_non_null (rc->hostname);
- GNUNET_CONTAINER_DLL_remove (hosts_head,
- hosts_tail,
- rc);
+ GNUNET_CONTAINER_DLL_remove (hosts_head, hosts_tail, rc);
cache_size--;
GNUNET_free (rc);
}
static void
free_active_lookup (struct ActiveLookup *al)
{
- GNUNET_CONTAINER_DLL_remove (lookup_head,
- lookup_tail,
- al);
+ GNUNET_CONTAINER_DLL_remove (lookup_head, lookup_tail, al);
if (NULL != al->resolve_handle)
{
GNUNET_DNSSTUB_resolve_cancel (al->resolve_handle);
}
-
/**
* Find out if the configuration file line contains a string
* starting with "nameserver ", and if so, return a copy of
* @return NULL if no nameserver is configured in this @a line
*/
static char *
-extract_dns_server (const char* line,
- size_t line_len)
+extract_dns_server (const char *line, size_t line_len)
{
- if (0 == strncmp (line,
- "nameserver ",
- strlen ("nameserver ")))
+ if (0 == strncmp (line, "nameserver ", strlen ("nameserver ")))
return GNUNET_strndup (line + strlen ("nameserver "),
line_len - strlen ("nameserver "));
return NULL;
* @return NULL if no nameserver is configured in this @a line
*/
static char *
-extract_search_domain (const char* line,
- size_t line_len)
+extract_search_domain (const char *line, size_t line_len)
{
- if (0 == strncmp (line,
- "search ",
- strlen ("search ")))
+ if (0 == strncmp (line, "search ", strlen ("search ")))
return GNUNET_strndup (line + strlen ("search "),
line_len - strlen ("search "));
return NULL;
unsigned int num_dns_servers;
fh = GNUNET_DISK_file_open ("/etc/resolv.conf",
- GNUNET_DISK_OPEN_READ,
- GNUNET_DISK_PERM_NONE);
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_NONE);
if (NULL == fh)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not open /etc/resolv.conf. "
- "DNS resolution will not be possible.\n");
+ "Could not open /etc/resolv.conf. "
+ "DNS resolution will not be possible.\n");
return -1;
}
- if (GNUNET_OK !=
- GNUNET_DISK_file_handle_size (fh,
- &bytes_read))
+ if (GNUNET_OK != GNUNET_DISK_file_handle_size (fh, &bytes_read))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Could not determine size of /etc/resolv.conf. "
- "DNS resolution will not be possible.\n");
+ "Could not determine size of /etc/resolv.conf. "
+ "DNS resolution will not be possible.\n");
GNUNET_DISK_file_close (fh);
return -1;
}
- if ((size_t) bytes_read > SIZE_MAX)
+ if (bytes_read > (off_t) SIZE_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "/etc/resolv.conf file too large to mmap. "
- "DNS resolution will not be possible.\n");
+ "/etc/resolv.conf file too large to mmap. "
+ "DNS resolution will not be possible.\n");
GNUNET_DISK_file_close (fh);
return -1;
}
buf = GNUNET_DISK_file_map (fh,
- &mh,
- GNUNET_DISK_MAP_TYPE_READ,
- (size_t) bytes_read);
+ &mh,
+ GNUNET_DISK_MAP_TYPE_READ,
+ (size_t) bytes_read);
*server_addrs = NULL;
read_offset = 0;
num_dns_servers = 0;
size_t line_len;
char *dns_server;
- newline = strchr (buf + read_offset,
- '\n');
+ newline = strchr (buf + read_offset, '\n');
if (NULL == newline)
break;
line_len = newline - buf - read_offset;
- dns_server = extract_dns_server (buf + read_offset,
- line_len);
+ dns_server = extract_dns_server (buf + read_offset, line_len);
if (NULL != dns_server)
{
- GNUNET_array_append (*server_addrs,
- num_dns_servers,
- dns_server);
+ GNUNET_array_append (*server_addrs, num_dns_servers, dns_server);
}
else if (NULL == my_domain)
{
- my_domain = extract_search_domain (buf + read_offset,
- line_len);
+ my_domain = extract_search_domain (buf + read_offset, line_len);
}
read_offset += line_len + 1;
}
* @param af address family of @a ip, AF_INET or AF_INET6
*/
static char *
-make_reverse_hostname (const void *ip,
- int af)
+make_reverse_hostname (const void *ip, int af)
{
- char *buf = GNUNET_new_array (80,
- char);
+ char *buf = GNUNET_new_array (80, char);
int pos = 0;
if (AF_INET == af)
{
- struct in_addr *addr = (struct in_addr *)ip;
+ struct in_addr *addr = (struct in_addr *) ip;
uint32_t ip_int = addr->s_addr;
for (int i = 3; i >= 0; i--)
{
- int n = GNUNET_snprintf (buf + pos,
- 80 - pos,
- "%u.",
- ((uint8_t *)&ip_int)[i]);
+ int n =
+ GNUNET_snprintf (buf + pos, 80 - pos, "%u.", ((uint8_t *) &ip_int)[i]);
if (n < 0)
{
- GNUNET_free (buf);
- return NULL;
+ GNUNET_free (buf);
+ return NULL;
}
pos += n;
}
- pos += GNUNET_snprintf (buf + pos,
- 80 - pos,
- "in-addr.arpa");
+ pos += GNUNET_snprintf (buf + pos, 80 - pos, "in-addr.arpa");
}
else if (AF_INET6 == af)
{
- struct in6_addr *addr = (struct in6_addr *)ip;
+ struct in6_addr *addr = (struct in6_addr *) ip;
for (int i = 15; i >= 0; i--)
{
- int n = GNUNET_snprintf (buf + pos,
- 80 - pos,
- "%x.",
- addr->s6_addr[i] & 0xf);
+ int n =
+ GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] & 0xf);
if (n < 0)
{
- GNUNET_free (buf);
- return NULL;
+ GNUNET_free (buf);
+ return NULL;
}
pos += n;
- n = GNUNET_snprintf (buf + pos,
- 80 - pos,
- "%x.",
- addr->s6_addr[i] >> 4);
+ n = GNUNET_snprintf (buf + pos, 80 - pos, "%x.", addr->s6_addr[i] >> 4);
if (n < 0)
{
- GNUNET_free (buf);
- return NULL;
+ GNUNET_free (buf);
+ return NULL;
}
pos += n;
}
- pos += GNUNET_snprintf (buf + pos,
- 80 - pos,
- "ip6.arpa");
+ pos += GNUNET_snprintf (buf + pos, 80 - pos, "ip6.arpa");
}
buf[pos] = '\0';
return buf;
static int
send_reply (struct GNUNET_DNSPARSER_Record *record,
uint16_t record_type,
- uint32_t client_request_id,
- struct GNUNET_SERVICE_Client *client)
+ uint32_t client_request_id,
+ struct GNUNET_SERVICE_Client *client)
{
struct GNUNET_RESOLVER_ResponseMessage *msg;
struct GNUNET_MQ_Envelope *env;
payload_len = strlen (record->data.hostname) + 1;
break;
case GNUNET_DNSPARSER_TYPE_A:
- if ( (GNUNET_DNSPARSER_TYPE_A != record_type) &&
- (GNUNET_DNSPARSER_TYPE_ALL != record_type) )
+ if ((GNUNET_DNSPARSER_TYPE_A != record_type) &&
+ (GNUNET_DNSPARSER_TYPE_ALL != record_type))
return GNUNET_NO;
payload = record->data.raw.data;
payload_len = record->data.raw.data_len;
break;
case GNUNET_DNSPARSER_TYPE_AAAA:
- if ( (GNUNET_DNSPARSER_TYPE_AAAA != record_type) &&
- (GNUNET_DNSPARSER_TYPE_ALL != record_type) )
+ if ((GNUNET_DNSPARSER_TYPE_AAAA != record_type) &&
+ (GNUNET_DNSPARSER_TYPE_ALL != record_type))
return GNUNET_NO;
payload = record->data.raw.data;
payload_len = record->data.raw.data_len;
return GNUNET_NO;
}
env = GNUNET_MQ_msg_extra (msg,
- payload_len,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ payload_len,
+ GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
msg->client_id = client_request_id;
- GNUNET_memcpy (&msg[1],
- payload,
- payload_len);
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_memcpy (&msg[1], payload, payload_len);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
return GNUNET_YES;
}
* @param client where to send @a record
*/
static void
-send_end_msg (uint32_t client_request_id,
- struct GNUNET_SERVICE_Client *client)
+send_end_msg (uint32_t client_request_id, struct GNUNET_SERVICE_Client *client)
{
struct GNUNET_RESOLVER_ResponseMessage *msg;
struct GNUNET_MQ_Envelope *env;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending END message\n");
- env = GNUNET_MQ_msg (msg,
- GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending END message\n");
+ env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
msg->client_id = client_request_id;
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env);
}
struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
struct RecordListEntry *n;
- for (struct RecordListEntry *pos = rc->records_head;
- NULL != pos;
- pos = n)
+ for (struct RecordListEntry *pos = rc->records_head; NULL != pos; pos = n)
{
n = pos->next;
if (now.abs_value_us > pos->record->expiration_time.abs_value_us)
{
- GNUNET_CONTAINER_DLL_remove (rc->records_head,
- rc->records_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (rc->records_head, rc->records_tail, pos);
GNUNET_DNSPARSER_free_record (pos->record);
GNUNET_free (pos->record);
GNUNET_free (pos);
*/
static void
process_get (const char *hostname,
- uint16_t record_type,
- uint32_t client_request_id,
- struct GNUNET_SERVICE_Client *client);
+ uint16_t record_type,
+ uint32_t client_request_id,
+ struct GNUNET_SERVICE_Client *client);
/**
static int
try_cache (const char *hostname,
uint16_t record_type,
- uint32_t client_request_id,
- struct GNUNET_SERVICE_Client *client)
+ uint32_t client_request_id,
+ struct GNUNET_SERVICE_Client *client)
{
struct ResolveCache *pos;
struct ResolveCache *next;
in_hosts = GNUNET_NO;
for (pos = hosts_head; NULL != pos; pos = pos->next)
- if (0 == strcmp (pos->hostname,
- hostname))
+ if (0 == strcmp (pos->hostname, hostname))
{
in_hosts = GNUNET_YES;
break;
{
next = pos->next;
if (GNUNET_YES == remove_expired (pos))
- continue;
- if (0 == strcmp (pos->hostname,
- hostname))
- break;
+ continue;
+ if (0 == strcmp (pos->hostname, hostname))
+ break;
}
}
if (NULL == pos)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No cache entry for '%s'\n",
- hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No cache entry for '%s'\n", hostname);
return GNUNET_NO;
}
- if ( (GNUNET_NO == in_hosts) &&
- (cache_head != pos) )
+ if ((GNUNET_NO == in_hosts) && (cache_head != pos))
{
/* move result to head to achieve LRU for cache eviction */
- GNUNET_CONTAINER_DLL_remove (cache_head,
- cache_tail,
- pos);
- GNUNET_CONTAINER_DLL_insert (cache_head,
- cache_tail,
- pos);
+ GNUNET_CONTAINER_DLL_remove (cache_head, cache_tail, pos);
+ GNUNET_CONTAINER_DLL_insert (cache_head, cache_tail, pos);
}
found = GNUNET_NO;
- for (struct RecordListEntry *rle = pos->records_head;
- NULL != rle;
+ for (struct RecordListEntry *rle = pos->records_head; NULL != rle;
rle = rle->next)
{
const struct GNUNET_DNSPARSER_Record *record = rle->record;
"Found cache entry for '%s', record type '%u'\n",
hostname,
record_type);
- if ( (GNUNET_DNSPARSER_TYPE_CNAME == record->type) &&
- (GNUNET_DNSPARSER_TYPE_CNAME != record_type) &&
- (GNUNET_NO == found) )
+ if ((GNUNET_DNSPARSER_TYPE_CNAME == record->type) &&
+ (GNUNET_DNSPARSER_TYPE_CNAME != record_type) && (GNUNET_NO == found))
{
const char *hostname = record->data.hostname;
- process_get (hostname,
- record_type,
- client_request_id,
- client);
+ process_get (hostname, record_type, client_request_id, client);
return GNUNET_YES; /* counts as a cache "hit" */
}
- found |= send_reply (rle->record,
- record_type,
- client_request_id,
- client);
+ found |= send_reply (rle->record, record_type, client_request_id, client);
}
if (GNUNET_NO == found)
return GNUNET_NO; /* had records, but none matched! */
- send_end_msg (client_request_id,
- client);
+ send_end_msg (client_request_id, client);
return GNUNET_YES;
}
struct GNUNET_DNSPARSER_Query query;
struct GNUNET_DNSPARSER_Packet packet;
- query.name = (char *)hostname;
+ query.name = (char *) hostname;
query.type = type;
query.dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
- memset (&packet,
- 0,
- sizeof (packet));
+ memset (&packet, 0, sizeof (packet));
packet.num_queries = 1;
packet.queries = &query;
packet.id = htons (dns_id);
packet.flags.recursion_desired = 1;
if (GNUNET_OK !=
- GNUNET_DNSPARSER_pack (&packet,
- UINT16_MAX,
- packet_buf,
- packet_size))
+ GNUNET_DNSPARSER_pack (&packet, UINT16_MAX, packet_buf, packet_size))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to pack query for hostname `%s'\n",
+ "Failed to pack query for hostname `%s'\n",
hostname);
packet_buf = NULL;
return GNUNET_SYSERR;
}
static void
-cache_answers(const char* name,
- struct GNUNET_DNSPARSER_Record *records,
- unsigned int num_records)
+cache_answers (const char *name,
+ struct GNUNET_DNSPARSER_Record *records,
+ unsigned int num_records)
{
struct ResolveCache *rc;
struct GNUNET_DNSPARSER_Record *record;
record = &records[i];
for (rc = cache_head; NULL != rc; rc = rc->next)
- if (0 == strcasecmp (rc->hostname,
- name))
+ if (0 == strcasecmp (rc->hostname, name))
break;
if (NULL == rc)
{
rc = GNUNET_new (struct ResolveCache);
rc->hostname = GNUNET_strdup (name);
- GNUNET_CONTAINER_DLL_insert (cache_head,
- cache_tail,
- rc);
+ GNUNET_CONTAINER_DLL_insert (cache_head, cache_tail, rc);
cache_size++;
}
/* TODO: ought to check first if we have this exact record
already in the cache! */
rle = GNUNET_new (struct RecordListEntry);
rle->record = GNUNET_DNSPARSER_duplicate_record (record);
- GNUNET_CONTAINER_DLL_insert (rc->records_head,
- rc->records_tail,
- rle);
+ GNUNET_CONTAINER_DLL_insert (rc->records_head, rc->records_tail, rle);
}
}
struct ActiveLookup *al = cls;
struct GNUNET_DNSPARSER_Packet *parsed;
- parsed = GNUNET_DNSPARSER_parse ((const char *)dns,
- dns_len);
+ parsed = GNUNET_DNSPARSER_parse ((const char *) dns, dns_len);
if (NULL == parsed)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
GNUNET_DNSPARSER_free_packet (parsed);
return;
}
- if (0 == parsed->num_answers + parsed->num_authority_records + parsed->num_additional_records)
+ if (0 == parsed->num_answers + parsed->num_authority_records +
+ parsed->num_additional_records)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"DNS reply (hostname %s, request ID %u) contains no answers\n",
al->hostname,
(unsigned int) al->client_request_id);
/* resume by trying again from cache */
- if (GNUNET_NO ==
- try_cache (al->hostname,
- al->record_type,
- al->client_request_id,
- al->client))
- /* cache failed, tell client we could not get an answer */
+ if (GNUNET_NO == try_cache (al->hostname,
+ al->record_type,
+ al->client_request_id,
+ al->client))
+ /* cache failed, tell client we could not get an answer */
{
- send_end_msg (al->client_request_id,
- al->client);
+ send_end_msg (al->client_request_id, al->client);
}
GNUNET_DNSPARSER_free_packet (parsed);
free_active_lookup (al);
al->hostname,
(unsigned int) al->client_request_id);
/* add to cache */
- cache_answers(al->hostname,
- parsed->answers, parsed->num_answers);
- cache_answers(al->hostname,
- parsed->authority_records, parsed->num_authority_records);
- cache_answers(al->hostname,
- parsed->additional_records, parsed->num_additional_records);
+ cache_answers (al->hostname, parsed->answers, parsed->num_answers);
+ cache_answers (al->hostname,
+ parsed->authority_records,
+ parsed->num_authority_records);
+ cache_answers (al->hostname,
+ parsed->additional_records,
+ parsed->num_additional_records);
/* see if we need to do the 2nd request for AAAA records */
- if ( (GNUNET_DNSPARSER_TYPE_ALL == al->record_type) &&
- (GNUNET_NO == al->did_aaaa) )
+ if ((GNUNET_DNSPARSER_TYPE_ALL == al->record_type) &&
+ (GNUNET_NO == al->did_aaaa))
{
char *packet_buf;
size_t packet_size;
dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT16_MAX);
- if (GNUNET_OK ==
- pack (al->hostname,
- GNUNET_DNSPARSER_TYPE_AAAA,
- dns_id,
- &packet_buf,
- &packet_size))
+ if (GNUNET_OK == pack (al->hostname,
+ GNUNET_DNSPARSER_TYPE_AAAA,
+ dns_id,
+ &packet_buf,
+ &packet_size))
{
al->did_aaaa = GNUNET_YES;
al->dns_id = dns_id;
GNUNET_DNSSTUB_resolve_cancel (al->resolve_handle);
- al->resolve_handle =
- GNUNET_DNSSTUB_resolve (dnsstub_ctx,
- packet_buf,
- packet_size,
- &handle_resolve_result,
- al);
+ al->resolve_handle = GNUNET_DNSSTUB_resolve (dnsstub_ctx,
+ packet_buf,
+ packet_size,
+ &handle_resolve_result,
+ al);
GNUNET_free (packet_buf);
GNUNET_DNSPARSER_free_packet (parsed);
return;
}
/* resume by trying again from cache */
- if (GNUNET_NO ==
- try_cache (al->hostname,
- al->record_type,
- al->client_request_id,
- al->client))
- /* cache failed, tell client we could not get an answer */
+ if (GNUNET_NO == try_cache (al->hostname,
+ al->record_type,
+ al->client_request_id,
+ al->client))
+ /* cache failed, tell client we could not get an answer */
{
- send_end_msg (al->client_request_id,
- al->client);
+ send_end_msg (al->client_request_id, al->client);
}
free_active_lookup (al);
GNUNET_DNSPARSER_free_packet (parsed);
struct ActiveLookup *al = cls;
al->timeout_task = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "DNS lookup timeout!\n");
- send_end_msg (al->client_request_id,
- al->client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS lookup timeout!\n");
+ send_end_msg (al->client_request_id, al->client);
free_active_lookup (al);
}
* @return #GNUNET_OK if the DNS query is now pending
*/
static int
-resolve_and_cache (const char* hostname,
+resolve_and_cache (const char *hostname,
uint16_t record_type,
uint32_t client_request_id,
struct GNUNET_SERVICE_Client *client)
uint16_t dns_id;
uint16_t type;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "resolve_and_cache `%s'\n",
- hostname);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "resolve_and_cache `%s'\n", hostname);
dns_id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT16_MAX);
type = GNUNET_DNSPARSER_TYPE_A;
else
type = record_type;
- if (GNUNET_OK !=
- pack (hostname,
- type,
- dns_id,
- &packet_buf,
- &packet_size))
+ if (GNUNET_OK != pack (hostname, type, dns_id, &packet_buf, &packet_size))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to pack query for hostname `%s'\n",
al->client_request_id = client_request_id;
al->dns_id = dns_id;
al->client = client;
- al->timeout_task = GNUNET_SCHEDULER_add_delayed (DNS_TIMEOUT,
- &handle_resolve_timeout,
- al);
- al->resolve_handle =
- GNUNET_DNSSTUB_resolve (dnsstub_ctx,
- packet_buf,
- packet_size,
- &handle_resolve_result,
- al);
+ al->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (DNS_TIMEOUT, &handle_resolve_timeout, al);
+ al->resolve_handle = GNUNET_DNSSTUB_resolve (dnsstub_ctx,
+ packet_buf,
+ packet_size,
+ &handle_resolve_result,
+ al);
GNUNET_free (packet_buf);
- GNUNET_CONTAINER_DLL_insert (lookup_head,
- lookup_tail,
- al);
+ GNUNET_CONTAINER_DLL_insert (lookup_head, lookup_tail, al);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Resolving %s, client_request_id = %u, dns_id = %u\n",
hostname,
{
char fqdn[255];
- if (GNUNET_NO !=
- try_cache (hostname,
- record_type,
- client_request_id,
- client))
+ if (GNUNET_NO != try_cache (hostname, record_type, client_request_id, client))
return;
- if ( (NULL != my_domain) &&
- (NULL == strchr (hostname,
- (unsigned char) '.')) &&
- (strlen (hostname) + strlen (my_domain) <= 253) )
+ if ((NULL != my_domain) && (NULL == strchr (hostname, (unsigned char) '.')) &&
+ (strlen (hostname) + strlen (my_domain) <= 253))
{
- GNUNET_snprintf (fqdn,
- sizeof (fqdn),
- "%s.%s",
- hostname,
- my_domain);
+ GNUNET_snprintf (fqdn, sizeof (fqdn), "%s.%s", hostname, my_domain);
}
else if (strlen (hostname) < 255)
{
- GNUNET_snprintf (fqdn,
- sizeof (fqdn),
- "%s",
- hostname);
+ GNUNET_snprintf (fqdn, sizeof (fqdn), "%s", hostname);
}
else
{
GNUNET_SERVICE_client_drop (client);
return;
}
- if (GNUNET_NO ==
- try_cache (fqdn,
- record_type,
- client_request_id,
- client))
+ if (GNUNET_NO == try_cache (fqdn, record_type, client_request_id, client))
{
if (GNUNET_OK !=
- resolve_and_cache (fqdn,
- record_type,
- client_request_id,
- client))
+ resolve_and_cache (fqdn, record_type, client_request_id, client))
{
- send_end_msg (client_request_id,
- client);
+ send_end_msg (client_request_id, client);
}
}
}
* @return #GNUNET_OK if @a get is well-formed
*/
static int
-check_get (void *cls,
- const struct GNUNET_RESOLVER_GetMessage *get)
+check_get (void *cls, const struct GNUNET_RESOLVER_GetMessage *get)
{
uint16_t size;
int direction;
af = ntohl (get->af);
switch (af)
{
- case AF_INET:
- if (size != sizeof (struct in_addr))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- break;
- case AF_INET6:
- if (size != sizeof (struct in6_addr))
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
- break;
- default:
+ case AF_INET:
+ if (size != sizeof (struct in_addr))
+ {
GNUNET_break (0);
return GNUNET_SYSERR;
+ }
+ break;
+ case AF_INET6:
+ if (size != sizeof (struct in6_addr))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ break;
+ default:
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
}
return GNUNET_OK;
}
* @param msg the actual message
*/
static void
-handle_get (void *cls,
- const struct GNUNET_RESOLVER_GetMessage *msg)
+handle_get (void *cls, const struct GNUNET_RESOLVER_GetMessage *msg)
{
struct GNUNET_SERVICE_Client *client = cls;
int direction;
/* IP from hostname */
hostname = GNUNET_strdup ((const char *) &msg[1]);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client asks to resolve `%s'\n",
- hostname);
+ "Client asks to resolve `%s'\n",
+ hostname);
switch (af)
{
- case AF_UNSPEC:
- {
- process_get (hostname,
- GNUNET_DNSPARSER_TYPE_ALL,
- client_request_id,
- client);
- break;
- }
- case AF_INET:
- {
- process_get (hostname,
- GNUNET_DNSPARSER_TYPE_A,
- client_request_id,
- client);
- break;
- }
- case AF_INET6:
- {
- process_get (hostname,
- GNUNET_DNSPARSER_TYPE_AAAA,
- client_request_id,
- client);
- break;
- }
- default:
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "got invalid af: %d\n",
- af);
- GNUNET_assert (0);
- }
+ case AF_UNSPEC: {
+ process_get (hostname,
+ GNUNET_DNSPARSER_TYPE_ALL,
+ client_request_id,
+ client);
+ break;
+ }
+ case AF_INET: {
+ process_get (hostname,
+ GNUNET_DNSPARSER_TYPE_A,
+ client_request_id,
+ client);
+ break;
+ }
+ case AF_INET6: {
+ process_get (hostname,
+ GNUNET_DNSPARSER_TYPE_AAAA,
+ client_request_id,
+ client);
+ break;
+ }
+ default: {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got invalid af: %d\n", af);
+ GNUNET_assert (0);
+ }
}
}
else
{
/* hostname from IP */
- hostname = make_reverse_hostname (&msg[1],
- af);
+ hostname = make_reverse_hostname (&msg[1], af);
process_get (hostname,
GNUNET_DNSPARSER_TYPE_PTR,
client_request_id,
rec->type = rec_type;
rec->dns_traffic_class = GNUNET_TUN_DNS_CLASS_INTERNET;
rec->name = GNUNET_strdup (hostname);
- rec->data.raw.data = GNUNET_memdup (data,
- data_size);
+ rec->data.raw.data = GNUNET_memdup (data, data_size);
rec->data.raw.data_len = data_size;
rle = GNUNET_new (struct RecordListEntry);
rle->record = rec;
rc = GNUNET_new (struct ResolveCache);
rc->hostname = GNUNET_strdup (hostname);
- GNUNET_CONTAINER_DLL_insert (rc->records_head,
- rc->records_tail,
- rle);
- GNUNET_CONTAINER_DLL_insert (hosts_head,
- hosts_tail,
- rc);
+ GNUNET_CONTAINER_DLL_insert (rc->records_head, rc->records_tail, rle);
+ GNUNET_CONTAINER_DLL_insert (hosts_head, hosts_tail, rc);
}
* @param line_len number of bytes in @a line
*/
static void
-extract_hosts (const char *line,
- size_t line_len)
+extract_hosts (const char *line, size_t line_len)
{
const char *c;
struct in_addr v4;
char *tok;
/* ignore everything after '#' */
- c = memrchr (line,
- (unsigned char) '#',
- line_len);
+ c = memrchr (line, (unsigned char) '#', line_len);
if (NULL != c)
line_len = c - line;
/* ignore leading whitespace */
- while ( (0 < line_len) &&
- isspace ((unsigned char) *line) )
+ while ((0 < line_len) && isspace ((unsigned char) *line))
{
line++;
line_len--;
}
- tbuf = GNUNET_strndup (line,
- line_len);
+ tbuf = GNUNET_strndup (line, line_len);
tok = strtok (tbuf, " \t");
if (NULL == tok)
{
GNUNET_free (tbuf);
return;
}
- if (1 == inet_pton (AF_INET,
- tok,
- &v4))
+ if (1 == inet_pton (AF_INET, tok, &v4))
{
while (NULL != (tok = strtok (NULL, " \t")))
- add_host (tok,
- GNUNET_DNSPARSER_TYPE_A,
- &v4,
- sizeof (struct in_addr));
+ add_host (tok, GNUNET_DNSPARSER_TYPE_A, &v4, sizeof (struct in_addr));
}
- else if (1 == inet_pton (AF_INET6,
- tok,
- &v6))
+ else if (1 == inet_pton (AF_INET6, tok, &v6))
{
while (NULL != (tok = strtok (NULL, " \t")))
- add_host (tok,
- GNUNET_DNSPARSER_TYPE_AAAA,
- &v6,
- sizeof (struct in6_addr));
+ add_host (tok, GNUNET_DNSPARSER_TYPE_AAAA, &v6, sizeof (struct in6_addr));
}
GNUNET_free (tbuf);
}
GNUNET_DISK_PERM_NONE);
if (NULL == fh)
{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to open /etc/hosts");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Failed to open /etc/hosts");
return;
}
- if (GNUNET_OK !=
- GNUNET_DISK_file_handle_size (fh,
- &bytes_read))
+ if (GNUNET_OK != GNUNET_DISK_file_handle_size (fh, &bytes_read))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Could not determin size of /etc/hosts. "
GNUNET_DISK_file_close (fh);
return;
}
- if ((size_t) bytes_read > SIZE_MAX)
+ if (bytes_read > (off_t) SIZE_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"/etc/hosts file too large to mmap. "
const char *newline;
size_t line_len;
- newline = strchr (buf + read_offset,
- '\n');
+ newline = strchr (buf + read_offset, '\n');
if (NULL == newline)
break;
line_len = newline - buf - read_offset;
- extract_hosts (buf + read_offset,
- line_len);
+ extract_hosts (buf + read_offset, line_len);
read_offset += line_len + 1;
}
GNUNET_DISK_file_unmap (mh);
(void) cfg;
(void) sh;
load_etc_hosts ();
- GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
- cls);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, cls);
dnsstub_ctx = GNUNET_DNSSTUB_start (128);
dns_servers = NULL;
num_dns_servers = lookup_dns_servers (&dns_servers);
if (0 >= num_dns_servers)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("No DNS server available. DNS resolution will not be possible.\n"));
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ ("No DNS server available. DNS resolution will not be possible.\n"));
return;
}
for (int i = 0; i < num_dns_servers; i++)
* @param internal_cls should be equal to @a c
*/
static void
-disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *c,
- void *internal_cls)
+disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
{
struct ActiveLookup *n;
(void) cls;
GNUNET_assert (c == internal_cls);
n = lookup_head;
- for (struct ActiveLookup *al = n;
- NULL != al;
- al = n)
+ for (struct ActiveLookup *al = n; NULL != al; al = n)
{
n = al->next;
if (al->client == c)
/**
* Define "main" method using service macro.
*/
-GNUNET_SERVICE_MAIN
-("resolver",
- GNUNET_SERVICE_OPTION_NONE,
- &init_cb,
- &connect_cb,
- &disconnect_cb,
- NULL,
- GNUNET_MQ_hd_var_size (get,
- GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST,
- struct GNUNET_RESOLVER_GetMessage,
- NULL),
- GNUNET_MQ_handler_end ());
+GNUNET_SERVICE_MAIN (
+ "resolver",
+ GNUNET_SERVICE_OPTION_NONE,
+ &init_cb,
+ &connect_cb,
+ &disconnect_cb,
+ NULL,
+ GNUNET_MQ_hd_var_size (get,
+ GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST,
+ struct GNUNET_RESOLVER_GetMessage,
+ NULL),
+ GNUNET_MQ_handler_end ());
#if defined(LINUX) && defined(__GLIBC__)
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((constructor))
-GNUNET_RESOLVER_memory_init ()
+void __attribute__ ((constructor)) GNUNET_RESOLVER_memory_init ()
{
mallopt (M_TRIM_THRESHOLD, 4 * 1024);
mallopt (M_TOP_PAD, 1 * 1024);