/* * Figure out the nis domain name */ static int determine_nis_domain(void) { static int nis_not_running = 0; char default_domain[YPMAXDOMAIN]; if (nis_not_running) return ENOENT; if (getdomainname(default_domain, sizeof(default_domain)) < 0) { nis_not_running = 1; plog(XLOG_ERROR, "getdomainname: %m"); return EIO; } if (!*default_domain) { nis_not_running = 1; plog(XLOG_INFO, "NIS domain name is not set. NIS ignored."); return ENOENT; } domain = strdup(default_domain); return 0; }
static int netgroup_match(const char *group, const char *machine, const char *user) { #if 0 /* original code */ #ifdef NIS static char *mydomain = 0; if (mydomain == 0) yp_get_default_domain(&mydomain); return (innetgr(group, machine, user, mydomain)); #else syslog(LOG_ERR, "NIS netgroup support not configured"); return (NO); #endif #else /* works better with glibc? */ static char *mydomain = 0; if (mydomain == 0) { static char domain[MAXHOSTNAMELEN+1]; getdomainname(domain, MAXHOSTNAMELEN); mydomain = domain; } return innetgr(group, machine, user, mydomain); #endif }
static inline char *localhostname(void) { char hostname[1024] = {0}; #ifdef PHP_WIN32 if (SUCCESS == gethostname(hostname, lenof(hostname))) { return estrdup(hostname); } #elif defined(HAVE_GETHOSTNAME) if (SUCCESS == gethostname(hostname, lenof(hostname))) { # if defined(HAVE_GETDOMAINNAME) size_t hlen = strlen(hostname); if (hlen <= lenof(hostname) - lenof("(none)")) { hostname[hlen++] = '.'; if (SUCCESS == getdomainname(&hostname[hlen], lenof(hostname) - hlen)) { if (!strcmp(&hostname[hlen], "(none)")) { hostname[hlen - 1] = '\0'; } return estrdup(hostname); } } # endif if (strcmp(hostname, "(none)")) { return estrdup(hostname); } } #endif return estrndup("localhost", lenof("localhost")); }
/* * Construct an Internet address representation. * If the nflag has been supplied, give * numeric value, otherwise try for symbolic name. */ static inline void inetname(struct sockaddr_in *from) { char *cp; static char domain[MAXHOSTNAMELEN + 1]; char name[MAXHOSTNAMELEN + 1]; static int first = 1; const char *ina; if (first && !nflag) { first = 0; if (getdomainname(domain, MAXHOSTNAMELEN) != 0) domain[0] = 0; } cp = 0; if (!nflag && from->sin_addr.s_addr != INADDR_ANY) { if(INET_rresolve(name, sizeof(name), from, 0x4000, 0xffffffff) >= 0) { if ((cp = strchr(name, '.')) && !strcmp(cp + 1, domain)) *cp = 0; cp = (char *)name; } } ina = inet_ntoa(from->sin_addr); if (nflag) printf(" %s", ina); else printf(" %s (%s)", (cp ? cp : ina), ina); }
int main(int argc, char *argv[]) { int ch; char domainname[MAXHOSTNAMELEN]; while ((ch = getopt(argc, argv, "")) != -1) switch (ch) { case '?': /* fall through */ default: usage(); } argc -= optind; argv += optind; if (argc > 1) usage(); if (*argv) { if (setdomainname(*argv, (int)strlen(*argv))) err(1, "setdomainname"); } else { if (getdomainname(domainname, (int)sizeof(domainname))) err(1, "getdomainname"); (void)printf("%s\n", domainname); } exit(0); }
int host2netname (char netname[MAXNETNAMELEN + 1], const char *host, const char *domain) { char *p; char hostname[MAXHOSTNAMELEN + 1]; char domainname[MAXHOSTNAMELEN + 1]; char *dot_in_host; size_t i; netname[0] = '\0'; /* make null first (no need for memset) */ if (host == NULL) __gethostname (hostname, MAXHOSTNAMELEN); else { strncpy (hostname, host, MAXHOSTNAMELEN); hostname[MAXHOSTNAMELEN] = '\0'; } dot_in_host = strchr (hostname, '.'); if (domain == NULL) { p = dot_in_host; if (p) { ++p; strncpy (domainname, p, MAXHOSTNAMELEN); domainname[MAXHOSTNAMELEN] = '\0'; } else { domainname[0] = 0; getdomainname (domainname, MAXHOSTNAMELEN); } } else { strncpy (domainname, domain, MAXHOSTNAMELEN); domainname[MAXHOSTNAMELEN] = '\0'; } i = strlen (domainname); if (i == 0) /* No domainname */ return 0; if (domainname[i - 1] == '.') domainname[i - 1] = 0; if (dot_in_host) /* strip off rest of name */ *dot_in_host = '\0'; if ((strlen (domainname) + strlen (hostname) + OPSYS_LEN + 3) > MAXNETNAMELEN) return 0; sprintf (netname, "%s.%s@%s", OPSYS, hostname, domainname); return 1; }
int __getdomainname_chk (char *buf, size_t buflen, size_t nreal) { if (buflen > nreal) __chk_fail (); return getdomainname (buf, buflen); }
/*@C PetscGetHostName - Returns the name of the host. This attempts to return the entire Internet name. It may not return the same name as MPI_Get_processor_name(). Not Collective Input Parameter: . nlen - length of name Output Parameter: . name - contains host name. Must be long enough to hold the name This is the fully qualified name, including the domain. Level: developer Concepts: machine name Concepts: host name Fortran Version: In Fortran this routine has the format $ character*(64) name $ call PetscGetHostName(name,ierr) .seealso: PetscGetUserName(),PetscGetArchType() @*/ PetscErrorCode PetscGetHostName(char name[],size_t nlen) { char *domain; PetscErrorCode ierr; #if defined(PETSC_HAVE_UNAME) && !defined(PETSC_HAVE_GETCOMPUTERNAME) struct utsname utname; #endif PetscFunctionBegin; #if defined(PETSC_HAVE_GETCOMPUTERNAME) { size_t nnlen = nlen; GetComputerName((LPTSTR)name,(LPDWORD)(&nnlen)); } #elif defined(PETSC_HAVE_UNAME) uname(&utname); ierr = PetscStrncpy(name,utname.nodename,nlen); CHKERRQ(ierr); #elif defined(PETSC_HAVE_GETHOSTNAME) gethostname(name,nlen); #elif defined(PETSC_HAVE_SYSINFO_3ARG) sysinfo(SI_HOSTNAME,name,nlen); #endif /* if there was not enough room then system call will not null terminate name */ name[nlen-1] = 0; /* See if this name includes the domain */ ierr = PetscStrchr(name,'.',&domain); CHKERRQ(ierr); if (!domain) { size_t l,ll; ierr = PetscStrlen(name,&l); CHKERRQ(ierr); if (l == nlen-1) PetscFunctionReturn(0); name[l++] = '.'; name[l] = 0; #if defined(PETSC_HAVE_SYSINFO_3ARG) sysinfo(SI_SRPC_DOMAIN,name+l,nlen-l); #elif defined(PETSC_HAVE_GETDOMAINNAME) if (getdomainname(name+l,nlen - l)) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_SYS,"getdomainname()"); #endif /* check if domain name is not a dnsdomainname and nuke it */ ierr = PetscStrlen(name,&ll); CHKERRQ(ierr); if (ll > 4) { const char *suffixes[] = {".edu",".com",".net",".org",".mil",0}; PetscInt index; ierr = PetscStrendswithwhich(name,suffixes,&index); CHKERRQ(ierr); if (!suffixes[index]) { ierr = PetscInfo1(0,"Rejecting domainname, likely is NIS %s\n",name); CHKERRQ(ierr); name[l-1] = 0; } } } PetscFunctionReturn(0); }
string Socket::getfqdn() { char fqdn[256]; ::gethostname(fqdn, 256); char* first_dot = strstr(fqdn, "."); if (first_dot != NULL) { *first_dot = 0; } // getnameinfo does not return aliases, which means we get "localhost" // on Linux if that's the first // entry for 127.0.0.1 in /etc/hosts #ifndef __sun char domainname[256]; // getdomainname is not a public call on Solaris, apparently if (getdomainname(domainname, 256) == 0 && domainname[0] != 0 && strcmp(domainname, "(none)") != 0 && strcmp(domainname, fqdn) != 0 && strstr(domainname, "localdomain") == NULL) { strcat(fqdn, domainname); } else { #endif // Try gethostbyaddr, like Python uint32_t local_host_addr = inet_addr("127.0.0.1"); hostent* hostents = gethostbyaddr( reinterpret_cast<char*>(&local_host_addr), sizeof(uint32_t), AF_INET ); if (hostents != NULL) { if ( strchr(hostents->h_name, '.') != NULL && strstr(hostents->h_name, "localhost") == NULL ) { strncpy(fqdn, hostents->h_name, 256); } else { for (uint8_t i = 0; hostents->h_aliases[i] != NULL; i++) { if ( strchr(hostents->h_aliases[i], '.') != NULL && strstr(hostents->h_name, "localhost") == NULL ) { strncpy(fqdn, hostents->h_aliases[i], 256); break; } } } } #ifndef __sun } #endif return fqdn; }
int ArgusInitializeAuthentication (struct ARGUS_INPUT *input) { int retn = 1; #ifdef ARGUS_SASL struct sockaddr_in localaddr, remoteaddr; int salen, fd = input->fd; char *localhostname = NULL; if ((retn = sasl_client_init(RaCallBacks)) != SASL_OK) ArgusLog (LOG_ERR, "ArgusInitializeAuthentication() sasl_client_init %d", retn); localhostname = ArgusCalloc (1, 1024); gethostname(localhostname, 1024); if (!strchr (localhostname, '.')) { strcat (localhostname, "."); getdomainname (&localhostname[strlen(localhostname)], 1024 - strlen(localhostname)); } if ((retn = sasl_client_new("argus", localhostname, NULL, SASL_SECURITY_LAYER, &input->sasl_conn)) != SASL_OK) ArgusLog (LOG_ERR, "ArgusInitializeAuthentication() sasl_client_new %d", retn); /* set external properties here sasl_setprop(input->sasl_conn, SASL_SSF_EXTERNAL, &extprops); */ /* set required security properties here sasl_setprop(input->sasl_conn, SASL_SEC_PROPS, &secprops); */ /* set ip addresses */ salen = sizeof(localaddr); if (getsockname(fd, (struct sockaddr *)&localaddr, &salen) < 0) perror("getsockname"); salen = sizeof(remoteaddr); if (getpeername(fd, (struct sockaddr *)&remoteaddr, &salen) < 0) perror("getpeername"); if ((retn = sasl_setprop(input->sasl_conn, SASL_IP_LOCAL, &localaddr)) != SASL_OK) ArgusLog (LOG_ERR, "ArgusInitializeAuthentication() error setting localaddr %d", retn); if ((retn = sasl_setprop(input->sasl_conn, SASL_IP_REMOTE, &remoteaddr)) != SASL_OK) ArgusLog (LOG_ERR, "ArgusInitializeAuthentication() error setting remoteaddr %d", retn); retn = 1; #endif #ifdef ARGUSDEBUG ArgusDebug (2, "ArgusInitializeAuthentication () returning %d\n", retn); #endif return (retn); }
int yp_get_default_domain(char **domp) { *domp = NULL; if (_yp_domain[0] == '\0') if (getdomainname(_yp_domain, sizeof _yp_domain)) return YPERR_NODOM; *domp = _yp_domain; if (_yp_domain[0] == '\0') return YPERR_NODOM; return 0; }
int main( int argc, char *argv[] ) { int ch; char domainname[MAXHOSTNAMELEN]; while ( ( ch = getopt( argc, argv, "" ) ) != -1 ) exit( 1 ); argc -= optind; argv += optind; if ( argc > 1 ) exit( 1 ); if ( *argv ) if ( setdomainname( *argv, (int) strlen( *argv ) ) ) err( 1, "setdomainname" ); else if ( getdomainname( domainname, (int) sizeof( domainname ) ) ) err( 1, "getdomainname" ); (void) printf( "%s\n", domainname ); exit( 0 ); }
/* netgroup_match - match group against machine or user */ static bool netgroup_match (const char *group, const char *machine, const char *user) { static char *mydomain = (char *)0; if (mydomain == (char *)0) { static char domain[MAXHOSTNAMELEN + 1]; getdomainname (domain, MAXHOSTNAMELEN); mydomain = domain; } return (innetgr (group, machine, user, mydomain) != 0); }
CertGenDlg::CertGenDlg(QWidget* parent) : QDialog(parent) { setupUi(this); char hn[HOST_NAME_MAX], dn[HOST_NAME_MAX]; if (gethostname(hn, sizeof hn) != -1) { if (getdomainname(dn, sizeof dn) != -1) { QString host = QString(hn) + '.' + dn; lineHostname->setText(host); } } }
NSPR_END_EXTERN_C #endif #endif /* SOLARIS */ int GetDomainName(char* name, int nameLen) { #ifdef SOLARIS long res = sysinfo(SI_SRPC_DOMAIN, name, nameLen); return (res < 0 ? res : 0); #else return getdomainname(name, nameLen); #endif }
static char *getNISserver(pam_handle_t *pamh, unsigned int ctrl) { char *master; char *domainname; int port, err; #ifdef HAVE_YP_GET_DEFAULT_DOMAIN if ((err = yp_get_default_domain(&domainname)) != 0) { pam_syslog(pamh, LOG_WARNING, "can't get local yp domain: %s", yperr_string(err)); return NULL; } #elif defined(HAVE_GETDOMAINNAME) char domainname_res[256]; if (getdomainname (domainname_res, sizeof (domainname_res)) == 0) { if (strcmp (domainname_res, "(none)") == 0) { /* If domainname is not set, some systems will return "(none)" */ domainname_res[0] = '\0'; } domainname = domainname_res; } else domainname = NULL; #endif if ((err = yp_master(domainname, "passwd.byname", &master)) != 0) { pam_syslog(pamh, LOG_WARNING, "can't find the master ypserver: %s", yperr_string(err)); return NULL; } port = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP); if (port == 0) { pam_syslog(pamh, LOG_WARNING, "yppasswdd not running on NIS master host"); return NULL; } if (port >= IPPORT_RESERVED) { pam_syslog(pamh, LOG_WARNING, "yppasswd daemon running on illegal port"); return NULL; } if (on(UNIX_DEBUG, ctrl)) { pam_syslog(pamh, LOG_DEBUG, "Use NIS server on %s with port %d", master, port); } return master; }
/* * On success return the current malloced and NUL terminated domainname. * On error return malloced and NUL terminated string "?". * This is an illegal first character for a domainname. * The returned malloced string must be freed by the caller. */ char* FAST_FUNC safe_getdomainname(void) { #if defined(__linux__) /* The field domainname of struct utsname is Linux specific. */ struct utsname uts; uname(&uts); return xstrndup(!uts.domainname[0] ? "?" : uts.domainname, sizeof(uts.domainname)); #else /* We really don't care about people with domain names wider than most screens */ char buf[256]; int r = getdomainname(buf, sizeof(buf)); buf[sizeof(buf)-1] = '\0'; return xstrdup(r < 0 ? "?" : buf); #endif }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { tst_require_root(); tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Save current domainname */ if ((getdomainname(old_domain_name, MAX_NAME_LEN)) < 0) { tst_brkm(TBROK, NULL, "getdomainname() failed while" " getting current domain name"); } TEST_PAUSE; }
static int mk_reply(int attr, void *data, int sz) { char *s = data; int n, i, ret = 0; switch (attr) { case IB_PING_ATTR: break; /* nothing to do here, just reply */ case IB_HOSTINFO_ATTR: if (gethostname(s, sz) < 0) snprintf(s, sz, "?hostname?"); s[sz - 1] = 0; if ((n = strlen(s)) >= sz - 1) { ret = sz; break; } s[n] = '.'; s += n + 1; sz -= n + 1; ret += n + 1; if (getdomainname(s, sz) < 0) snprintf(s, sz, "?domainname?"); if ((n = strlen(s)) == 0) s[-1] = 0; /* no domain */ else ret += n; break; case IB_CPUINFO_ATTR: s[0] = '\0'; for (i = 0; i < host_ncpu && sz > 0; i++) { n = snprintf(s, sz, "cpu %d: model %s MHZ %s\n", i, cpus[i].model, cpus[i].mhz); if (n >= sz) { IBWARN("cpuinfo truncated"); ret = sz; break; } sz -= n; s += n; ret += n; } ret++; break; default: DEBUG("unknown attr %d", attr); } return ret; }
int clip_GETDOMAINNAME(ClipMachine *mp) { /* return host domain name of process */ char buf[256]; #ifdef OS_MINGW DWORD s; GetComputerName(buf, &s); #else if ( getdomainname(buf,255) != 0 ) _clip_retc(mp, ""); else #endif _clip_retc(mp, buf); return 0; }
void dns_test(cyg_addrword_t p) { struct in_addr addr; struct hostent *hent; char dn[256]; CYG_TEST_INIT(); init_all_network_interfaces(); CYG_TEST_INFO("Starting dns2 test"); getdomainname(dn,sizeof(dn)); diag_printf("INFO:<DHCP said domain name is %s>\n",dn); #ifndef USE_HARDCODED_DOMAIN // If not hard-coded we can't tell what it's _meant_ to be CYG_TEST_CHECK(!strncmp(dn,_LOOKUP_DOMAINNAME,sizeof(_LOOKUP_DOMAINNAME)), "DHCP got the wrong domainname"); #endif //ifdef _LOOKUP_DOMAINNAME /* Expect _LOOKUP_IP as the answer. This is a CNAME lookup */ inet_aton(_LOOKUP_IP, &addr); hent = gethostbyname(_LOOKUP_FQDN); if (hent != NULL) { diag_printf("PASS:<%s is %s>\n", hent->h_name, inet_ntoa(*(struct in_addr *)hent->h_addr)); if (0 != memcmp((void*)&addr, (void*)(hent->h_addr), sizeof(struct in_addr))) { diag_printf("FAIL:<expected " _LOOKUP_FQDN " to be " _LOOKUP_IP ">\n"); } } else { diag_printf("FAIL:<Asked for " _LOOKUP_FQDN ". No answer: %s>\n", hstrerror(h_errno)); } /* Now just the hostname */ #ifdef USE_HARDCODED_DOMAIN // set the domain by hand if required. setdomainname(_LOOKUP_DOMAINNAME, sizeof(_LOOKUP_DOMAINNAME)); #endif //ifdef _LOOKUP_DOMAINNAME hent = gethostbyname(_LOOKUP_HOSTNAME); if (hent != NULL) { diag_printf("PASS:<%s is %s>\n", _LOOKUP_HOSTNAME, inet_ntoa(*(struct in_addr *)hent->h_addr)); } else { diag_printf("FAIL:<Asked for " _LOOKUP_HOSTNAME ". No answer: %s>\n", hstrerror(h_errno)); } CYG_TEST_FINISH("dns2 test completed"); }
static int gen_issuer(const char * dn[], uint8_t *buf, int *offset) { int ret = X509_OK; int seq_offset; int seq_size = pre_adjust_with_size( ASN1_SEQUENCE, &seq_offset, buf, offset); char fqdn[128]; /* we need the common name, so if not configured, work out the fully * qualified domain name */ if (dn[X509_COMMON_NAME] == NULL || strlen(dn[X509_COMMON_NAME]) == 0) { int fqdn_len; gethostname(fqdn, sizeof(fqdn)); fqdn_len = strlen(fqdn); fqdn[fqdn_len++] = '.'; getdomainname(&fqdn[fqdn_len], sizeof(fqdn)-fqdn_len); fqdn_len = strlen(fqdn); if (fqdn[fqdn_len-1] == '.') /* ensure '.' is not last char */ fqdn[fqdn_len-1] = 0; dn[X509_COMMON_NAME] = fqdn; } if ((ret = gen_dn(dn[X509_COMMON_NAME], 3, buf, offset))) goto error; if (dn[X509_ORGANIZATION] != NULL && strlen(dn[X509_ORGANIZATION]) > 0) { if ((ret = gen_dn(dn[X509_ORGANIZATION], 10, buf, offset))) goto error; } if (dn[X509_ORGANIZATIONAL_UNIT] != NULL && strlen(dn[X509_ORGANIZATIONAL_UNIT]) > 0) { if ((ret = gen_dn(dn[X509_ORGANIZATIONAL_UNIT], 11, buf, offset))) goto error; } adjust_with_size(seq_size, seq_offset, buf, offset); error: return ret; }
static char * get_default_domain(void) { char temp[256]; if (default_domain != NULL) return (default_domain); if (getdomainname(temp, sizeof(temp)) < 0) return (0); if ((int) strlen(temp) > 0) { default_domain = malloc((strlen(temp) + (unsigned)1)); if (default_domain == NULL) return (0); (void) strcpy(default_domain, temp); return (default_domain); } return (0); }
int nix_getdomainname(char *buf, size_t bufsiz, nix_env_t *env) { if (buf == NULL) { nix_env_set_errno(env, EFAULT); return (-1); } if (bufsiz == 0) return (0); if (getdomainname(buf, bufsiz) != 0) { nix_env_set_errno(env, errno); return (-1); } return (0); }
void KWM::setWmCommand(Window w, const QString &command){ static Atom a = 0; if (!a) a = XInternAtom(qt_xdisplay(), "WM_CLIENT_MACHINE", False); setQStringProperty(w, XA_WM_COMMAND, command); QString machine; QString domain; QString all=""; char buf[200]; if (!gethostname(buf, 200)) machine = buf; if (!getdomainname(buf, 200)) domain = buf; if (!machine.isEmpty()) all = machine; if (!domain.isEmpty() && domain != "(none)") all += "." + domain; setQStringProperty(w, a, all); }
static void backup_domain(void) { char domain[MAXHOSTNAMELEN]; int fd; size_t l; ssize_t r,n = 0; memset(domain, 0, sizeof(domain)); ATF_REQUIRE_EQ(0, getdomainname(domain, sizeof(domain))); l = strnlen(domain, MAXHOSTNAMELEN); fd = open(DOMAIN_BACKUP_FILE, O_WRONLY | O_CREAT | O_EXCL, 0644); ATF_REQUIRE(fd >= 0); while ((r = write(fd, domain + n, l - n)) > 0) n += r; ATF_REQUIRE_EQ(0, r); close(fd); }
/* setup() - performs all ONE TIME setup for this test */ void setup() { tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Check whether we are root */ if (geteuid() != 0) { tst_brkm(TBROK, NULL, "Test must be run as root"); } /* Save current domain name */ if ((getdomainname(old_domain_name, sizeof(old_domain_name))) < 0) { tst_brkm(TBROK, NULL, "getdomainname() failed while" " getting current domain name"); } TEST_PAUSE; }
extern char * _DtCmGetLocalDomain(char *hostname) { static char *domain = NULL; char buf[BUFSIZ], *ptr; CLIENT *cl; if (domain == NULL) { domain = (char *)malloc(BUFSIZ); #if defined(sun) || defined(USL) || defined(__uxp__) sysinfo(SI_SRPC_DOMAIN, domain, BUFSIZ - 1); #else getdomainname(domain, BUFSIZ - 1); #endif /* sun || USL || __uxp__ */ /* check domain name */ /* this is a hack to find out the domain name that * is acceptable to the rpc interface, e.g. * DGDO.Eng.Sun.COM is returned by sysinfo but * this name is not acceptable to the rpc interface * hence we need to stripe out the first component */ ptr = domain; if (hostname == NULL) hostname = _DtCmGetLocalHost(); while (1) { snprintf(buf, sizeof buf, "%s.%s", hostname, ptr); if ((cl = clnt_create(buf, 100068, 5, "udp")) == NULL) { ptr = strchr(ptr, '.'); if (ptr) ptr++; else break; } else { clnt_destroy(cl); break; } } if (ptr && ptr != domain) domain = ptr; } return (domain); }
int main(void) { int z; char name[256]; z = gethostname(name , sizeof(name)); if(-1 == z) { fprintf(stderr, "%s\n,: uname", strerror(errno)); exit(1); } printf("hostname = %s\n", name); z = getdomainname(name , sizeof(name)); if(-1 == z) { fprintf(stderr, "%s\n,: uname", strerror(errno)); exit(1); } printf("doaminname = %s\n", name); return 0; }
static void get_host_and_domain(char *data, int sz) { char *s = data; int n; if (gethostname(s, sz) < 0) snprintf(s, sz, "?hostname?"); s[sz - 1] = 0; if ((n = strlen(s)) >= sz) return; s[n] = '.'; s += n + 1; sz -= n + 1; if (getdomainname(s, sz) < 0) snprintf(s, sz, "?domainname?"); if (strlen(s) == 0) s[-1] = 0; /* no domain */ }