1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate * 22*7c478bd9Sstevel@tonic-gate * Copyright 1995 Sun Microsystems, Inc. All rights reserved. 23*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*7c478bd9Sstevel@tonic-gate */ 25*7c478bd9Sstevel@tonic-gate 26*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 27*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 31*7c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 32*7c478bd9Sstevel@tonic-gate * California. 33*7c478bd9Sstevel@tonic-gate */ 34*7c478bd9Sstevel@tonic-gate 35*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate /* 38*7c478bd9Sstevel@tonic-gate * This is a user command which asks a particular ypserv which version of a 39*7c478bd9Sstevel@tonic-gate * map it is using. Usage is: 40*7c478bd9Sstevel@tonic-gate * 41*7c478bd9Sstevel@tonic-gate * yppoll [-h <host>] [-d <domainname>] mapname 42*7c478bd9Sstevel@tonic-gate * 43*7c478bd9Sstevel@tonic-gate * If the host is ommitted, the local host will be used. If host is specified 44*7c478bd9Sstevel@tonic-gate * as an internet address, no yp services need to be locally available. 45*7c478bd9Sstevel@tonic-gate * 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate #include <stdio.h> 48*7c478bd9Sstevel@tonic-gate #include <ctype.h> 49*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 50*7c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 51*7c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 52*7c478bd9Sstevel@tonic-gate #include <netdir.h> 53*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 54*7c478bd9Sstevel@tonic-gate #include "yp_b.h" 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate #ifdef NULL 57*7c478bd9Sstevel@tonic-gate #undef NULL 58*7c478bd9Sstevel@tonic-gate #endif 59*7c478bd9Sstevel@tonic-gate #define NULL 0 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate #define TIMEOUT 30 /* Total seconds for timeout */ 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate static int status = 0; /* exit status */ 64*7c478bd9Sstevel@tonic-gate static char *domain = NULL; 65*7c478bd9Sstevel@tonic-gate static char default_domain_name[YPMAXDOMAIN]; 66*7c478bd9Sstevel@tonic-gate static char *map = NULL; 67*7c478bd9Sstevel@tonic-gate static char *host = NULL; 68*7c478bd9Sstevel@tonic-gate static char default_host_name[256]; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate static char err_usage[] = 71*7c478bd9Sstevel@tonic-gate "Usage:\n\ 72*7c478bd9Sstevel@tonic-gate yppoll [ -h host ] [ -d domainname ] mapname\n\n"; 73*7c478bd9Sstevel@tonic-gate static char err_bad_args[] = 74*7c478bd9Sstevel@tonic-gate "Bad %s argument.\n"; 75*7c478bd9Sstevel@tonic-gate static char err_cant_get_kname[] = 76*7c478bd9Sstevel@tonic-gate "Can't get %s back from system call.\n"; 77*7c478bd9Sstevel@tonic-gate static char err_null_kname[] = 78*7c478bd9Sstevel@tonic-gate "%s hasn't been set on this machine.\n"; 79*7c478bd9Sstevel@tonic-gate static char err_bad_hostname[] = "hostname"; 80*7c478bd9Sstevel@tonic-gate static char err_bad_mapname[] = "mapname"; 81*7c478bd9Sstevel@tonic-gate static char err_bad_domainname[] = "domainname"; 82*7c478bd9Sstevel@tonic-gate static char err_bad_resp[] = 83*7c478bd9Sstevel@tonic-gate "Ill-formed response returned from ypserv on host %s.\n"; 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate static void get_command_line_args(); 86*7c478bd9Sstevel@tonic-gate static void getdomain(); 87*7c478bd9Sstevel@tonic-gate static void getlochost(); 88*7c478bd9Sstevel@tonic-gate static void getmapparms(); 89*7c478bd9Sstevel@tonic-gate static void newresults(); 90*7c478bd9Sstevel@tonic-gate static void getypserv(); 91*7c478bd9Sstevel@tonic-gate 92*7c478bd9Sstevel@tonic-gate extern void exit(); 93*7c478bd9Sstevel@tonic-gate extern int getdomainname(); 94*7c478bd9Sstevel@tonic-gate extern int gethostname(); 95*7c478bd9Sstevel@tonic-gate extern unsigned int strlen(); 96*7c478bd9Sstevel@tonic-gate extern int strcmp(); 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * This is the mainline for the yppoll process. 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate void 103*7c478bd9Sstevel@tonic-gate main(argc, argv) 104*7c478bd9Sstevel@tonic-gate int argc; 105*7c478bd9Sstevel@tonic-gate char **argv; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate { 108*7c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate if (!domain) { 111*7c478bd9Sstevel@tonic-gate getdomain(); 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate if (!host) { 115*7c478bd9Sstevel@tonic-gate getypserv(); 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate getmapparms(); 119*7c478bd9Sstevel@tonic-gate exit(status); 120*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate /* 124*7c478bd9Sstevel@tonic-gate * This does the command line argument processing. 125*7c478bd9Sstevel@tonic-gate */ 126*7c478bd9Sstevel@tonic-gate static void 127*7c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv) 128*7c478bd9Sstevel@tonic-gate int argc; 129*7c478bd9Sstevel@tonic-gate char **argv; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate { 132*7c478bd9Sstevel@tonic-gate argv++; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate while (--argc) { 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate if ((*argv)[0] == '-') { 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate switch ((*argv)[1]) { 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate case 'h': 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate if (argc > 1) { 143*7c478bd9Sstevel@tonic-gate argv++; 144*7c478bd9Sstevel@tonic-gate argc--; 145*7c478bd9Sstevel@tonic-gate host = *argv; 146*7c478bd9Sstevel@tonic-gate argv++; 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate if ((int)strlen(host) > 256) { 149*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 150*7c478bd9Sstevel@tonic-gate err_bad_args, 151*7c478bd9Sstevel@tonic-gate err_bad_hostname); 152*7c478bd9Sstevel@tonic-gate exit(1); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate } else { 156*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 157*7c478bd9Sstevel@tonic-gate exit(1); 158*7c478bd9Sstevel@tonic-gate } 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate break; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate case 'd': 163*7c478bd9Sstevel@tonic-gate 164*7c478bd9Sstevel@tonic-gate if (argc > 1) { 165*7c478bd9Sstevel@tonic-gate argv++; 166*7c478bd9Sstevel@tonic-gate argc--; 167*7c478bd9Sstevel@tonic-gate domain = *argv; 168*7c478bd9Sstevel@tonic-gate argv++; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate if ((int)strlen(domain) > YPMAXDOMAIN) { 171*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 172*7c478bd9Sstevel@tonic-gate err_bad_args, 173*7c478bd9Sstevel@tonic-gate err_bad_domainname); 174*7c478bd9Sstevel@tonic-gate exit(1); 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate } else { 178*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 179*7c478bd9Sstevel@tonic-gate exit(1); 180*7c478bd9Sstevel@tonic-gate } 181*7c478bd9Sstevel@tonic-gate 182*7c478bd9Sstevel@tonic-gate break; 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate default: 185*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 186*7c478bd9Sstevel@tonic-gate exit(1); 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate 190*7c478bd9Sstevel@tonic-gate } else { 191*7c478bd9Sstevel@tonic-gate if (!map) { 192*7c478bd9Sstevel@tonic-gate map = *argv; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate if ((int)strlen(map) > YPMAXMAP) { 195*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_bad_args, 196*7c478bd9Sstevel@tonic-gate err_bad_mapname); 197*7c478bd9Sstevel@tonic-gate exit(1); 198*7c478bd9Sstevel@tonic-gate } 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate } else { 201*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 202*7c478bd9Sstevel@tonic-gate exit(1); 203*7c478bd9Sstevel@tonic-gate } 204*7c478bd9Sstevel@tonic-gate } 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if (!map) { 208*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 209*7c478bd9Sstevel@tonic-gate exit(1); 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate /* 214*7c478bd9Sstevel@tonic-gate * This gets the local default domainname, and makes sure that it's set 215*7c478bd9Sstevel@tonic-gate * to something reasonable. domain is set here. 216*7c478bd9Sstevel@tonic-gate */ 217*7c478bd9Sstevel@tonic-gate static void 218*7c478bd9Sstevel@tonic-gate getdomain() 219*7c478bd9Sstevel@tonic-gate { 220*7c478bd9Sstevel@tonic-gate if (!getdomainname(default_domain_name, YPMAXDOMAIN)) { 221*7c478bd9Sstevel@tonic-gate domain = default_domain_name; 222*7c478bd9Sstevel@tonic-gate } else { 223*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_cant_get_kname, err_bad_domainname); 224*7c478bd9Sstevel@tonic-gate exit(1); 225*7c478bd9Sstevel@tonic-gate } 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate if ((int)strlen(domain) == 0) { 228*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_null_kname, err_bad_domainname); 229*7c478bd9Sstevel@tonic-gate exit(1); 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate } 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate /* 234*7c478bd9Sstevel@tonic-gate * This gets the local hostname back from the kernel 235*7c478bd9Sstevel@tonic-gate */ 236*7c478bd9Sstevel@tonic-gate static void 237*7c478bd9Sstevel@tonic-gate getlochost() 238*7c478bd9Sstevel@tonic-gate { 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate if (! gethostname(default_host_name, 256)) { 241*7c478bd9Sstevel@tonic-gate host = default_host_name; 242*7c478bd9Sstevel@tonic-gate } else { 243*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_cant_get_kname, err_bad_hostname); 244*7c478bd9Sstevel@tonic-gate exit(1); 245*7c478bd9Sstevel@tonic-gate } 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate 248*7c478bd9Sstevel@tonic-gate static void 249*7c478bd9Sstevel@tonic-gate getmapparms() 250*7c478bd9Sstevel@tonic-gate { 251*7c478bd9Sstevel@tonic-gate CLIENT * map_clnt; 252*7c478bd9Sstevel@tonic-gate struct ypresp_order oresp; 253*7c478bd9Sstevel@tonic-gate struct ypreq_nokey req; 254*7c478bd9Sstevel@tonic-gate struct ypresp_master mresp; 255*7c478bd9Sstevel@tonic-gate struct ypresp_master *mresults = (struct ypresp_master *) NULL; 256*7c478bd9Sstevel@tonic-gate struct ypresp_order *oresults = (struct ypresp_order *) NULL; 257*7c478bd9Sstevel@tonic-gate 258*7c478bd9Sstevel@tonic-gate struct timeval timeout; 259*7c478bd9Sstevel@tonic-gate enum clnt_stat s; 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate if ((map_clnt = clnt_create(host, YPPROG, YPVERS, 262*7c478bd9Sstevel@tonic-gate "netpath")) == NULL) { 263*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 264*7c478bd9Sstevel@tonic-gate "Can't create connection to %s.\n", host); 265*7c478bd9Sstevel@tonic-gate clnt_pcreateerror("Reason"); 266*7c478bd9Sstevel@tonic-gate exit(1); 267*7c478bd9Sstevel@tonic-gate } 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate timeout.tv_sec = TIMEOUT; 270*7c478bd9Sstevel@tonic-gate timeout.tv_usec = 0; 271*7c478bd9Sstevel@tonic-gate req.domain = domain; 272*7c478bd9Sstevel@tonic-gate req.map = map; 273*7c478bd9Sstevel@tonic-gate mresp.master = NULL; 274*7c478bd9Sstevel@tonic-gate 275*7c478bd9Sstevel@tonic-gate if (clnt_call(map_clnt, YPPROC_MASTER, (xdrproc_t)xdr_ypreq_nokey, 276*7c478bd9Sstevel@tonic-gate (caddr_t) &req, (xdrproc_t)xdr_ypresp_master, 277*7c478bd9Sstevel@tonic-gate (caddr_t) &mresp, timeout) == RPC_SUCCESS) { 278*7c478bd9Sstevel@tonic-gate mresults = &mresp; 279*7c478bd9Sstevel@tonic-gate s = (enum clnt_stat) clnt_call(map_clnt, YPPROC_ORDER, 280*7c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_nokey, (char *)&req, 281*7c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_order, (char *)&oresp, timeout); 282*7c478bd9Sstevel@tonic-gate 283*7c478bd9Sstevel@tonic-gate if (s == RPC_SUCCESS) { 284*7c478bd9Sstevel@tonic-gate oresults = &oresp; 285*7c478bd9Sstevel@tonic-gate newresults(mresults, oresults); 286*7c478bd9Sstevel@tonic-gate } else { 287*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 288*7c478bd9Sstevel@tonic-gate "Can't make YPPROC_ORDER call to ypserv at %s.\n ", 289*7c478bd9Sstevel@tonic-gate host); 290*7c478bd9Sstevel@tonic-gate clnt_perror(map_clnt, "Reason"); 291*7c478bd9Sstevel@tonic-gate exit(1); 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate } else { 295*7c478bd9Sstevel@tonic-gate clnt_destroy(map_clnt); 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate } 298*7c478bd9Sstevel@tonic-gate 299*7c478bd9Sstevel@tonic-gate static void 300*7c478bd9Sstevel@tonic-gate newresults(m, o) 301*7c478bd9Sstevel@tonic-gate struct ypresp_master *m; 302*7c478bd9Sstevel@tonic-gate struct ypresp_order *o; 303*7c478bd9Sstevel@tonic-gate { 304*7c478bd9Sstevel@tonic-gate char *s_domok = "Domain %s is supported.\n"; 305*7c478bd9Sstevel@tonic-gate char *s_ook = "Map %s has order number %d.\n"; 306*7c478bd9Sstevel@tonic-gate char *s_mok = "The master server is %s.\n"; 307*7c478bd9Sstevel@tonic-gate char *s_mbad = "Can't get master for map %s.\n Reason: %s\n"; 308*7c478bd9Sstevel@tonic-gate char *s_obad = "Can't get order number for map %s.\n Reason: %s\n"; 309*7c478bd9Sstevel@tonic-gate 310*7c478bd9Sstevel@tonic-gate if (m->status == YP_TRUE && o->status == YP_TRUE) { 311*7c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 312*7c478bd9Sstevel@tonic-gate (void) printf(s_ook, map, o->ordernum); 313*7c478bd9Sstevel@tonic-gate (void) printf(s_mok, m->master); 314*7c478bd9Sstevel@tonic-gate } else if (o->status == YP_TRUE) { 315*7c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 316*7c478bd9Sstevel@tonic-gate (void) printf(s_ook, map, o->ordernum); 317*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_mbad, map, 318*7c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(m->status))); 319*7c478bd9Sstevel@tonic-gate status = 1; 320*7c478bd9Sstevel@tonic-gate } else if (m->status == YP_TRUE) { 321*7c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 322*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_obad, map, 323*7c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(o->status))); 324*7c478bd9Sstevel@tonic-gate (void) printf(s_mok, m->master); 325*7c478bd9Sstevel@tonic-gate status = 1; 326*7c478bd9Sstevel@tonic-gate } else { 327*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 328*7c478bd9Sstevel@tonic-gate "Can't get any map parameter information.\n"); 329*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_obad, map, 330*7c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(o->status))); 331*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_mbad, map, 332*7c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(m->status))); 333*7c478bd9Sstevel@tonic-gate status = 1; 334*7c478bd9Sstevel@tonic-gate } 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate static void 338*7c478bd9Sstevel@tonic-gate getypserv() 339*7c478bd9Sstevel@tonic-gate { 340*7c478bd9Sstevel@tonic-gate struct ypbind_resp response; 341*7c478bd9Sstevel@tonic-gate struct ypbind_domain ypdomain; 342*7c478bd9Sstevel@tonic-gate struct ypbind_binding *binding; 343*7c478bd9Sstevel@tonic-gate static char hostbuf[256]; 344*7c478bd9Sstevel@tonic-gate 345*7c478bd9Sstevel@tonic-gate getlochost(); 346*7c478bd9Sstevel@tonic-gate 347*7c478bd9Sstevel@tonic-gate (void) memset((char *)&response, 0, sizeof (response)); 348*7c478bd9Sstevel@tonic-gate ypdomain.ypbind_domainname = domain; 349*7c478bd9Sstevel@tonic-gate ypdomain.ypbind_vers = YPBINDVERS; 350*7c478bd9Sstevel@tonic-gate (void) rpc_call(host, YPBINDPROG, YPBINDVERS, YPBINDPROC_DOMAIN, 351*7c478bd9Sstevel@tonic-gate xdr_ypbind_domain, (char *)&ypdomain, xdr_ypbind_resp, 352*7c478bd9Sstevel@tonic-gate (char *)&response, "netpath"); 353*7c478bd9Sstevel@tonic-gate if (response.ypbind_status != YPBIND_SUCC_VAL) { 354*7c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "couldn't get yp server - status %u\n", 355*7c478bd9Sstevel@tonic-gate response.ypbind_status); 356*7c478bd9Sstevel@tonic-gate exit(1); 357*7c478bd9Sstevel@tonic-gate } 358*7c478bd9Sstevel@tonic-gate binding = response.ypbind_resp_u.ypbind_bindinfo; 359*7c478bd9Sstevel@tonic-gate host = binding->ypbind_servername; 360*7c478bd9Sstevel@tonic-gate 361*7c478bd9Sstevel@tonic-gate /* 362*7c478bd9Sstevel@tonic-gate * When ypbind is running in broadcast mode, it sets the 363*7c478bd9Sstevel@tonic-gate * servername to "". To get the real name of the server, 364*7c478bd9Sstevel@tonic-gate * we need to do a host lookup on the svcaddr. This code 365*7c478bd9Sstevel@tonic-gate * is similar to code in ypwhich. 366*7c478bd9Sstevel@tonic-gate */ 367*7c478bd9Sstevel@tonic-gate if (strcmp(host, "") == 0) { 368*7c478bd9Sstevel@tonic-gate struct nd_hostservlist *nhs; 369*7c478bd9Sstevel@tonic-gate struct netconfig *nconf = binding->ypbind_nconf; 370*7c478bd9Sstevel@tonic-gate struct netbuf *svcaddr = binding->ypbind_svcaddr; 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate if (netdir_getbyaddr(nconf, &nhs, svcaddr) != ND_OK) { 373*7c478bd9Sstevel@tonic-gate struct sockaddr_in *sa; 374*7c478bd9Sstevel@tonic-gate 375*7c478bd9Sstevel@tonic-gate sa = (struct sockaddr_in *)svcaddr->buf; 376*7c478bd9Sstevel@tonic-gate 377*7c478bd9Sstevel@tonic-gate strcpy(hostbuf, inet_ntoa(sa->sin_addr)); 378*7c478bd9Sstevel@tonic-gate } else { 379*7c478bd9Sstevel@tonic-gate sprintf(hostbuf, "%s", nhs->h_hostservs->h_host); 380*7c478bd9Sstevel@tonic-gate } 381*7c478bd9Sstevel@tonic-gate host = hostbuf; 382*7c478bd9Sstevel@tonic-gate netdir_free((char *)nhs, ND_HOSTSERVLIST); 383*7c478bd9Sstevel@tonic-gate } 384*7c478bd9Sstevel@tonic-gate } 385