1 /* 2 * Copyright (c) 1992/3 Theo de Raadt <deraadt@fsa.ca> 3 * Copyright (c) 1992/3 John Brezak 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote 15 * products derived from this software without specific prior written 16 * permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 #ifndef lint 32 static char rcsid[] = "yppoll.c,v 1.2 1993/08/02 17:57:20 mycroft Exp"; 33 #endif /* not lint */ 34 35 #include <sys/param.h> 36 #include <sys/types.h> 37 #include <sys/socket.h> 38 #include <stdio.h> 39 #include <time.h> 40 41 #include <rpc/rpc.h> 42 #include <rpc/xdr.h> 43 #include <rpcsvc/yp_prot.h> 44 #include <rpcsvc/ypclnt.h> 45 46 usage() 47 { 48 fprintf(stderr, "Usage:\n"); 49 fprintf(stderr, "\typpoll [-h host] [-d domainname] mapname\n"); 50 exit(1); 51 } 52 53 int 54 main(argc, argv) 55 char **argv; 56 { 57 char *domainname; 58 char *hostname = "localhost"; 59 char *inmap, *master; 60 int order; 61 extern char *optarg; 62 extern int optind; 63 int c, r; 64 65 yp_get_default_domain(&domainname); 66 67 while( (c=getopt(argc, argv, "h:d:?")) != -1) 68 switch(c) { 69 case 'd': 70 domainname = optarg; 71 break; 72 case 'h': 73 hostname = optarg; 74 break; 75 case '?': 76 usage(); 77 /*NOTREACHED*/ 78 } 79 80 if(optind + 1 != argc ) 81 usage(); 82 83 inmap = argv[optind]; 84 85 r = yp_order(domainname, inmap, &order); 86 if (r != 0) { 87 fprintf(stderr, "No such map %s. Reason: %s\n", 88 inmap, yperr_string(r)); 89 exit(1); 90 } 91 printf("Map %s has order number %d. %s", inmap, order, ctime((time_t *)&order)); 92 r = yp_master(domainname, inmap, &master); 93 if (r != 0) { 94 fprintf(stderr, "No such map %s. Reason: %s\n", 95 inmap, yperr_string(r)); 96 exit(1); 97 } 98 printf("The master server is %s.\n", master); 99 100 exit(0); 101 } 102