
Путь: Toys/LSB, команды версии: Ver.4 Ver.9 Комментарии в файле hostname.c : Команд: 2 hostname
dnsdomainname
Исходный текст в файле hostname.c #define FOR_hostname
#define FORCE_FLAGS
#include "toys.h"
GLOBALS(
char *F;
)
void hostname_main(void)
{
char *hostname = toybuf, *dot;
struct hostent *h;
gethostname(toybuf, sizeof(toybuf)-1);
if (TT.F && (hostname = xreadfile(TT.F, 0, 0))) {
if (!*chomp(hostname)) {
if (CFG_TOYBOX_FREE) free(hostname);
if (!FLAG(b)) error_exit("empty '%s'", TT.F);
hostname = 0;
}
} else hostname = (FLAG(b) && !*toybuf) ? "localhost" : *toys.optargs;
// Setting?
if (hostname) {
if (sethostname(hostname, strlen(hostname)))
perror_exit("set '%s'", hostname);
return;
}
// We only do the DNS lookup for -d and -f.
if (FLAG(d) || FLAG(f)) {
if (!(h = gethostbyname(toybuf)))
error_exit("gethostbyname: %s", hstrerror(h_errno));
snprintf(toybuf, sizeof(toybuf), "%s", h->h_name);
}
dot = toybuf+strcspn(toybuf, ".");
if (FLAG(s)) *dot = '\0';
xputs(FLAG(d) ? dot+1 : toybuf);
}
void dnsdomainname_main(void)
{
toys.optflags = FLAG_d;
hostname_main();
} |
![]() |