fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <string.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <memory.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <varargs.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <ctype.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <signal.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/param.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <rpc/rpc.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netdb.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/pathconf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netdir.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netconfig.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sockio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <net/if.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <syslog.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <netinet/in.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nfs/nfs_sec.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/rdc_prot.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "librdc.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MAXIFS 32
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* number of transports to try */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define MNT_PREF_LISTLEN 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define FIRST_TRY 1
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define SECOND_TRY 2
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteIs_ipv6present(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct lifnum lifn;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sock = socket(AF_INET6, SOCK_DGRAM, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sock < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lifn.lifn_family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lifn.lifn_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(sock, SIOCGLIFNUM, (char *)&lifn) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(sock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte close(sock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (lifn.lifn_count == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following is stolen from autod_nfs.c
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegetmyaddrs(struct ifconf *ifc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int numifs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int family;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifc->ifc_buf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifc->ifc_len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sock = socket(family, SOCK_DGRAM, 0)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("getmyaddrs(): socket");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(sock, SIOCGIFNUM, (char *)&numifs) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("getmyaddrs(): SIOCGIFNUM");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte numifs = MAXIFS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = (char *)malloc(numifs * sizeof (struct ifreq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "getmyaddrs(): malloc failed\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(sock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifc->ifc_buf = buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifc->ifc_len = numifs * sizeof (struct ifreq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(sock, SIOCGIFCONF, (char *)ifc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror("getmyaddrs(): SIOCGIFCONF");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*EMPTY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) close(sock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteself_check(char *hostname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int n;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct sockaddr_in *s1, *s2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ifreq *ifr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nd_hostserv hs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct nd_addrlist *retaddrs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netconfig *nconfp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct ifconf *ifc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int retval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifc = malloc(sizeof (struct ifconf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ifc == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte memset((char *)ifc, 0, sizeof (struct ifconf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte getmyaddrs(ifc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the IP address for hostname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nconfp = getnetconfigent("udp");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nconfp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "self_check(): getnetconfigent failed\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hs.h_host = hostname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hs.h_serv = "rpcbind";
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netdir_getbyname(nconfp, &hs, &retaddrs) != ND_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freenetconfigent(nconfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freenetconfigent(nconfp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s1 = (struct sockaddr_in *)retaddrs->n_addrs->buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now compare it against the list of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addresses for the interfaces on this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ifr = ifc->ifc_req;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte n = ifc->ifc_len / sizeof (struct ifreq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s2 = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; n > 0; n--, ifr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ifr->ifr_addr.sa_family != AF_INET)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s2 = (struct sockaddr_in *)&ifr->ifr_addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (memcmp((char *)&s2->sin_addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&s1->sin_addr, sizeof (s1->sin_addr)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netdir_free((void *)retaddrs, ND_ADDRLIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out; /* it's me */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte netdir_free((void *)retaddrs, ND_ADDRLIST);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte retval = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ifc->ifc_buf != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ifc->ifc_buf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(ifc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (retval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconvert_nconf_to_knconf(struct netconfig *nconf, struct knetconfig *knconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(nconf->nc_device, &sb) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) syslog(LOG_ERR, "can't find device for transport %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nconf->nc_device);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_ADDR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte printf("lib knconf %x %s %s %x\n", nconf->nc_semantics,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nconf->nc_protofmly, nconf->nc_proto, sb.st_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_semantics = nconf->nc_semantics;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_protofmly = nconf->nc_protofmly;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_proto = nconf->nc_proto;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_rdev = sb.st_rdev;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct hostent *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegethost_byname(const char *name)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int errnum;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (getipnodebyname(name, AF_INET6, AI_DEFAULT, &errnum));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (gethostbyname(name));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegethost_netaddrs(char *fromhost, char *tohost,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *fromnetaddr, char *tonetaddr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct hostent *host;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int errnum;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = getipnodebyname(fromhost, AF_INET6, AI_DEFAULT, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s"), fromhost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < host->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fromnetaddr[j] = host->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freehostent(host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = gethostbyname(fromhost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s"), fromhost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host->h_length < 4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "host->h_length(%d) < 4!\n", host->h_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < host->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fromnetaddr[j] = host->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = getipnodebyname(tohost, AF_INET6, AI_DEFAULT, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s"), tohost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < host->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tonetaddr[j] = host->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freehostent(host);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = gethostbyname(tohost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s"), tohost);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (host->h_length < 4) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "host->h_length(%d) < 4!\n", host->h_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < host->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tonetaddr[j] = host->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the network address on "hostname" for program "prog"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with version "vers" by using the nconf configuration data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the address of a netconfig pointer is null then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information is not sufficient and no netbuf will be returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Finally, ping the null procedure of that service.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic struct netbuf *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_the_addr(char *hostname, ulong_t prog, ulong_t vers,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netconfig *nconf, ushort_t port, struct t_info *tinfo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int portmap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf *nb = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct t_bind *tbind = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLIENT *cl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct timeval tv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int fd = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AUTH *ah = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nconf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd = t_open(nconf->nc_device, O_RDWR, tinfo)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tbind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (portmap) { /* contact rpcbind */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rpcb_getaddr(prog, vers, nconf, &tbind->addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hostname) == FALSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(nconf->nc_protofmly, NC_INET) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)tbind->addr.buf)->sin_port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NC_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (strcmp(nconf->nc_protofmly, NC_INET6) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in6 *)tbind->addr.buf)->sin6_port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Simon -- we never use the client we create?! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = clnt_tli_create(fd, nconf, &tbind->addr, prog, vers, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ah = authsys_create_default();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ah != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl->cl_auth = ah;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tv.tv_sec = 5;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tv.tv_usec = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clnt_control(cl, CLSET_TIMEOUT, (char *)&tv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* create our own address and skip rpcbind */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf *nb;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct hostent *hp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int j;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int errnum;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned short family;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb = &(tbind->addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(nconf->nc_protofmly, NC_INET6) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = getipnodebyname(hostname, AF_INET6, 0, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte family = AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->len = nb->maxlen = sizeof (struct sockaddr_in6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = getipnodebyname(hostname, AF_INET, 0, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->len = nb->maxlen = sizeof (struct sockaddr_in);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_ADDR
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s\n"), hostname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf = (char *)calloc(1, nb->maxlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nb->buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(dgettext("sndr", "no memory\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (family == AF_INET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < hp->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf[j+4] = hp->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_port = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < hp->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf[j+8] = hp->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in6 *)(nb->buf))->sin6_port = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in6 *)(nb->buf))->sin6_family =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AF_INET6;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte freehostent(hp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = gethostbyname(hostname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) fprintf(stderr, dgettext("sndr",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Could not find host %s"), hostname);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->len = nb->maxlen = sizeof (struct sockaddr_in);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf = (char *)calloc(1, nb->maxlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nb->buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(dgettext("sndr", "no memory\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (j = 0; j < hp->h_length; j++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf[j+4] = hp->h_addr[j];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (hp->h_addrtype == AF_INET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_port = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make a copy of the netbuf to return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb = (struct netbuf *)calloc(1, sizeof (*nb));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nb == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(dgettext("sndr", "no memory\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nb = tbind->addr; /* structure copy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->buf = (char *)calloc(1, nb->maxlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nb->buf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) printf(dgettext("sndr", "no memory\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memcpy(nb->buf, tbind->addr.buf, tbind->addr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cl) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ah != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte AUTH_DESTROY(cl->cl_auth);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl->cl_auth = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte clnt_destroy(cl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tbind) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte t_free((char *)tbind, T_BIND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tbind = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) t_close(fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get a network address on "hostname" for program "prog"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * with version "vers". If the port number is specified (non zero)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then try for a TCP/UDP transport and set the port number of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * resulting IP address.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the address of a netconfig pointer was passed and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if it's not null, use it as the netconfig otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * assign the address of the netconfig that was used to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * establish contact with the service.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If portmap is false, we return a similiar address and we do not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * contact rpcbind
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestruct netbuf *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteget_addr(char *hostname, ulong_t prog, ulong_t vers, struct netconfig **nconfp,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *proto, char *srvport, struct t_info *tinfo, int portmap)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf *nb = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netconfig *nconf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NCONF_HANDLE *nc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nthtry = FIRST_TRY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct servent *svp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ushort_t port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First lets get the requested port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((svp = getservbyname(srvport, proto)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port = svp->s_port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No nconf passed in.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Try to get a nconf from /etc/netconfig filtered by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the NETPATH environment variable.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First search for COTS, second for CLTS unless proto
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is specified. When we retry, we reset the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * netconfig list so that we would search the whole list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all over again.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nc = setnetpath()) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If proto is specified, then only search for the match,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise try COTS first, if failed, try CLTS.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (proto) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nconf = getnetpath(nc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(nconf->nc_netid, proto) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the port number is specified then TCP/UDP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is needed. Otherwise any cots/clts will do.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(nconf->nc_protofmly, NC_INET) == 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NC_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte || strcmp(nconf->nc_protofmly, NC_INET6) == 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(nconf->nc_proto, NC_TCP) == 0 ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strcmp(nconf->nc_proto, NC_UDP) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nconf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nconf == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nb = get_the_addr(hostname, prog, vers, nconf, port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tinfo, portmap)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (nconf = getnetpath(nc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nconf->nc_flag & NC_VISIBLE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nthtry == FIRST_TRY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nconf->nc_semantics == NC_TPI_COTS_ORD) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nconf->nc_semantics == NC_TPI_COTS)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (port == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((strcmp(nconf->nc_protofmly,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NC_INET) == 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef NC_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte || strcmp(nconf->nc_protofmly,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NC_INET6) == 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(nconf->nc_proto, NC_TCP) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nconf == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++nthtry <= MNT_PREF_LISTLEN) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte endnetpath(nc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nc = setnetpath()) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nb = get_the_addr(hostname, prog, vers, nconf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port, tinfo, portmap)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Continue the same search path in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * netconfig db until no more matched
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nconf (nconf == NULL).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef AF_INET6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nb->len == 8) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (strcmp(nconf->nc_protofmly, NC_INET6) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have a mismatch in the netconfig retry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Got nconf and nb. Now dup the netconfig structure (nconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return it thru nconfp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *nconfp = getnetconfigent(nconf->nc_netid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*nconfp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syslog(LOG_ERR, "no memory\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte endnetpath(nc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nb);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* return values as for nsc_check_release() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_check_release(char **reqd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* librdc.so must be built on the runtime OS release */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (nsc_check_release(BUILD_REV_STR, NULL, reqd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}