From 66c552de33469f3b2619ed398436addfe843adea Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 8 Feb 2017 09:32:56 +0100 Subject: llmnrd: Use strncasecmp() instead of open-coding it Use strncasecmp() from to compare the hostnames. Signed-off-by: Tobias Klauser --- llmnr.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/llmnr.c b/llmnr.c index ec7726e..9436341 100644 --- a/llmnr.c +++ b/llmnr.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -52,7 +53,7 @@ void llmnr_init(const char *hostname, bool ipv6) static bool llmnr_name_matches(const uint8_t *query) { - uint8_t i, n = llmnr_hostname[0]; + uint8_t n = llmnr_hostname[0]; /* length */ if (query[0] != n) @@ -61,16 +62,7 @@ static bool llmnr_name_matches(const uint8_t *query) if (query[1 + n] != 0) return false; - for (i = 1; i <= n; i++) { - char a = query[i]; - char b = llmnr_hostname[i]; - a = isalpha(a) ? tolower(a) : a; - b = isalpha(b) ? tolower(b) : b; - if (a != b) { - return false; - } - } - return true; + return strncasecmp((const char *)&query[1], &llmnr_hostname[1], n) == 0; } static void llmnr_respond(unsigned int ifindex, const struct llmnr_hdr *hdr, -- cgit v1.2.3-54-g00ecf