X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fdns-domain.c;h=e716d333e4b031b60b989c6699af5b7581e1992e;hp=20a44ce4e11bf4ba84ffd6446ad193c095cae370;hb=9fc688865394518a68539070e10d8c9eb1f0dd6e;hpb=f08ce65bef386c42d6a1c0171dac612512772c70 diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 20a44ce4e..e716d333e 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -464,6 +464,28 @@ int dns_name_endswith(const char *name, const char *suffix) { } } +int dns_name_between(const char *a, const char *b, const char *c) { + int n; + + /* Determine if b is strictly greater than a and strictly smaller than c. + We consider the order of names to be circular, so that if a is + strictly greater than c, we consider b to be between them if it is + either greater than a or smaller than c. This is how the canonical + DNS name order used in NSEC records work. */ + + n = dns_name_compare_func(a, c); + if (n == 0) + return -EINVAL; + else if (n < 0) + /* a<---b--->c */ + return dns_name_compare_func(a, b) < 0 && + dns_name_compare_func(b, c) < 0; + else + /* <--b--c a--b--> */ + return dns_name_compare_func(b, c) < 0 || + dns_name_compare_func(a, b) < 0; +} + int dns_name_reverse(int family, const union in_addr_union *a, char **ret) { const uint8_t *p; int r;