mirror of
https://github.com/pi-hole/FTL.git
synced 2024-10-26 16:52:18 +02:00
Remove duplicate function getDatabaseHostname()
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
@@ -1581,82 +1581,6 @@ void updateMACVendorRecords(void)
|
||||
dbclose();
|
||||
}
|
||||
|
||||
char *__attribute__((malloc)) getDatabaseHostname(const char *ipaddr)
|
||||
{
|
||||
// Test if this is an IPv6 address
|
||||
bool IPv6 = false;
|
||||
if(ipaddr != NULL && strstr(ipaddr,":") != NULL)
|
||||
{
|
||||
IPv6 = true;
|
||||
}
|
||||
|
||||
// Do we want to resolve IPv4/IPv6 names at all?
|
||||
if( (IPv6 && !config.resolveIPv6) ||
|
||||
(!IPv6 && !config.resolveIPv4))
|
||||
{
|
||||
if(config.debug & DEBUG_RESOLVER)
|
||||
{
|
||||
logg(" ---> \"\" (configured to not resolve %s host names)",
|
||||
IPv6 ? "IPv6" : "IPv4");
|
||||
}
|
||||
return strdup("");
|
||||
}
|
||||
|
||||
// Open pihole-FTL.db database file if needed
|
||||
const bool db_already_open = FTL_DB_avail();
|
||||
if(!db_already_open && !dbopen())
|
||||
{
|
||||
logg("getDatabaseHostname(\"%s\") - Failed to open DB", ipaddr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Prepare SQLite statement
|
||||
sqlite3_stmt *stmt = NULL;
|
||||
const char *querystr = "SELECT name FROM network_addresses "
|
||||
"WHERE name IS NOT NULL AND ip = ?;";
|
||||
int rc = sqlite3_prepare_v2(FTL_db, querystr, -1, &stmt, NULL);
|
||||
if( rc != SQLITE_OK ){
|
||||
logg("getDatabaseHostname(\"%s\") - SQL error prepare: %s",
|
||||
ipaddr, sqlite3_errstr(rc));
|
||||
if(!db_already_open)
|
||||
dbclose();
|
||||
return strdup("");
|
||||
}
|
||||
|
||||
// Bind ipaddr to prepared statement
|
||||
if((rc = sqlite3_bind_text(stmt, 1, ipaddr, -1, SQLITE_STATIC)) != SQLITE_OK)
|
||||
{
|
||||
logg("getDatabaseHostname(\"%s\"): Failed to bind ip: %s",
|
||||
ipaddr, sqlite3_errstr(rc));
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
if(!db_already_open)
|
||||
dbclose();
|
||||
return strdup("");
|
||||
}
|
||||
|
||||
char *hostname = NULL;
|
||||
rc = sqlite3_step(stmt);
|
||||
if(rc == SQLITE_ROW)
|
||||
{
|
||||
// Database record found (result might be empty)
|
||||
hostname = strdup((char*)sqlite3_column_text(stmt, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not found or error (will be logged automatically through our SQLite3 hook)
|
||||
hostname = strdup("");
|
||||
}
|
||||
|
||||
// Finalize statement and close database handle
|
||||
sqlite3_reset(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
if(!db_already_open)
|
||||
dbclose();
|
||||
|
||||
return hostname;
|
||||
}
|
||||
|
||||
// Get hardware address of device identified by IP address
|
||||
char *__attribute__((malloc)) getMACfromIP(const char *ipaddr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user