domainname.c revision 1.13
11.13Skleink/*	$NetBSD: domainname.c,v 1.13 2004/04/19 08:24:56 kleink 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.12Sagc * 3. Neither the name of the University nor the names of its contributors
161.5Smycroft *    may be used to endorse or promote products derived from this software
171.5Smycroft *    without specific prior written permission.
181.4Scgd *
191.5Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201.5Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211.5Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221.5Smycroft * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231.5Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291.4Scgd * SUCH DAMAGE.
301.4Scgd */
311.4Scgd
321.8Sthorpej#include <sys/cdefs.h>
331.2Smycroft#ifndef lint
341.10Smycroft__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\
351.8Sthorpej	The Regents of the University of California.  All rights reserved.\n");
361.2Smycroft#endif /* not lint */
371.2Smycroft
381.5Smycroft#ifndef lint
391.7Scgd#if 0
401.7Scgdstatic char sccsid[] = "@(#)hostname.c	8.1 (Berkeley) 5/31/93";
411.7Scgd#else
421.13Skleink__RCSID("$NetBSD: domainname.c,v 1.13 2004/04/19 08:24:56 kleink Exp $");
431.7Scgd#endif
441.5Smycroft#endif /* not lint */
451.5Smycroft
461.5Smycroft#include <sys/param.h>
471.5Smycroft
481.5Smycroft#include <err.h>
491.3Sjtc#include <stdio.h>
501.3Sjtc#include <stdlib.h>
511.3Sjtc#include <string.h>
521.3Sjtc#include <unistd.h>
531.3Sjtc
541.13Skleinkstatic void usage(void);
551.13Skleinkint main(int, char *[]);
561.1Sderaadt
571.5Smycroftint
581.13Skleinkmain(int argc, char *argv[])
591.1Sderaadt{
601.5Smycroft	int ch;
611.5Smycroft	char domainname[MAXHOSTNAMELEN];
621.1Sderaadt
631.13Skleink	setprogname(argv[0]);
641.13Skleink
651.13Skleink	while ((ch = getopt(argc, argv, "")) != -1) {
661.5Smycroft		switch (ch) {
671.5Smycroft		case '?':
681.5Smycroft		default:
691.5Smycroft			usage();
701.13Skleink			/* NOTREACHED */
711.5Smycroft		}
721.13Skleink	}
731.5Smycroft	argc -= optind;
741.5Smycroft	argv += optind;
751.5Smycroft
761.5Smycroft	if (argc > 1)
771.5Smycroft		usage();
781.3Sjtc
791.5Smycroft	if (*argv) {
801.10Smycroft		if (setdomainname(*argv, strlen(*argv)))
811.5Smycroft			err(1, "setdomainname");
821.3Sjtc	} else {
831.5Smycroft		if (getdomainname(domainname, sizeof(domainname)))
841.5Smycroft			err(1, "getdomainname");
851.5Smycroft		(void)printf("%s\n", domainname);
861.1Sderaadt	}
871.13Skleink	exit(EXIT_SUCCESS);
881.9Scgd	/* NOTREACHED */
891.1Sderaadt}
901.1Sderaadt
911.13Skleinkstatic void
921.13Skleinkusage(void)
931.3Sjtc{
941.13Skleink	(void)fprintf(stderr, "usage: %s [name-of-domain]\n", getprogname());
951.13Skleink	exit(EXIT_FAILURE);
961.3Sjtc}
97