Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ ctld [OPTIONS] FILE
--rd Print registered domain
--fqdn Print fully-qualified-domain-name
--private Use private suffix list as well
--domain Print effective 2nd level label
--err Print Errors only
--custom=<param> Add a comma-separated list of custom suffixes (no space)
-h , --help Print this help message
Expand Down
12 changes: 10 additions & 2 deletions src/ctld.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int main(int argc, char ** argv){
{.short_option=0, .long_option = "tld", .has_param = NO_PARAM, .help="Print suffix", .tag="print_tld"},
{.short_option=0, .long_option = "rd", .has_param = NO_PARAM, .help="Print registered domain", .tag="print_rd"},
{.short_option=0, .long_option = "fqdn", .has_param = NO_PARAM, .help="Print fully-qualified-domain-name", .tag="print_fqdn"},
{.short_option=0, .long_option = "domain", .has_param = NO_PARAM, .help="Print effective 2nd level label", .tag="print_domain"},
{.short_option=0, .long_option = "private", .has_param = NO_PARAM, .help="Use private suffix list as well", .tag="use_private"},
{.short_option=0, .long_option = "err", .has_param = NO_PARAM, .help="Print Errors only", .tag="print_err"},
{.short_option=0, .long_option = "custom", .has_param = HAS_PARAM, .help="Add a comma-separated list of custom suffixes (no space)", .tag="custom_suffix"},
Expand All @@ -41,7 +42,7 @@ int main(int argc, char ** argv){
arg_show_help(&cmd, argc, argv);
return 1;
}
int print_tld, print_rd, print_fqdn, use_private, print_err;
int print_tld, print_rd, print_fqdn, print_domain, use_private, print_err;
if (arg_is_tag_set(pargs, "print_help")){
arg_show_help(&cmd, argc, argv);
return 0;
Expand All @@ -53,6 +54,7 @@ int main(int argc, char ** argv){
print_tld = arg_is_tag_set(pargs, "print_tld")?1:0;
print_rd = arg_is_tag_set(pargs, "print_rd")?1:0;
print_fqdn = arg_is_tag_set(pargs, "print_fqdn")?1:0;
print_domain = arg_is_tag_set(pargs, "print_domain")?1:0;
use_private = arg_is_tag_set(pargs, "use_private")?1:0;
print_err = arg_is_tag_set(pargs, "print_err")?1:0;
char * filename = cmd.extra?cmd.extra:NULL;
Expand All @@ -75,7 +77,7 @@ int main(int argc, char ** argv){
return 1;
}
// set this as the default option
if (print_rd == 0 && print_tld == 0 && print_fqdn == 0)
if (print_rd == 0 && print_tld == 0 && print_fqdn == 0 && print_domain == 0)
print_rd = 1;

char * l = NULL;
Expand Down Expand Up @@ -218,6 +220,12 @@ int main(int argc, char ** argv){
printf("\t");
PRINTIFSET(result->suffix);
p++;
}
if (print_domain){
if (p)
printf("\t");
PRINTIFSET(result->domain);
p++;
}
printf("\n");
}
Expand Down
4 changes: 4 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ test $(echo "http://xn--npth-5q5a1g.nạpthẻ.vn/app" | ./bin/ctld --rd) == 'xn

test $(echo "nạpthẻ.vn" | ./bin/ctld --rd) == 'xn--npth-5q5a1g.vn' || echo $FAIL
test $(echo "xn--npth-5q5a1g.nạpthẻ.vn" | ./bin/ctld --rd) == 'xn--npth-5q5a1g.vn' || echo $FAIL

test $(echo "xn--npth-5q5a1g.nạpthẻ.vn" | ./bin/ctld --domain) == 'xn--npth-5q5a1g' || echo $FAIL
test $(echo "https://freefire.xn--npth-5q5a1g.vn/app" | ./bin/ctld --domain) == 'xn--npth-5q5a1g' || echo $FAIL
test $(echo "https://test.vic.edu.au/app" | ./bin/ctld --domain) == 'test' || echo $FAIL