domainname.c revision 26402
12862Swollman/*
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 * 3. All advertising materials mentioning features or use of this software
142862Swollman *    must display the following acknowledgement:
152862Swollman *	This product includes software developed by the University of
162862Swollman *	California, Berkeley and its contributors.
172862Swollman * 4. Neither the name of the University nor the names of its contributors
182862Swollman *    may be used to endorse or promote products derived from this software
192862Swollman *    without specific prior written permission.
202862Swollman *
212862Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222862Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
232862Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
242862Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
252862Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
262862Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
272862Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
282862Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
292862Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
302862Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
312862Swollman * SUCH DAMAGE.
3220420Ssteve *
3326402Scharnier *	$Id: domainname.c,v 1.8 1997/02/22 14:03:01 peter Exp $
342862Swollman */
352862Swollman
362862Swollman#ifndef lint
3720420Sstevestatic char const copyright[] =
382862Swollman"@(#) Copyright (c) 1988, 1993\n\
392862Swollman	The Regents of the University of California.  All rights reserved.\n";
402862Swollman#endif /* not lint */
412862Swollman
422862Swollman#ifndef lint
4320420Sstevestatic char const sccsid[] = "From: @(#)hostname.c	8.1 (Berkeley) 5/31/93";
442862Swollman#endif /* not lint */
452862Swollman
462862Swollman#include <sys/param.h>
472862Swollman
482862Swollman#include <err.h>
492862Swollman#include <stdio.h>
502862Swollman#include <stdlib.h>
512862Swollman#include <string.h>
522862Swollman#include <unistd.h>
532862Swollman
5426402Scharnierextern char *__progname;
5526402Scharnier
5626402Scharniervoid usage __P((void));
5726402Scharnier
582862Swollmanint
592862Swollmanmain(argc,argv)
602862Swollman	int argc;
612862Swollman	char *argv[];
622862Swollman{
6326402Scharnier	int ch;
647165Sjoerg	char domainname[MAXHOSTNAMELEN];
652862Swollman
6626402Scharnier	while ((ch = getopt(argc, argv, "")) != -1)
6726402Scharnier		switch (ch) {
6826402Scharnier		default:
6926402Scharnier			usage();
7026402Scharnier		}
7126402Scharnier	argc -= optind;
7226402Scharnier	argv += optind;
732862Swollman
7426402Scharnier	if (argc > 1)
7526402Scharnier		usage();
7626402Scharnier
772862Swollman	if (*argv) {
782862Swollman		if (setdomainname(*argv, strlen(*argv)))
792862Swollman			err(1, "setdomainname");
802862Swollman	} else {
812862Swollman		if (getdomainname(domainname, sizeof(domainname)))
822862Swollman			err(1, "getdomainname");
832862Swollman		(void)printf("%s\n", domainname);
842862Swollman	}
852862Swollman	exit(0);
862862Swollman}
8726402Scharnier
8826402Scharniervoid
8926402Scharnierusage()
9026402Scharnier{
9126402Scharnier	(void)fprintf(stderr, "usage: %s [ypdomain]\n", __progname);
9226402Scharnier	exit(1);
9326402Scharnier}
94