fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* number of transports to try */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(sock, SIOCGLIFNUM, (char *)&lifn) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following is stolen from autod_nfs.c
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sock = socket(family, SOCK_DGRAM, 0)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ioctl(sock, SIOCGIFNUM, (char *)&numifs) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte buf = (char *)malloc(numifs * sizeof (struct ifreq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "getmyaddrs(): malloc failed\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the IP address for hostname
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "self_check(): getnetconfigent failed\n");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (netdir_getbyname(nconfp, &hs, &retaddrs) != ND_OK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s1 = (struct sockaddr_in *)retaddrs->n_addrs->buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now compare it against the list of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addresses for the interfaces on this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; n > 0; n--, ifr++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (char *)&s1->sin_addr, sizeof (s1->sin_addr)) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteconvert_nconf_to_knconf(struct netconfig *nconf, struct knetconfig *knconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) syslog(LOG_ERR, "can't find device for transport %s\n",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
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 return (getipnodebyname(name, AF_INET6, AI_DEFAULT, &errnum));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = getipnodebyname(fromhost, AF_INET6, AI_DEFAULT, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "host->h_length(%d) < 4!\n", host->h_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte host = getipnodebyname(tohost, AF_INET6, AI_DEFAULT, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else /* !AF_INET6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fprintf(stderr, "host->h_length(%d) < 4!\n", host->h_length);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* AF_INET6 */
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 * If the address of a netconfig pointer is null then
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information is not sufficient and no netbuf will be returned.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Finally, ping the null procedure of that service.
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 if ((fd = t_open(nconf->nc_device, O_RDWR, tinfo)) == -1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((tbind = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rpcb_getaddr(prog, vers, nconf, &tbind->addr,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED pointer alignment */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)tbind->addr.buf)->sin_port
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 /* Simon -- we never use the client we create?! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cl = clnt_tli_create(fd, nconf, &tbind->addr, prog, vers, 0, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) clnt_control(cl, CLSET_TIMEOUT, (char *)&tv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* create our own address and skip rpcbind */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(nconf->nc_protofmly, NC_INET6) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = getipnodebyname(hostname, AF_INET6, 0, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->len = nb->maxlen = sizeof (struct sockaddr_in6);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte hp = getipnodebyname(hostname, AF_INET, 0, &errnum);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nb->len = nb->maxlen = sizeof (struct sockaddr_in);
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 /* 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 nb->len = nb->maxlen = sizeof (struct sockaddr_in);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_port = port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((struct sockaddr_in *)(nb->buf))->sin_family = AF_INET;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Make a copy of the netbuf to return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) memcpy(nb->buf, tbind->addr.buf, tbind->addr.len);
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 * 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 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 * First lets get the requested port
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((svp = getservbyname(srvport, proto)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No nconf passed in.
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 * If proto is specified, then only search for the match,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * otherwise try COTS first, if failed, try CLTS.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the port number is specified then TCP/UDP
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is needed. Otherwise any cots/clts will do.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nb = get_the_addr(hostname, prog, vers, nconf, port,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CSTYLED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* while */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((nb = get_the_addr(hostname, prog, vers, nconf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Continue the same search path in the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * netconfig db until no more matched
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nconf (nconf == NULL).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We have a mismatch in the netconfig retry
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Got nconf and nb. Now dup the netconfig structure (nconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and return it thru nconfp.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* return values as for nsc_check_release() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* librdc.so must be built on the runtime OS release */