summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-02-08 09:32:56 +0100
committerTobias Klauser <tklauser@distanz.ch>2017-02-08 09:34:39 +0100
commit66c552de33469f3b2619ed398436addfe843adea (patch)
tree57233c752d68500febbc177fbaf085933567a6fa
parent5ff55246e69340fbcf1fa1283c9bd259aae8b2c6 (diff)
llmnrd: Use strncasecmp() instead of open-coding it
Use strncasecmp() from <strings.h> to compare the hostnames. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r--llmnr.c14
1 files 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 <stdbool.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h>
#include <unistd.h>
#include <arpa/inet.h>
@@ -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,