domainname.c revision 1.11
11.11Smycroft/*	$NetBSD: domainname.c,v 1.11 1998/07/28 05:31:24 mycroft 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.10Smycroft__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\
391.8Sthorpej	The Regents of the University of California.  All rights reserved.\n");
401.2Smycroft#endif /* not lint */
411.2Smycroft
421.5Smycroft#ifndef lint
431.7Scgd#if 0
441.7Scgdstatic char sccsid[] = "@(#)hostname.c	8.1 (Berkeley) 5/31/93";
451.7Scgd#else
461.11Smycroft__RCSID("$NetBSD: domainname.c,v 1.11 1998/07/28 05:31:24 mycroft Exp $");
471.7Scgd#endif
481.5Smycroft#endif /* not lint */
491.5Smycroft
501.5Smycroft#include <sys/param.h>
511.5Smycroft
521.5Smycroft#include <err.h>
531.3Sjtc#include <stdio.h>
541.3Sjtc#include <stdlib.h>
551.3Sjtc#include <string.h>
561.3Sjtc#include <unistd.h>
571.3Sjtc
581.10Smycroftvoid usage __P((void));
591.8Sthorpejint main __P((int, char *[]));
601.1Sderaadt
611.5Smycroftint
621.1Sderaadtmain(argc, argv)
631.3Sjtc	int argc;
641.5Smycroft	char *argv[];
651.1Sderaadt{
661.5Smycroft	int ch;
671.5Smycroft	char domainname[MAXHOSTNAMELEN];
681.1Sderaadt
691.6Smycroft	while ((ch = getopt(argc, argv, "")) != -1)
701.5Smycroft		switch (ch) {
711.5Smycroft		case '?':
721.5Smycroft		default:
731.5Smycroft			usage();
741.5Smycroft		}
751.5Smycroft	argc -= optind;
761.5Smycroft	argv += optind;
771.5Smycroft
781.5Smycroft	if (argc > 1)
791.5Smycroft		usage();
801.3Sjtc
811.5Smycroft	if (*argv) {
821.10Smycroft		if (setdomainname(*argv, strlen(*argv)))
831.5Smycroft			err(1, "setdomainname");
841.3Sjtc	} else {
851.5Smycroft		if (getdomainname(domainname, sizeof(domainname)))
861.5Smycroft			err(1, "getdomainname");
871.5Smycroft		(void)printf("%s\n", domainname);
881.1Sderaadt	}
891.1Sderaadt	exit(0);
901.9Scgd	/* NOTREACHED */
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.11Smycroft	/* NOTREACHED */
1001.3Sjtc}
101