domainname.c revision 1.12
11.12Sagc/* $NetBSD: domainname.c,v 1.12 2003/08/07 09:05:12 agc Exp $ */ 21.7Scgd 31.4Scgd/* 41.5Smycroft * Copyright (c) 1988, 1993 51.5Smycroft * The Regents of the University of California. All rights reserved. 61.4Scgd * 71.4Scgd * Redistribution and use in source and binary forms, with or without 81.4Scgd * modification, are permitted provided that the following conditions 91.4Scgd * are met: 101.4Scgd * 1. Redistributions of source code must retain the above copyright 111.4Scgd * notice, this list of conditions and the following disclaimer. 121.4Scgd * 2. Redistributions in binary form must reproduce the above copyright 131.4Scgd * notice, this list of conditions and the following disclaimer in the 141.4Scgd * documentation and/or other materials provided with the distribution. 151.12Sagc * 3. Neither the name of the University nor the names of its contributors 161.5Smycroft * may be used to endorse or promote products derived from this software 171.5Smycroft * without specific prior written permission. 181.4Scgd * 191.5Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201.5Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211.5Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221.5Smycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231.5Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291.4Scgd * SUCH DAMAGE. 301.4Scgd */ 311.4Scgd 321.8Sthorpej#include <sys/cdefs.h> 331.2Smycroft#ifndef lint 341.10Smycroft__COPYRIGHT("@(#) Copyright (c) 1988, 1993\n\ 351.8Sthorpej The Regents of the University of California. All rights reserved.\n"); 361.2Smycroft#endif /* not lint */ 371.2Smycroft 381.5Smycroft#ifndef lint 391.7Scgd#if 0 401.7Scgdstatic char sccsid[] = "@(#)hostname.c 8.1 (Berkeley) 5/31/93"; 411.7Scgd#else 421.12Sagc__RCSID("$NetBSD: domainname.c,v 1.12 2003/08/07 09:05:12 agc Exp $"); 431.7Scgd#endif 441.5Smycroft#endif /* not lint */ 451.5Smycroft 461.5Smycroft#include <sys/param.h> 471.5Smycroft 481.5Smycroft#include <err.h> 491.3Sjtc#include <stdio.h> 501.3Sjtc#include <stdlib.h> 511.3Sjtc#include <string.h> 521.3Sjtc#include <unistd.h> 531.3Sjtc 541.10Smycroftvoid usage __P((void)); 551.8Sthorpejint main __P((int, char *[])); 561.1Sderaadt 571.5Smycroftint 581.1Sderaadtmain(argc, argv) 591.3Sjtc int argc; 601.5Smycroft char *argv[]; 611.1Sderaadt{ 621.5Smycroft int ch; 631.5Smycroft char domainname[MAXHOSTNAMELEN]; 641.1Sderaadt 651.6Smycroft while ((ch = getopt(argc, argv, "")) != -1) 661.5Smycroft switch (ch) { 671.5Smycroft case '?': 681.5Smycroft default: 691.5Smycroft usage(); 701.5Smycroft } 711.5Smycroft argc -= optind; 721.5Smycroft argv += optind; 731.5Smycroft 741.5Smycroft if (argc > 1) 751.5Smycroft usage(); 761.3Sjtc 771.5Smycroft if (*argv) { 781.10Smycroft if (setdomainname(*argv, strlen(*argv))) 791.5Smycroft err(1, "setdomainname"); 801.3Sjtc } else { 811.5Smycroft if (getdomainname(domainname, sizeof(domainname))) 821.5Smycroft err(1, "getdomainname"); 831.5Smycroft (void)printf("%s\n", domainname); 841.1Sderaadt } 851.1Sderaadt exit(0); 861.9Scgd /* NOTREACHED */ 871.1Sderaadt} 881.1Sderaadt 891.5Smycroftvoid 901.5Smycroftusage() 911.3Sjtc{ 921.5Smycroft 931.6Smycroft (void)fprintf(stderr, "usage: domainname [name-of-domain]\n"); 941.3Sjtc exit(1); 951.11Smycroft /* NOTREACHED */ 961.3Sjtc} 97