1139969Simp/*-
22862Swollman * Copyright (c) 1988, 1993
32862Swollman *	The Regents of the University of California.  All rights reserved.
42862Swollman *
52862Swollman * Redistribution and use in source and binary forms, with or without
62862Swollman * modification, are permitted provided that the following conditions
72862Swollman * are met:
82862Swollman * 1. Redistributions of source code must retain the above copyright
92862Swollman *    notice, this list of conditions and the following disclaimer.
102862Swollman * 2. Redistributions in binary form must reproduce the above copyright
112862Swollman *    notice, this list of conditions and the following disclaimer in the
122862Swollman *    documentation and/or other materials provided with the distribution.
132862Swollman * 4. Neither the name of the University nor the names of its contributors
142862Swollman *    may be used to endorse or promote products derived from this software
152862Swollman *    without specific prior written permission.
162862Swollman *
172862Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
182862Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
192862Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
202862Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
212862Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
222862Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
232862Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
242862Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
252862Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
262862Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272862Swollman * SUCH DAMAGE.
282862Swollman */
292862Swollman
30114433Sobrien#if 0
312862Swollman#ifndef lint
3220420Sstevestatic char const copyright[] =
332862Swollman"@(#) Copyright (c) 1988, 1993\n\
342862Swollman	The Regents of the University of California.  All rights reserved.\n";
352862Swollman#endif /* not lint */
362862Swollman
372862Swollman#ifndef lint
3820420Sstevestatic char const sccsid[] = "From: @(#)hostname.c	8.1 (Berkeley) 5/31/93";
39114433Sobrien#endif /* not lint */
4036009Scharnier#endif
4199109Sobrien#include <sys/cdefs.h>
4299109Sobrien__FBSDID("$FreeBSD$");
432862Swollman
442862Swollman#include <sys/param.h>
452862Swollman
462862Swollman#include <err.h>
472862Swollman#include <stdio.h>
482862Swollman#include <stdlib.h>
492862Swollman#include <string.h>
502862Swollman#include <unistd.h>
512862Swollman
5290108Simpstatic void usage(void);
5326402Scharnier
542862Swollmanint
5590108Simpmain(int argc, char *argv[])
562862Swollman{
5726402Scharnier	int ch;
587165Sjoerg	char domainname[MAXHOSTNAMELEN];
592862Swollman
6026402Scharnier	while ((ch = getopt(argc, argv, "")) != -1)
6126402Scharnier		switch (ch) {
6291080Smarkm		case '?':
6391080Smarkm			/* fall through */
6426402Scharnier		default:
6526402Scharnier			usage();
6626402Scharnier		}
6726402Scharnier	argc -= optind;
6826402Scharnier	argv += optind;
692862Swollman
7026402Scharnier	if (argc > 1)
7126402Scharnier		usage();
7226402Scharnier
732862Swollman	if (*argv) {
7476874Skris		if (setdomainname(*argv, (int)strlen(*argv)))
752862Swollman			err(1, "setdomainname");
762862Swollman	} else {
7776874Skris		if (getdomainname(domainname, (int)sizeof(domainname)))
782862Swollman			err(1, "getdomainname");
792862Swollman		(void)printf("%s\n", domainname);
802862Swollman	}
812862Swollman	exit(0);
822862Swollman}
8326402Scharnier
8490108Simpstatic void
8590108Simpusage(void)
8626402Scharnier{
8726434Scharnier	(void)fprintf(stderr, "usage: domainname [ypdomain]\n");
8826402Scharnier	exit(1);
8926402Scharnier}
90