71 lines
2.1 KiB
C
71 lines
2.1 KiB
C
/*
|
|
*----------------------------------------------------------------------
|
|
* "THE BEER-WARE LICENSE" (Revision 42):
|
|
* <jeang3nie@HitchHiker-Linux.org> wrote this file. As long as you
|
|
* retain this notice you can do whatever you want with this stuff. If
|
|
* we meet some day, and you think this stuff is worth it, you can buy
|
|
* me a beer in return.
|
|
* ---------------------------------------------------------------------
|
|
* ______ _______ _ _________
|
|
* ( __ \ ( ___ )( ( /|( )\__ __/
|
|
* | ( \ )| ( ) || \ ( ||/ ) (
|
|
* | | ) || | | || \ | | | |
|
|
* | | | || | | || (\ \) | | |
|
|
* | | ) || | | || | \ | | |
|
|
* | (__/ )| (___) || ) \ | | |
|
|
* (______/ (_______)|/ )_) )_(
|
|
*
|
|
* _______ _______ _ _________ _______
|
|
* ( ____ )( ___ )( \ /|\__ __/( ____ \
|
|
* | ( )|| ( ) || \ ( | ) ( | ( |/
|
|
* | (____)|| (___) || \ | | | | | |
|
|
* | _____)| ___ || (\ \) | | | | |
|
|
* | ( | ( ) || | \ | | | | |
|
|
* | ) | ) ( || ) \ |___) (___| (____|\
|
|
* |/ |/ \||/ \_)\_______/(_______/
|
|
*
|
|
*/
|
|
|
|
#define _DEFAULT_SOURCE
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <libgen.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
static const char *__progname;
|
|
|
|
static void usage() {
|
|
fprintf(stderr,
|
|
"Usage: %s [domainname]\n", __progname);
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
__progname = basename(argv[0]);
|
|
if (argc > 2) {
|
|
usage();
|
|
}
|
|
if (argv[1]) {
|
|
if (!strncmp(argv[1], "-", 1)) {
|
|
fprintf(stderr, "%s: unknown option\n", argv[1]);
|
|
usage();
|
|
}
|
|
if (setdomainname(argv[1], strlen(argv[1])) != 0) {
|
|
perror("setdomainname");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
} else {
|
|
char domainname[MAXHOSTNAMELEN];
|
|
if (getdomainname(domainname, sizeof(domainname)) != 0) {
|
|
perror("getdomainname");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
puts(domainname);
|
|
}
|
|
return 0;
|
|
}
|