Skip to content

Commit 9b1065e

Browse files
authored
Merge pull request #952 from pi-hole/fix/case-insensitive_mac
Use case-insensitive comparison for MAC addresses
2 parents c86107e + 01c36ef commit 9b1065e

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/database/network-table.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,17 +1160,7 @@ void parse_neighbor_cache(void)
11601160
// only the changed to the database are collected for latter
11611161
// commitment. Read-only access such as this SELECT command will be
11621162
// executed immediately on the database.
1163-
char *querystr = NULL;
1164-
rc = asprintf(&querystr, "SELECT id FROM network WHERE hwaddr = \'%s\';", hwaddr);
1165-
if(querystr == NULL || rc < 0)
1166-
{
1167-
logg("Memory allocation failed in parse_arp_cache(): %i", rc);
1168-
break;
1169-
}
1170-
1171-
// Perform SQL query
1172-
int dbID = db_query_int(querystr);
1173-
free(querystr);
1163+
int dbID = find_device_by_hwaddr(hwaddr);
11741164

11751165
if(dbID == DB_FAILED)
11761166
{
@@ -1392,19 +1382,19 @@ bool unify_hwaddr(void)
13921382

13931383
// Update firstSeen with lowest value across all rows with the same hwaddr
13941384
dbquery("UPDATE network "\
1395-
"SET firstSeen = (SELECT MIN(firstSeen) FROM network WHERE hwaddr = \'%s\') "\
1385+
"SET firstSeen = (SELECT MIN(firstSeen) FROM network WHERE hwaddr = \'%s\' COLLATE NOCASE) "\
13961386
"WHERE id = %i;",\
13971387
hwaddr, id);
13981388

13991389
// Update numQueries with sum of all rows with the same hwaddr
14001390
dbquery("UPDATE network "\
1401-
"SET numQueries = (SELECT SUM(numQueries) FROM network WHERE hwaddr = \'%s\') "\
1391+
"SET numQueries = (SELECT SUM(numQueries) FROM network WHERE hwaddr = \'%s\' COLLATE NOCASE) "\
14021392
"WHERE id = %i;",\
14031393
hwaddr, id);
14041394

14051395
// Remove all other lines with the same hwaddr but a different id
14061396
dbquery("DELETE FROM network "\
1407-
"WHERE hwaddr = \'%s\' "\
1397+
"WHERE hwaddr = \'%s\' COLLATE NOCASE "\
14081398
"AND id != %i;",\
14091399
hwaddr, id);
14101400

0 commit comments

Comments
 (0)