17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate * 22*a506a34cSth160488 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of 327c478bd9Sstevel@tonic-gate * California. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * This is a user command which asks a particular ypserv which version of a 397c478bd9Sstevel@tonic-gate * map it is using. Usage is: 407c478bd9Sstevel@tonic-gate * 417c478bd9Sstevel@tonic-gate * yppoll [-h <host>] [-d <domainname>] mapname 427c478bd9Sstevel@tonic-gate * 437c478bd9Sstevel@tonic-gate * If the host is ommitted, the local host will be used. If host is specified 447c478bd9Sstevel@tonic-gate * as an internet address, no yp services need to be locally available. 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate #include <stdio.h> 487c478bd9Sstevel@tonic-gate #include <ctype.h> 497c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 507c478bd9Sstevel@tonic-gate #include <rpcsvc/ypclnt.h> 517c478bd9Sstevel@tonic-gate #include <rpcsvc/yp_prot.h> 527c478bd9Sstevel@tonic-gate #include <netdir.h> 537c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 547c478bd9Sstevel@tonic-gate #include "yp_b.h" 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #ifdef NULL 577c478bd9Sstevel@tonic-gate #undef NULL 587c478bd9Sstevel@tonic-gate #endif 597c478bd9Sstevel@tonic-gate #define NULL 0 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate #define TIMEOUT 30 /* Total seconds for timeout */ 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate static int status = 0; /* exit status */ 647c478bd9Sstevel@tonic-gate static char *domain = NULL; 657c478bd9Sstevel@tonic-gate static char default_domain_name[YPMAXDOMAIN]; 667c478bd9Sstevel@tonic-gate static char *map = NULL; 677c478bd9Sstevel@tonic-gate static char *host = NULL; 687c478bd9Sstevel@tonic-gate static char default_host_name[256]; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate static char err_usage[] = 717c478bd9Sstevel@tonic-gate "Usage:\n\ 727c478bd9Sstevel@tonic-gate yppoll [ -h host ] [ -d domainname ] mapname\n\n"; 737c478bd9Sstevel@tonic-gate static char err_bad_args[] = 747c478bd9Sstevel@tonic-gate "Bad %s argument.\n"; 757c478bd9Sstevel@tonic-gate static char err_cant_get_kname[] = 767c478bd9Sstevel@tonic-gate "Can't get %s back from system call.\n"; 777c478bd9Sstevel@tonic-gate static char err_null_kname[] = 787c478bd9Sstevel@tonic-gate "%s hasn't been set on this machine.\n"; 797c478bd9Sstevel@tonic-gate static char err_bad_hostname[] = "hostname"; 807c478bd9Sstevel@tonic-gate static char err_bad_mapname[] = "mapname"; 817c478bd9Sstevel@tonic-gate static char err_bad_domainname[] = "domainname"; 827c478bd9Sstevel@tonic-gate static char err_bad_resp[] = 837c478bd9Sstevel@tonic-gate "Ill-formed response returned from ypserv on host %s.\n"; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate static void get_command_line_args(); 867c478bd9Sstevel@tonic-gate static void getdomain(); 877c478bd9Sstevel@tonic-gate static void getlochost(); 887c478bd9Sstevel@tonic-gate static void getmapparms(); 897c478bd9Sstevel@tonic-gate static void newresults(); 907c478bd9Sstevel@tonic-gate static void getypserv(); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate extern void exit(); 937c478bd9Sstevel@tonic-gate extern int getdomainname(); 947c478bd9Sstevel@tonic-gate extern int gethostname(); 957c478bd9Sstevel@tonic-gate extern unsigned int strlen(); 967c478bd9Sstevel@tonic-gate extern int strcmp(); 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * This is the mainline for the yppoll process. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 102*a506a34cSth160488 int 1037c478bd9Sstevel@tonic-gate main(argc, argv) 1047c478bd9Sstevel@tonic-gate int argc; 1057c478bd9Sstevel@tonic-gate char **argv; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate { 1087c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv); 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if (!domain) { 1117c478bd9Sstevel@tonic-gate getdomain(); 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate if (!host) { 1157c478bd9Sstevel@tonic-gate getypserv(); 1167c478bd9Sstevel@tonic-gate } 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate getmapparms(); 119*a506a34cSth160488 return (status); 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * This does the command line argument processing. 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate static void 1267c478bd9Sstevel@tonic-gate get_command_line_args(argc, argv) 1277c478bd9Sstevel@tonic-gate int argc; 1287c478bd9Sstevel@tonic-gate char **argv; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate { 1317c478bd9Sstevel@tonic-gate argv++; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate while (--argc) { 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate if ((*argv)[0] == '-') { 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate switch ((*argv)[1]) { 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate case 'h': 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate if (argc > 1) { 1427c478bd9Sstevel@tonic-gate argv++; 1437c478bd9Sstevel@tonic-gate argc--; 1447c478bd9Sstevel@tonic-gate host = *argv; 1457c478bd9Sstevel@tonic-gate argv++; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate if ((int)strlen(host) > 256) { 1487c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1497c478bd9Sstevel@tonic-gate err_bad_args, 1507c478bd9Sstevel@tonic-gate err_bad_hostname); 1517c478bd9Sstevel@tonic-gate exit(1); 1527c478bd9Sstevel@tonic-gate } 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate } else { 1557c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 1567c478bd9Sstevel@tonic-gate exit(1); 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate break; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate case 'd': 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if (argc > 1) { 1647c478bd9Sstevel@tonic-gate argv++; 1657c478bd9Sstevel@tonic-gate argc--; 1667c478bd9Sstevel@tonic-gate domain = *argv; 1677c478bd9Sstevel@tonic-gate argv++; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate if ((int)strlen(domain) > YPMAXDOMAIN) { 1707c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 1717c478bd9Sstevel@tonic-gate err_bad_args, 1727c478bd9Sstevel@tonic-gate err_bad_domainname); 1737c478bd9Sstevel@tonic-gate exit(1); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate } else { 1777c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 1787c478bd9Sstevel@tonic-gate exit(1); 1797c478bd9Sstevel@tonic-gate } 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate break; 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate default: 1847c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 1857c478bd9Sstevel@tonic-gate exit(1); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate } 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate } else { 1907c478bd9Sstevel@tonic-gate if (!map) { 1917c478bd9Sstevel@tonic-gate map = *argv; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if ((int)strlen(map) > YPMAXMAP) { 1947c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_bad_args, 1957c478bd9Sstevel@tonic-gate err_bad_mapname); 1967c478bd9Sstevel@tonic-gate exit(1); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate } else { 2007c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 2017c478bd9Sstevel@tonic-gate exit(1); 2027c478bd9Sstevel@tonic-gate } 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate if (!map) { 2077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_usage); 2087c478bd9Sstevel@tonic-gate exit(1); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* 2137c478bd9Sstevel@tonic-gate * This gets the local default domainname, and makes sure that it's set 2147c478bd9Sstevel@tonic-gate * to something reasonable. domain is set here. 2157c478bd9Sstevel@tonic-gate */ 2167c478bd9Sstevel@tonic-gate static void 2177c478bd9Sstevel@tonic-gate getdomain() 2187c478bd9Sstevel@tonic-gate { 2197c478bd9Sstevel@tonic-gate if (!getdomainname(default_domain_name, YPMAXDOMAIN)) { 2207c478bd9Sstevel@tonic-gate domain = default_domain_name; 2217c478bd9Sstevel@tonic-gate } else { 2227c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_cant_get_kname, err_bad_domainname); 2237c478bd9Sstevel@tonic-gate exit(1); 2247c478bd9Sstevel@tonic-gate } 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate if ((int)strlen(domain) == 0) { 2277c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_null_kname, err_bad_domainname); 2287c478bd9Sstevel@tonic-gate exit(1); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate } 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate /* 2337c478bd9Sstevel@tonic-gate * This gets the local hostname back from the kernel 2347c478bd9Sstevel@tonic-gate */ 2357c478bd9Sstevel@tonic-gate static void 2367c478bd9Sstevel@tonic-gate getlochost() 2377c478bd9Sstevel@tonic-gate { 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate if (! gethostname(default_host_name, 256)) { 2407c478bd9Sstevel@tonic-gate host = default_host_name; 2417c478bd9Sstevel@tonic-gate } else { 2427c478bd9Sstevel@tonic-gate (void) fprintf(stderr, err_cant_get_kname, err_bad_hostname); 2437c478bd9Sstevel@tonic-gate exit(1); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate } 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate static void 2487c478bd9Sstevel@tonic-gate getmapparms() 2497c478bd9Sstevel@tonic-gate { 2507c478bd9Sstevel@tonic-gate CLIENT * map_clnt; 2517c478bd9Sstevel@tonic-gate struct ypresp_order oresp; 2527c478bd9Sstevel@tonic-gate struct ypreq_nokey req; 2537c478bd9Sstevel@tonic-gate struct ypresp_master mresp; 2547c478bd9Sstevel@tonic-gate struct ypresp_master *mresults = (struct ypresp_master *)NULL; 2557c478bd9Sstevel@tonic-gate struct ypresp_order *oresults = (struct ypresp_order *)NULL; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate struct timeval timeout; 2587c478bd9Sstevel@tonic-gate enum clnt_stat s; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate if ((map_clnt = clnt_create(host, YPPROG, YPVERS, 2617c478bd9Sstevel@tonic-gate "netpath")) == NULL) { 2627c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2637c478bd9Sstevel@tonic-gate "Can't create connection to %s.\n", host); 2647c478bd9Sstevel@tonic-gate clnt_pcreateerror("Reason"); 2657c478bd9Sstevel@tonic-gate exit(1); 2667c478bd9Sstevel@tonic-gate } 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate timeout.tv_sec = TIMEOUT; 2697c478bd9Sstevel@tonic-gate timeout.tv_usec = 0; 2707c478bd9Sstevel@tonic-gate req.domain = domain; 2717c478bd9Sstevel@tonic-gate req.map = map; 2727c478bd9Sstevel@tonic-gate mresp.master = NULL; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if (clnt_call(map_clnt, YPPROC_MASTER, (xdrproc_t)xdr_ypreq_nokey, 2757c478bd9Sstevel@tonic-gate (caddr_t)&req, (xdrproc_t)xdr_ypresp_master, 2767c478bd9Sstevel@tonic-gate (caddr_t)&mresp, timeout) == RPC_SUCCESS) { 2777c478bd9Sstevel@tonic-gate mresults = &mresp; 2787c478bd9Sstevel@tonic-gate s = (enum clnt_stat) clnt_call(map_clnt, YPPROC_ORDER, 2797c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypreq_nokey, (char *)&req, 2807c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_ypresp_order, (char *)&oresp, timeout); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate if (s == RPC_SUCCESS) { 2837c478bd9Sstevel@tonic-gate oresults = &oresp; 2847c478bd9Sstevel@tonic-gate newresults(mresults, oresults); 2857c478bd9Sstevel@tonic-gate } else { 2867c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2877c478bd9Sstevel@tonic-gate "Can't make YPPROC_ORDER call to ypserv at %s.\n ", 2887c478bd9Sstevel@tonic-gate host); 2897c478bd9Sstevel@tonic-gate clnt_perror(map_clnt, "Reason"); 2907c478bd9Sstevel@tonic-gate exit(1); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate } else { 2947c478bd9Sstevel@tonic-gate clnt_destroy(map_clnt); 2957c478bd9Sstevel@tonic-gate } 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate static void 2997c478bd9Sstevel@tonic-gate newresults(m, o) 3007c478bd9Sstevel@tonic-gate struct ypresp_master *m; 3017c478bd9Sstevel@tonic-gate struct ypresp_order *o; 3027c478bd9Sstevel@tonic-gate { 3037c478bd9Sstevel@tonic-gate char *s_domok = "Domain %s is supported.\n"; 3047c478bd9Sstevel@tonic-gate char *s_ook = "Map %s has order number %d.\n"; 3057c478bd9Sstevel@tonic-gate char *s_mok = "The master server is %s.\n"; 3067c478bd9Sstevel@tonic-gate char *s_mbad = "Can't get master for map %s.\n Reason: %s\n"; 3077c478bd9Sstevel@tonic-gate char *s_obad = "Can't get order number for map %s.\n Reason: %s\n"; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if (m->status == YP_TRUE && o->status == YP_TRUE) { 3107c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 3117c478bd9Sstevel@tonic-gate (void) printf(s_ook, map, o->ordernum); 3127c478bd9Sstevel@tonic-gate (void) printf(s_mok, m->master); 3137c478bd9Sstevel@tonic-gate } else if (o->status == YP_TRUE) { 3147c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 3157c478bd9Sstevel@tonic-gate (void) printf(s_ook, map, o->ordernum); 3167c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_mbad, map, 3177c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(m->status))); 3187c478bd9Sstevel@tonic-gate status = 1; 3197c478bd9Sstevel@tonic-gate } else if (m->status == YP_TRUE) { 3207c478bd9Sstevel@tonic-gate (void) printf(s_domok, domain); 3217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_obad, map, 3227c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(o->status))); 3237c478bd9Sstevel@tonic-gate (void) printf(s_mok, m->master); 3247c478bd9Sstevel@tonic-gate status = 1; 3257c478bd9Sstevel@tonic-gate } else { 3267c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 3277c478bd9Sstevel@tonic-gate "Can't get any map parameter information.\n"); 3287c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_obad, map, 3297c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(o->status))); 3307c478bd9Sstevel@tonic-gate (void) fprintf(stderr, s_mbad, map, 3317c478bd9Sstevel@tonic-gate yperr_string(ypprot_err(m->status))); 3327c478bd9Sstevel@tonic-gate status = 1; 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate static void 3377c478bd9Sstevel@tonic-gate getypserv() 3387c478bd9Sstevel@tonic-gate { 3397c478bd9Sstevel@tonic-gate struct ypbind_resp response; 3407c478bd9Sstevel@tonic-gate struct ypbind_domain ypdomain; 3417c478bd9Sstevel@tonic-gate struct ypbind_binding *binding; 3427c478bd9Sstevel@tonic-gate static char hostbuf[256]; 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate getlochost(); 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate (void) memset((char *)&response, 0, sizeof (response)); 3477c478bd9Sstevel@tonic-gate ypdomain.ypbind_domainname = domain; 3487c478bd9Sstevel@tonic-gate ypdomain.ypbind_vers = YPBINDVERS; 3497c478bd9Sstevel@tonic-gate (void) rpc_call(host, YPBINDPROG, YPBINDVERS, YPBINDPROC_DOMAIN, 3507c478bd9Sstevel@tonic-gate xdr_ypbind_domain, (char *)&ypdomain, xdr_ypbind_resp, 3517c478bd9Sstevel@tonic-gate (char *)&response, "netpath"); 3527c478bd9Sstevel@tonic-gate if (response.ypbind_status != YPBIND_SUCC_VAL) { 3537c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "couldn't get yp server - status %u\n", 3547c478bd9Sstevel@tonic-gate response.ypbind_status); 3557c478bd9Sstevel@tonic-gate exit(1); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate binding = response.ypbind_resp_u.ypbind_bindinfo; 3587c478bd9Sstevel@tonic-gate host = binding->ypbind_servername; 3597c478bd9Sstevel@tonic-gate 3607c478bd9Sstevel@tonic-gate /* 3617c478bd9Sstevel@tonic-gate * When ypbind is running in broadcast mode, it sets the 3627c478bd9Sstevel@tonic-gate * servername to "". To get the real name of the server, 3637c478bd9Sstevel@tonic-gate * we need to do a host lookup on the svcaddr. This code 3647c478bd9Sstevel@tonic-gate * is similar to code in ypwhich. 3657c478bd9Sstevel@tonic-gate */ 3667c478bd9Sstevel@tonic-gate if (strcmp(host, "") == 0) { 3677c478bd9Sstevel@tonic-gate struct nd_hostservlist *nhs; 3687c478bd9Sstevel@tonic-gate struct netconfig *nconf = binding->ypbind_nconf; 3697c478bd9Sstevel@tonic-gate struct netbuf *svcaddr = binding->ypbind_svcaddr; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate if (netdir_getbyaddr(nconf, &nhs, svcaddr) != ND_OK) { 3727c478bd9Sstevel@tonic-gate struct sockaddr_in *sa; 3737c478bd9Sstevel@tonic-gate 3747c478bd9Sstevel@tonic-gate sa = (struct sockaddr_in *)svcaddr->buf; 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate strcpy(hostbuf, inet_ntoa(sa->sin_addr)); 3777c478bd9Sstevel@tonic-gate } else { 3787c478bd9Sstevel@tonic-gate sprintf(hostbuf, "%s", nhs->h_hostservs->h_host); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate host = hostbuf; 3817c478bd9Sstevel@tonic-gate netdir_free((char *)nhs, ND_HOSTSERVLIST); 3827c478bd9Sstevel@tonic-gate } 3837c478bd9Sstevel@tonic-gate } 384