domainname.c revision 7165
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.
322862Swollman */
332862Swollman
342862Swollman#ifndef lint
352862Swollmanstatic char copyright[] =
362862Swollman"@(#) Copyright (c) 1988, 1993\n\
372862Swollman	The Regents of the University of California.  All rights reserved.\n";
382862Swollman#endif /* not lint */
392862Swollman
402862Swollman#ifndef lint
412862Swollman/*static char sccsid[] = "From: @(#)hostname.c	8.1 (Berkeley) 5/31/93"; */
422862Swollmanstatic const char rcsid[] =
437165Sjoerg	"$Id: domainname.c,v 1.4 1994/09/26 02:14:27 wollman Exp $";
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
542862Swollmanint
552862Swollmanmain(argc,argv)
562862Swollman	int argc;
572862Swollman	char *argv[];
582862Swollman{
597165Sjoerg	char domainname[MAXHOSTNAMELEN];
602862Swollman
613107Swollman	argc--, argv++;
622862Swollman
632862Swollman	if (*argv) {
642862Swollman		if (setdomainname(*argv, strlen(*argv)))
652862Swollman			err(1, "setdomainname");
662862Swollman	} else {
672862Swollman		if (getdomainname(domainname, sizeof(domainname)))
682862Swollman			err(1, "getdomainname");
692862Swollman		(void)printf("%s\n", domainname);
702862Swollman	}
712862Swollman	exit(0);
722862Swollman}
73