int main_is_fqdn(const char *progname, const int argc, const char **argv){ if(argc<2) help_is_fqdn(); int r = is_fqdn(argv[1]); return r; }
/* Try to get a fully qualified domain name. */ static char *get_hostname (void) { #if HAS_TCPIP_CODE struct hostent *host_entry = NULL; #endif char buf[256], *b; char domain_name[256]; #ifdef JED_HOSTNAME if (is_fqdn (JED_HOSTNAME)) return SLang_create_slstring (JED_HOSTNAME); #endif b = buf; if ((-1 == gethostname (buf, sizeof (buf))) || (*buf == 0)) { b = getenv ("HOSTNAME"); if ((b == NULL) || (*b == 0)) return NULL; } #if HAS_TCPIP_CODE /* gethostname may not provide the full name so use gethostbyname * to get more information. Why isn't there a simplified interface to * get the FQDN!!!! */ host_entry = gethostbyname (b); #if defined(TRY_AGAIN) && !defined(MULTINET) if ((host_entry == NULL) && (h_errno == TRY_AGAIN)) { sleep (2); host_entry = gethostbyname (b); } #endif if ((host_entry != NULL) && (host_entry->h_name != NULL) && (host_entry->h_name[0] != 0)) { char **aliases; if (is_fqdn ((char *)host_entry->h_name)) return SLang_create_slstring ((char *)host_entry->h_name); if (NULL != (aliases = host_entry->h_aliases)) { while (*aliases != NULL) { if (is_fqdn (*aliases)) return SLang_create_slstring (*aliases); aliases++; } } /* We have no FQDN */ b = (char *)host_entry->h_name; } #endif /* HAS_TCPIP_CODE */ if (*b == 0) return NULL; if ((0 == is_fqdn (b)) && (0 == get_domainname (domain_name, sizeof (domain_name)))) { return combine_host_and_domain (b, domain_name); } /* Oh well */ return SLang_create_slstring (b); }