Skip to content

Commit

Permalink
Added RESOLVEIPV6 config flag + extended comments in source
Browse files Browse the repository at this point in the history
Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Sep 30, 2017
1 parent 0a463ab commit e5847f7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ typedef struct {
bool query_display;
bool analyze_AAAA;
int maxDBdays;
bool resolveIPv6;
} ConfigStruct;

// Dynamic structs
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ Possible settings (**the option shown first is the default**):
- `QUERY_DISPLAY=yes|no` (Display all queries? Set to `no` to hide query display)
- `AAAA_QUERY_ANALYSIS=yes|no` (Allow `FTL` to analyze AAAA queries from pihole.log?)
- `MAXDBDAYS=365` (How long should queries be stored in the database? Setting this to `0` disables the database altogether)
- `RESOLVEIPV6=yes|no` (Should `FTL` try to resolve IPv6 addresses to host names?)

### Implemented keywords (starting with `>`, subject to change):

Expand Down
14 changes: 14 additions & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@ void read_FTLconf(void)
else
logg(" MAXDBDAYS: max age for stored queries is %i days", config.maxDBdays);

// RESOLVEIPV6
// defaults to: Yes
config.resolveIPv6 = true;
buffer = parse_FTLconf(fp, "RESOLVEIPV6");
if(buffer != NULL)
{
if(strcmp(buffer, "no") == 0)
config.resolveIPv6 = false;
}
if(config.resolveIPv6)
logg(" RESOLVEIPV6: Resolve IPv6 addresses");
else
logg(" RESOLVEIPV6: Don\'t resolve IPv6 addresses");

logg("Finished config file parsing");

if(conflinebuffer != NULL)
Expand Down
14 changes: 12 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,15 +718,23 @@ void process_pihole_log(int file)
char *resolveHostname(const char *addr)
{
// Get host name
struct hostent *he;
struct hostent *he = NULL;
char *hostname;
bool IPv6 = false;

// Test if we want to resolve an IPv6 address
if(strstr(addr,":") != NULL)
{
IPv6 = true;
}

if(IPv6 && config.resolveIPv6) // Resolve IPv6 address only if requested
{
struct in6_addr ipaddr;
inet_pton(AF_INET6, addr, &ipaddr);
he = gethostbyaddr(&ipaddr, sizeof ipaddr, AF_INET6);
}
else
else if(!IPv6) // Always resolve IPv4 addresses
{
struct in_addr ipaddr;
inet_pton(AF_INET, addr, &ipaddr);
Expand All @@ -735,11 +743,13 @@ char *resolveHostname(const char *addr)

if(he == NULL)
{
// No hostname found
hostname = calloc(1,sizeof(char));
hostname[0] = '\0';
}
else
{
// Return hostname copied to new memory location
hostname = strdup(he->h_name);
}

Expand Down

0 comments on commit e5847f7

Please sign in to comment.