domainname.c revision 1.4
1/* 2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote 14 * products derived from this software without specific prior written 15 * permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#ifndef lint 31static char rcsid[] = "$Id: domainname.c,v 1.4 1994/02/23 02:48:29 cgd Exp $"; 32#endif /* not lint */ 33 34#include <stdio.h> 35#include <stdlib.h> 36#include <string.h> 37#include <unistd.h> 38#include <sys/param.h> 39 40static void usage __P((void)); 41 42main(argc, argv) 43 int argc; 44 char **argv; 45{ 46 char dom[MAXHOSTNAMELEN]; 47 48 if( argc>2 ) { 49 usage (); 50 /* NOTREACHED */ 51 } 52 53 if( argc==2 ) { 54 if( setdomainname(argv[1], strlen(argv[1])+1) == -1) { 55 perror("setdomainname"); 56 exit(1); 57 } 58 } else { 59 if( getdomainname(dom, sizeof(dom)) == -1) { 60 perror("getdomainname"); 61 exit(1); 62 } 63 printf("%s\n", dom); 64 } 65 66 exit(0); 67} 68 69static void 70usage () 71{ 72 (void)fprintf(stderr, "usage: domainname [name-of-domain]\n"); 73 exit(1); 74} 75