/* check all labels the from the parent labels, from right to left.
* When they /all/ match we have found a subdomain
*/
- j = sub_lab;
- for (i = par_lab; i >= 0; i--) {
+ j = sub_lab - 1; /* we count from zero, thank you */
+ for (i = par_lab -1; i >= 0; i--) {
tmp_sub = ldns_dname_label(sub, j);
tmp_par = ldns_dname_label(parent, i);
ldns_rdf_print(stdout, tmp_par);
printf("\n");
+ if (ldns_rdf_compare(tmp_sub, tmp_par) != 0) {
+ /* they are not equal */
+ ldns_rdf_deep_free(tmp_sub);
+ ldns_rdf_deep_free(tmp_par);
+ return false;
+ }
+
ldns_rdf_deep_free(tmp_sub);
ldns_rdf_deep_free(tmp_par);
j--;
-
}
- return false;
+ return true;
}
ldns_rdf *
{
ldns_rdf *test;
ldns_rdf *test2;
+ ldns_rdf *parent;
+ ldns_rdf *child;
ldns_rdf *newlabel;
test = ldns_dname_new_frm_str("bla.miek.nl");
test2 = ldns_dname_new_frm_str("www.bla.miek.nl");
+ parent = ldns_dname_new_frm_str("yahoo.com");
+ child = ldns_dname_new_frm_str("miek.nl");
+
ldns_rdf_print(stdout, test);
printf("\n");
printf("\n");
ldns_rdf_deep_free(newlabel);
- (void)ldns_dname_is_subdomain(test2, test);
+ if (ldns_dname_is_subdomain(test2, test)) {
+ printf("Yes, it's a subdomain\n");
+ } else {
+ printf("Go fuck your self\n");
+ }
+
+ if (ldns_dname_is_subdomain(child, parent)) {
+ printf("Yes, it's a subdomain\n");
+ } else {
+ printf("Go fuck your self\n");
+ }
return 0;
}