domainname.c revision 26434
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. 3220420Ssteve * 3326434Scharnier * $Id: domainname.c,v 1.9 1997/06/03 06:19:04 charnier Exp $ 342862Swollman */ 352862Swollman 362862Swollman#ifndef lint 3720420Sstevestatic char const copyright[] = 382862Swollman"@(#) Copyright (c) 1988, 1993\n\ 392862Swollman The Regents of the University of California. All rights reserved.\n"; 402862Swollman#endif /* not lint */ 412862Swollman 422862Swollman#ifndef lint 4320420Sstevestatic char const sccsid[] = "From: @(#)hostname.c 8.1 (Berkeley) 5/31/93"; 442862Swollman#endif /* not lint */ 452862Swollman 462862Swollman#include <sys/param.h> 472862Swollman 482862Swollman#include <err.h> 492862Swollman#include <stdio.h> 502862Swollman#include <stdlib.h> 512862Swollman#include <string.h> 522862Swollman#include <unistd.h> 532862Swollman 5426402Scharniervoid usage __P((void)); 5526402Scharnier 562862Swollmanint 572862Swollmanmain(argc,argv) 582862Swollman int argc; 592862Swollman char *argv[]; 602862Swollman{ 6126402Scharnier int ch; 627165Sjoerg char domainname[MAXHOSTNAMELEN]; 632862Swollman 6426402Scharnier while ((ch = getopt(argc, argv, "")) != -1) 6526402Scharnier switch (ch) { 6626402Scharnier default: 6726402Scharnier usage(); 6826402Scharnier } 6926402Scharnier argc -= optind; 7026402Scharnier argv += optind; 712862Swollman 7226402Scharnier if (argc > 1) 7326402Scharnier usage(); 7426402Scharnier 752862Swollman if (*argv) { 762862Swollman if (setdomainname(*argv, strlen(*argv))) 772862Swollman err(1, "setdomainname"); 782862Swollman } else { 792862Swollman if (getdomainname(domainname, sizeof(domainname))) 802862Swollman err(1, "getdomainname"); 812862Swollman (void)printf("%s\n", domainname); 822862Swollman } 832862Swollman exit(0); 842862Swollman} 8526402Scharnier 8626402Scharniervoid 8726402Scharnierusage() 8826402Scharnier{ 8926434Scharnier (void)fprintf(stderr, "usage: domainname [ypdomain]\n"); 9026402Scharnier exit(1); 9126402Scharnier} 92