mirror of
https://github.com/rfc1036/whois.git
synced 2026-05-03 06:51:09 +00:00
Add in_domain() to check if the argument is a subdomain
This commit is contained in:
parent
257abceab3
commit
3aa160e6a1
26
whois.c
26
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;
|
||||
|
||||
1
whois.h
1
whois.h
@ -29,6 +29,7 @@ unsigned long myinet_aton(const char *);
|
||||
unsigned long asn32_to_long(const char *);
|
||||
int isasciidigit(const char);
|
||||
int domcmp(const char *, const char *);
|
||||
int in_domain(const char *, const char *);
|
||||
const char *is_new_gtld(const char *);
|
||||
int domfind(const char *, const char *[]);
|
||||
char *normalize_domain(const char *);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user