domainname.c revision 3107
191094Sdes/* 2115619Sdes * Copyright (c) 1988, 1993 3228690Sdes * The Regents of the University of California. All rights reserved. 491094Sdes * 591094Sdes * Redistribution and use in source and binary forms, with or without 691094Sdes * modification, are permitted provided that the following conditions 799158Sdes * are met: 899158Sdes * 1. Redistributions of source code must retain the above copyright 999158Sdes * notice, this list of conditions and the following disclaimer. 1091094Sdes * 2. Redistributions in binary form must reproduce the above copyright 1191094Sdes * notice, this list of conditions and the following disclaimer in the 1291094Sdes * documentation and/or other materials provided with the distribution. 1391094Sdes * 3. All advertising materials mentioning features or use of this software 1491094Sdes * must display the following acknowledgement: 1591094Sdes * This product includes software developed by the University of 1691094Sdes * California, Berkeley and its contributors. 1791094Sdes * 4. Neither the name of the University nor the names of its contributors 1891094Sdes * may be used to endorse or promote products derived from this software 1991094Sdes * without specific prior written permission. 2091094Sdes * 2191094Sdes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2291094Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2391094Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2491094Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2591094Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2691094Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2791094Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2891094Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2991094Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3091094Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3191094Sdes * SUCH DAMAGE. 3291094Sdes */ 3391094Sdes 3491094Sdes#ifndef lint 35348980Sdesstatic char copyright[] = 3691094Sdes"@(#) Copyright (c) 1988, 1993\n\ 3791094Sdes The Regents of the University of California. All rights reserved.\n"; 38228690Sdes#endif /* not lint */ 39228690Sdes 40228690Sdes#ifndef lint 41228690Sdes/*static char sccsid[] = "From: @(#)hostname.c 8.1 (Berkeley) 5/31/93"; */ 42236099Sdesstatic const char rcsid[] = 4391094Sdes "$Id: domainname.c,v 1.3 1994/09/21 22:30:55 bde Exp $"; 4491094Sdes#endif /* not lint */ 4591094Sdes 4691094Sdes#include <sys/param.h> 4791094Sdes 4891094Sdes#include <err.h> 4991094Sdes#include <stdio.h> 5091094Sdes#include <stdlib.h> 51255376Sdes#include <string.h> 5291094Sdes#include <unistd.h> 53228690Sdes 54114536Sdesint 55115619Sdesmain(argc,argv) 5691094Sdes int argc; 5791094Sdes char *argv[]; 5891100Sdes{ 5991100Sdes char *p, domainname[MAXHOSTNAMELEN]; 60115619Sdes 6191094Sdes argc--, argv++; 6291094Sdes 6391094Sdes if (*argv) { 64115619Sdes if (setdomainname(*argv, strlen(*argv))) 6591094Sdes err(1, "setdomainname"); 6691094Sdes } else { 67115619Sdes if (getdomainname(domainname, sizeof(domainname))) 68255376Sdes err(1, "getdomainname"); 6991094Sdes (void)printf("%s\n", domainname); 7091094Sdes } 71236099Sdes exit(0); 7291094Sdes} 73228690Sdes