domainname.c revision 90108
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[] = 4550471Speter "$FreeBSD: head/bin/domainname/domainname.c 90108 2002-02-02 06:24:13Z imp $"; 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 5690108Simpstatic void usage(void); 5726402Scharnier 582862Swollmanint 5990108Simpmain(int argc, 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) { 7676874Skris if (setdomainname(*argv, (int)strlen(*argv))) 772862Swollman err(1, "setdomainname"); 782862Swollman } else { 7976874Skris if (getdomainname(domainname, (int)sizeof(domainname))) 802862Swollman err(1, "getdomainname"); 812862Swollman (void)printf("%s\n", domainname); 822862Swollman } 832862Swollman exit(0); 842862Swollman} 8526402Scharnier 8690108Simpstatic void 8790108Simpusage(void) 8826402Scharnier{ 8926434Scharnier (void)fprintf(stderr, "usage: domainname [ypdomain]\n"); 9026402Scharnier exit(1); 9126402Scharnier} 92