11.15Sjoerg/* $NetBSD: domainname.c,v 1.15 2011/08/29 14:51:18 joerg 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.14Slukem__COPYRIGHT("@(#) Copyright (c) 1988, 1993\ 351.14Slukem The Regents of the University of California. All rights reserved."); 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.15Sjoerg__RCSID("$NetBSD: domainname.c,v 1.15 2011/08/29 14:51:18 joerg 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.15Sjoerg__dead static void usage(void); 551.1Sderaadt 561.5Smycroftint 571.13Skleinkmain(int argc, char *argv[]) 581.1Sderaadt{ 591.5Smycroft int ch; 601.5Smycroft char domainname[MAXHOSTNAMELEN]; 611.1Sderaadt 621.13Skleink setprogname(argv[0]); 631.13Skleink 641.13Skleink while ((ch = getopt(argc, argv, "")) != -1) { 651.5Smycroft switch (ch) { 661.5Smycroft case '?': 671.5Smycroft default: 681.5Smycroft usage(); 691.13Skleink /* NOTREACHED */ 701.5Smycroft } 711.13Skleink } 721.5Smycroft argc -= optind; 731.5Smycroft argv += optind; 741.5Smycroft 751.5Smycroft if (argc > 1) 761.5Smycroft usage(); 771.3Sjtc 781.5Smycroft if (*argv) { 791.10Smycroft if (setdomainname(*argv, strlen(*argv))) 801.5Smycroft err(1, "setdomainname"); 811.3Sjtc } else { 821.5Smycroft if (getdomainname(domainname, sizeof(domainname))) 831.5Smycroft err(1, "getdomainname"); 841.5Smycroft (void)printf("%s\n", domainname); 851.1Sderaadt } 861.13Skleink exit(EXIT_SUCCESS); 871.9Scgd /* NOTREACHED */ 881.1Sderaadt} 891.1Sderaadt 901.13Skleinkstatic void 911.13Skleinkusage(void) 921.3Sjtc{ 931.13Skleink (void)fprintf(stderr, "usage: %s [name-of-domain]\n", getprogname()); 941.13Skleink exit(EXIT_FAILURE); 951.3Sjtc} 96