summaryrefslogtreecommitdiff
path: root/whois.c
diff options
context:
space:
mode:
authorMarco d'Itri <md@linux.it>2014-10-15 14:30:35 +0200
committerMarco d'Itri <md@linux.it>2014-10-15 14:30:35 +0200
commit3aa160e6a14c9f14055d1864763c6408c363e6ef (patch)
tree84476980d3e881fe5ca1703f19645804d9cdfa1a /whois.c
parent257abceab316ce713f9af75e2a1ff7ad03e34254 (diff)
downloadwhois-3aa160e6a14c9f14055d1864763c6408c363e6ef.tar.gz
Add in_domain() to check if the argument is a subdomain
Diffstat (limited to 'whois.c')
-rw-r--r--whois.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/whois.c b/whois.c
index c4afc09..60d2971 100644
--- a/whois.c
+++ b/whois.c
@@ -1049,6 +1049,32 @@ int domcmp(const char *dom, const char *tld)
return 0;
}
+/* check if dom is a subdomain of tld */
+int in_domain(const char *dom, const char *tld)
+{
+ size_t dom_len, tld_len;
+ const char *p = NULL;
+
+ if ((dom_len = strlen(dom)) == 0)
+ return 0;
+
+ if ((tld_len = strlen(tld)) == 0)
+ return 0;
+
+ /* dom cannot be shorter than what we are looking for */
+ /* -1 to ignore dom containing just a dot and tld */
+ if (tld_len >= dom_len - 1)
+ return 0;
+
+ p = dom + dom_len - tld_len;
+
+ /* fail if the character before tld is not a dot */
+ if (*(p - 1) != '.')
+ return 0;
+
+ return strcaseeq(p, tld);
+}
+
const char *is_new_gtld(const char *s)
{
int i;