diff --git a/src/dns.c b/src/dns.c
index 9cf4363..bb1e0b3 100644
--- a/src/dns.c
+++ b/src/dns.c
@@ -77,6 +77,46 @@ void dns_print_current_resolutions(struct dns_resolvers *resolvers)
 #endif
 
 /*
+ * Case folding for DNS names (ASCII toupper)
+ * https://tools.ietf.org/html/rfc4343#section-3
+ * Uppercase <length> bytes of <buf> in place.
+ */
+void dns_toupper(unsigned char *buf, int length)
+{
+	int i;
+
+	for (i = 0; i < length; i++) {
+		if (buf[i] >= 0x61 && buf[i] <= 0x7A)
+			buf[i] -= 0x20;
+	}
+}
+
+/*
+ * Case insensitive string comparison
+ * Return value:
+ *  0: str1 is equal to str2
+ * <0: str1 is less than str2
+ * >0: str1 is greater than str2
+ */
+int dns_strnicmp(const unsigned char *str1, const unsigned char *str2, size_t num)
+{
+	unsigned char c1, c2;
+	int i;
+
+	for (i = 0; i < num; i++) {
+		c1 = str1[i];
+		c2 = str2[i];
+		dns_toupper(&c1, 1);
+		dns_toupper(&c2, 1);
+		if (c1 < c2)
+			return -1;
+		else if (c1 > c2)
+			return 1;
+	}
+	return 0;
+}
+
+/*
  * check if there is more than 1 resolution in the resolver's resolution list
  * return value:
  * 0: empty list
@@ -257,7 +297,7 @@ void dns_resolve_recv(struct dgram_conn *dgram)
 		 * We can check only the first query of the list. We send one query at a time
 		 * so we get one query in the response */
 		query = LIST_NEXT(&dns_p->query_list, struct dns_query_item *, list);
-		if (query && memcmp(query->name, resolution->hostname_dn, resolution->hostname_dn_len) != 0) {
+		if (query && dns_strnicmp((unsigned char *)query->name, (unsigned char *)resolution->hostname_dn, resolution->hostname_dn_len) != 0) {
 			nameserver->counters.other += 1;
 			resolution->requester_error_cb(resolution, DNS_RESP_WRONG_NAME);
 			continue;
