domainname.c revision 1.8
11.8Sthorpej/*	$NetBSD: domainname.c,v 1.8 1997/07/20 06:04:11 thorpej Exp $	*/
21.7Scgd
31.4Scgd/*
41.5Smycroft * Copyright (c) 1988, 1993
51.5Smycroft *	The Regents of the University of California.  All rights reserved.
61.4Scgd *
71.4Scgd * Redistribution and use in source and binary forms, with or without
81.4Scgd * modification, are permitted provided that the following conditions
91.4Scgd * are met:
101.4Scgd * 1. Redistributions of source code must retain the above copyright
111.4Scgd *    notice, this list of conditions and the following disclaimer.
121.4Scgd * 2. Redistributions in binary form must reproduce the above copyright
131.4Scgd *    notice, this list of conditions and the following disclaimer in the
141.4Scgd *    documentation and/or other materials provided with the distribution.
151.5Smycroft * 3. All advertising materials mentioning features or use of this software
161.5Smycroft *    must display the following acknowledgement:
171.5Smycroft *	This product includes software developed by the University of
181.5Smycroft *	California, Berkeley and its contributors.
191.5Smycroft * 4. Neither the name of the University nor the names of its contributors
201.5Smycroft *    may be used to endorse or promote products derived from this software
211.5Smycroft *    without specific prior written permission.
221.4Scgd *
231.5Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
241.5Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
251.5Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
261.5Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
271.5Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
281.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
291.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
301.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
311.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
321.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
331.4Scgd * SUCH DAMAGE.
341.4Scgd */
351.4Scgd
361.8Sthorpej#include <sys/cdefs.h>
371.2Smycroft#ifndef lint
381.8Sthorpej__COPYRIGHT(
391.5Smycroft"@(#) Copyright (c) 1988, 1993\n\
401.8Sthorpej	The Regents of the University of California.  All rights reserved.\n");
411.2Smycroft#endif /* not lint */
421.2Smycroft
431.5Smycroft#ifndef lint
441.7Scgd#if 0
451.7Scgdstatic char sccsid[] = "@(#)hostname.c	8.1 (Berkeley) 5/31/93";
461.7Scgd#else
471.8Sthorpej__RCSID("$NetBSD: domainname.c,v 1.8 1997/07/20 06:04:11 thorpej Exp $");
481.7Scgd#endif
491.5Smycroft#endif /* not lint */
501.5Smycroft
511.5Smycroft#include <sys/param.h>
521.5Smycroft
531.5Smycroft#include <err.h>
541.3Sjtc#include <stdio.h>
551.3Sjtc#include <stdlib.h>
561.3Sjtc#include <string.h>
571.3Sjtc#include <unistd.h>
581.3Sjtc
591.8Sthorpejint main __P((int, char *[]));
601.5Smycroftvoid usage __P((void));
611.1Sderaadt
621.5Smycroftint
631.1Sderaadtmain(argc, argv)
641.3Sjtc	int argc;
651.5Smycroft	char *argv[];
661.1Sderaadt{
671.5Smycroft	int ch;
681.5Smycroft	char domainname[MAXHOSTNAMELEN];
691.1Sderaadt
701.6Smycroft	while ((ch = getopt(argc, argv, "")) != -1)
711.5Smycroft		switch (ch) {
721.5Smycroft		case '?':
731.5Smycroft		default:
741.5Smycroft			usage();
751.5Smycroft		}
761.5Smycroft	argc -= optind;
771.5Smycroft	argv += optind;
781.5Smycroft
791.5Smycroft	if (argc > 1)
801.5Smycroft		usage();
811.3Sjtc
821.5Smycroft	if (*argv) {
831.5Smycroft		if (setdomainname(*argv, strlen(*argv)))
841.5Smycroft			err(1, "setdomainname");
851.3Sjtc	} else {
861.5Smycroft		if (getdomainname(domainname, sizeof(domainname)))
871.5Smycroft			err(1, "getdomainname");
881.5Smycroft		(void)printf("%s\n", domainname);
891.1Sderaadt	}
901.1Sderaadt	exit(0);
911.1Sderaadt}
921.1Sderaadt
931.5Smycroftvoid
941.5Smycroftusage()
951.3Sjtc{
961.5Smycroft
971.6Smycroft	(void)fprintf(stderr, "usage: domainname [name-of-domain]\n");
981.3Sjtc	exit(1);
991.3Sjtc}
100