domainname.c revision 36009
12862Swollman/* 22862Swollman * Copyright (c) 1988, 1993 32862Swollman * The Regents of the University of California. All rights reserved. 42862Swollman * 52862Swollman * Redistribution and use in source and binary forms, with or without 62862Swollman * modification, are permitted provided that the following conditions 72862Swollman * are met: 82862Swollman * 1. Redistributions of source code must retain the above copyright 92862Swollman * notice, this list of conditions and the following disclaimer. 102862Swollman * 2. Redistributions in binary form must reproduce the above copyright 112862Swollman * notice, this list of conditions and the following disclaimer in the 122862Swollman * documentation and/or other materials provided with the distribution. 132862Swollman * 3. All advertising materials mentioning features or use of this software 142862Swollman * must display the following acknowledgement: 152862Swollman * This product includes software developed by the University of 162862Swollman * California, Berkeley and its contributors. 172862Swollman * 4. Neither the name of the University nor the names of its contributors 182862Swollman * may be used to endorse or promote products derived from this software 192862Swollman * without specific prior written permission. 202862Swollman * 212862Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 222862Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 232862Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 242862Swollman * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 252862Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 262862Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 272862Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 282862Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 292862Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 302862Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 312862Swollman * SUCH DAMAGE. 322862Swollman */ 332862Swollman 342862Swollman#ifndef lint 3520420Sstevestatic char const copyright[] = 362862Swollman"@(#) Copyright (c) 1988, 1993\n\ 372862Swollman The Regents of the University of California. All rights reserved.\n"; 382862Swollman#endif /* not lint */ 392862Swollman 402862Swollman#ifndef lint 4136009Scharnier#if 0 4220420Sstevestatic char const sccsid[] = "From: @(#)hostname.c 8.1 (Berkeley) 5/31/93"; 4336009Scharnier#endif 4436009Scharnierstatic const char rcsid[] = 4536009Scharnier "$Id$"; 462862Swollman#endif /* not lint */ 472862Swollman 482862Swollman#include <sys/param.h> 492862Swollman 502862Swollman#include <err.h> 512862Swollman#include <stdio.h> 522862Swollman#include <stdlib.h> 532862Swollman#include <string.h> 542862Swollman#include <unistd.h> 552862Swollman 5626402Scharniervoid usage __P((void)); 5726402Scharnier 582862Swollmanint 592862Swollmanmain(argc,argv) 602862Swollman int argc; 612862Swollman char *argv[]; 622862Swollman{ 6326402Scharnier int ch; 647165Sjoerg char domainname[MAXHOSTNAMELEN]; 652862Swollman 6626402Scharnier while ((ch = getopt(argc, argv, "")) != -1) 6726402Scharnier switch (ch) { 6826402Scharnier default: 6926402Scharnier usage(); 7026402Scharnier } 7126402Scharnier argc -= optind; 7226402Scharnier argv += optind; 732862Swollman 7426402Scharnier if (argc > 1) 7526402Scharnier usage(); 7626402Scharnier 772862Swollman if (*argv) { 782862Swollman if (setdomainname(*argv, strlen(*argv))) 792862Swollman err(1, "setdomainname"); 802862Swollman } else { 812862Swollman if (getdomainname(domainname, sizeof(domainname))) 822862Swollman err(1, "getdomainname"); 832862Swollman (void)printf("%s\n", domainname); 842862Swollman } 852862Swollman exit(0); 862862Swollman} 8726402Scharnier 8826402Scharniervoid 8926402Scharnierusage() 9026402Scharnier{ 9126434Scharnier (void)fprintf(stderr, "usage: domainname [ypdomain]\n"); 9226402Scharnier exit(1); 9326402Scharnier} 94