domainname.c revision 1.7
11.7Scgd/* $NetBSD: domainname.c,v 1.7 1995/03/21 09:04:22 cgd 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.5Smycroft * 3. All advertising materials mentioning features or use of this software 161.5Smycroft * must display the following acknowledgement: 171.5Smycroft * This product includes software developed by the University of 181.5Smycroft * California, Berkeley and its contributors. 191.5Smycroft * 4. Neither the name of the University nor the names of its contributors 201.5Smycroft * may be used to endorse or promote products derived from this software 211.5Smycroft * without specific prior written permission. 221.4Scgd * 231.5Smycroft * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 241.5Smycroft * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 251.5Smycroft * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 261.5Smycroft * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 271.5Smycroft * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 281.4Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 291.4Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 301.4Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 311.4Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 321.4Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 331.4Scgd * SUCH DAMAGE. 341.4Scgd */ 351.4Scgd 361.2Smycroft#ifndef lint 371.5Smycroftstatic char copyright[] = 381.5Smycroft"@(#) Copyright (c) 1988, 1993\n\ 391.5Smycroft The Regents of the University of California. All rights reserved.\n"; 401.2Smycroft#endif /* not lint */ 411.2Smycroft 421.5Smycroft#ifndef lint 431.7Scgd#if 0 441.7Scgdstatic char sccsid[] = "@(#)hostname.c 8.1 (Berkeley) 5/31/93"; 451.7Scgd#else 461.7Scgdstatic char rcsid[] = "$NetBSD: domainname.c,v 1.7 1995/03/21 09:04:22 cgd Exp $"; 471.7Scgd#endif 481.5Smycroft#endif /* not lint */ 491.5Smycroft 501.5Smycroft#include <sys/param.h> 511.5Smycroft 521.5Smycroft#include <err.h> 531.3Sjtc#include <stdio.h> 541.3Sjtc#include <stdlib.h> 551.3Sjtc#include <string.h> 561.3Sjtc#include <unistd.h> 571.3Sjtc 581.5Smycroftvoid usage __P((void)); 591.1Sderaadt 601.5Smycroftint 611.1Sderaadtmain(argc, argv) 621.3Sjtc int argc; 631.5Smycroft char *argv[]; 641.1Sderaadt{ 651.5Smycroft int ch; 661.5Smycroft char domainname[MAXHOSTNAMELEN]; 671.1Sderaadt 681.6Smycroft while ((ch = getopt(argc, argv, "")) != -1) 691.5Smycroft switch (ch) { 701.5Smycroft case '?': 711.5Smycroft default: 721.5Smycroft usage(); 731.5Smycroft } 741.5Smycroft argc -= optind; 751.5Smycroft argv += optind; 761.5Smycroft 771.5Smycroft if (argc > 1) 781.5Smycroft usage(); 791.3Sjtc 801.5Smycroft if (*argv) { 811.5Smycroft if (setdomainname(*argv, strlen(*argv))) 821.5Smycroft err(1, "setdomainname"); 831.3Sjtc } else { 841.5Smycroft if (getdomainname(domainname, sizeof(domainname))) 851.5Smycroft err(1, "getdomainname"); 861.5Smycroft (void)printf("%s\n", domainname); 871.1Sderaadt } 881.1Sderaadt exit(0); 891.1Sderaadt} 901.1Sderaadt 911.5Smycroftvoid 921.5Smycroftusage() 931.3Sjtc{ 941.5Smycroft 951.6Smycroft (void)fprintf(stderr, "usage: domainname [name-of-domain]\n"); 961.3Sjtc exit(1); 971.3Sjtc} 98