domainname.c revision 1.6
11.4Scgd/*
21.5Smycroft * Copyright (c) 1988, 1993
31.5Smycroft *	The Regents of the University of California.  All rights reserved.
41.4Scgd *
51.4Scgd * Redistribution and use in source and binary forms, with or without
61.4Scgd * modification, are permitted provided that the following conditions
71.4Scgd * are met:
81.4Scgd * 1. Redistributions of source code must retain the above copyright
91.4Scgd *    notice, this list of conditions and the following disclaimer.
101.4Scgd * 2. Redistributions in binary form must reproduce the above copyright
111.4Scgd *    notice, this list of conditions and the following disclaimer in the
121.4Scgd *    documentation and/or other materials provided with the distribution.
131.5Smycroft * 3. All advertising materials mentioning features or use of this software
141.5Smycroft *    must display the following acknowledgement:
151.5Smycroft *	This product includes software developed by the University of
161.5Smycroft *	California, Berkeley and its contributors.
171.5Smycroft * 4. Neither the name of the University nor the names of its contributors
181.5Smycroft *    may be used to endorse or promote products derived from this software
191.5Smycroft *    without specific prior written permission.
201.4Scgd *
211.5Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221.5Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231.5Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241.5Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251.5Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311.4Scgd * SUCH DAMAGE.
321.4Scgd */
331.4Scgd
341.2Smycroft#ifndef lint
351.5Smycroftstatic char copyright[] =
361.5Smycroft"@(#) Copyright (c) 1988, 1993\n\
371.5Smycroft	The Regents of the University of California.  All rights reserved.\n";
381.2Smycroft#endif /* not lint */
391.2Smycroft
401.5Smycroft#ifndef lint
411.5Smycroft/*static char sccsid[] = "from: @(#)hostname.c	8.1 (Berkeley) 5/31/93";*/
421.6Smycroftstatic char *rcsid = "$Id: domainname.c,v 1.6 1994/09/26 06:53:21 mycroft Exp $";
431.5Smycroft#endif /* not lint */
441.5Smycroft
451.5Smycroft#include <sys/param.h>
461.5Smycroft
471.5Smycroft#include <err.h>
481.3Sjtc#include <stdio.h>
491.3Sjtc#include <stdlib.h>
501.3Sjtc#include <string.h>
511.3Sjtc#include <unistd.h>
521.3Sjtc
531.5Smycroftvoid usage __P((void));
541.1Sderaadt
551.5Smycroftint
561.1Sderaadtmain(argc, argv)
571.3Sjtc	int argc;
581.5Smycroft	char *argv[];
591.1Sderaadt{
601.5Smycroft	int ch;
611.5Smycroft	char domainname[MAXHOSTNAMELEN];
621.1Sderaadt
631.6Smycroft	while ((ch = getopt(argc, argv, "")) != -1)
641.5Smycroft		switch (ch) {
651.5Smycroft		case '?':
661.5Smycroft		default:
671.5Smycroft			usage();
681.5Smycroft		}
691.5Smycroft	argc -= optind;
701.5Smycroft	argv += optind;
711.5Smycroft
721.5Smycroft	if (argc > 1)
731.5Smycroft		usage();
741.3Sjtc
751.5Smycroft	if (*argv) {
761.5Smycroft		if (setdomainname(*argv, strlen(*argv)))
771.5Smycroft			err(1, "setdomainname");
781.3Sjtc	} else {
791.5Smycroft		if (getdomainname(domainname, sizeof(domainname)))
801.5Smycroft			err(1, "getdomainname");
811.5Smycroft		(void)printf("%s\n", domainname);
821.1Sderaadt	}
831.1Sderaadt	exit(0);
841.1Sderaadt}
851.1Sderaadt
861.5Smycroftvoid
871.5Smycroftusage()
881.3Sjtc{
891.5Smycroft
901.6Smycroft	(void)fprintf(stderr, "usage: domainname [name-of-domain]\n");
911.3Sjtc	exit(1);
921.3Sjtc}
93