domainname.c revision 1.4
11.4Scgd/*
21.4Scgd * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca>
31.4Scgd * 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.4Scgd * 3. The name of the author may not be used to endorse or promote
141.4Scgd *    products derived from this software without specific prior written
151.4Scgd *    permission.
161.4Scgd *
171.4Scgd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
181.4Scgd * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
191.4Scgd * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201.4Scgd * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
211.4Scgd * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271.4Scgd * SUCH DAMAGE.
281.4Scgd */
291.4Scgd
301.2Smycroft#ifndef lint
311.4Scgdstatic char rcsid[] = "$Id: domainname.c,v 1.4 1994/02/23 02:48:29 cgd Exp $";
321.2Smycroft#endif /* not lint */
331.2Smycroft
341.3Sjtc#include <stdio.h>
351.3Sjtc#include <stdlib.h>
361.3Sjtc#include <string.h>
371.3Sjtc#include <unistd.h>
381.1Sderaadt#include <sys/param.h>
391.3Sjtc
401.3Sjtcstatic void usage __P((void));
411.1Sderaadt
421.1Sderaadtmain(argc, argv)
431.3Sjtc	int argc;
441.3Sjtc	char **argv;
451.1Sderaadt{
461.1Sderaadt	char dom[MAXHOSTNAMELEN];
471.1Sderaadt
481.1Sderaadt	if( argc>2 ) {
491.3Sjtc		usage ();
501.3Sjtc		/* NOTREACHED */
511.1Sderaadt	}
521.3Sjtc
531.1Sderaadt	if( argc==2 ) {
541.1Sderaadt		if( setdomainname(argv[1], strlen(argv[1])+1) == -1) {
551.1Sderaadt			perror("setdomainname");
561.1Sderaadt			exit(1);
571.1Sderaadt		}
581.3Sjtc	} else {
591.3Sjtc		if( getdomainname(dom, sizeof(dom)) == -1) {
601.3Sjtc			perror("getdomainname");
611.3Sjtc			exit(1);
621.3Sjtc		}
631.3Sjtc		printf("%s\n", dom);
641.1Sderaadt	}
651.3Sjtc
661.1Sderaadt	exit(0);
671.1Sderaadt}
681.1Sderaadt
691.3Sjtcstatic void
701.3Sjtcusage ()
711.3Sjtc{
721.3Sjtc	(void)fprintf(stderr, "usage: domainname [name-of-domain]\n");
731.3Sjtc	exit(1);
741.3Sjtc}
75