FreeBSD/usr.sbin/rpc.lockd/lockd.c
/*
 * Look up addresses for the kernel to create transports for.
 */
Look up addresses for the kernel to create transports for.
Look up addresses for the kernel to create transports for .
void
lookup_addresses(struct netconfig *nconf)
{
	struct addrinfo hints, *res = NULL;
	struct sockaddr_in *sin;
	struct sockaddr_in6 *sin6;
	struct __rpc_sockinfo si;
	struct netbuf servaddr;
	int aicode;
	int nhostsbak;
	u_int32_t host_addr[4];  
	char *uaddr;
	if ((nconf->nc_semantics != NC_TPI_CLTS) &&
	    (nconf->nc_semantics != NC_TPI_COTS) &&
	    (nconf->nc_semantics != NC_TPI_COTS_ORD))
		return;	
	if (!__rpc_nconf2sockinfo(nconf, &si)) {
		syslog(LOG_ERR, "cannot get information for %s",
		    nconf->nc_netid);
		return;
	}
	memset(&hints, 0, sizeof hints);
	hints.ai_flags = AI_PASSIVE;
	hints.ai_family = si.si_af;
	hints.ai_socktype = si.si_socktype;
	hints.ai_protocol = si.si_proto;
	nhostsbak = nhosts;
	while (nhostsbak > 0) {
		--nhostsbak;
		switch (hints.ai_family) {
			case AF_INET:
				if (inet_pton(AF_INET, hosts[nhostsbak],
				    host_addr) == 1) {
					hints.ai_flags &= AI_NUMERICHOST;
				} else {
					if (inet_pton(AF_INET6, hosts[nhostsbak],
					    host_addr) == 1) {
						continue;
					}
				}
				break;
			case AF_INET6:
				if (inet_pton(AF_INET6, hosts[nhostsbak],
				    host_addr) == 1) {
					hints.ai_flags &= AI_NUMERICHOST;
				} else {
					if (inet_pton(AF_INET, hosts[nhostsbak],
					    host_addr) == 1) {
						continue;
					}
				}
				break;
			default:
				break;
		}
		if (strcmp("*", hosts[nhostsbak]) == 0) {
			if (svcport_str == NULL) {
				res = malloc(sizeof(struct addrinfo));
				if (res == NULL) 
					out_of_mem();
				res->ai_flags = hints.ai_flags;
				res->ai_family = hints.ai_family;
				res->ai_protocol = hints.ai_protocol;
				switch (res->ai_family) {
					case AF_INET:
						sin = malloc(sizeof(struct sockaddr_in));
						if (sin == NULL) 
							out_of_mem();
						sin->sin_family = AF_INET;
						sin->sin_port = htons(0);
						sin->sin_addr.s_addr = htonl(INADDR_ANY);
						res->ai_addr = (struct sockaddr*) sin;
						res->ai_addrlen = (socklen_t)
						    sizeof(res->ai_addr);
						break;
					case AF_INET6:
						sin6 = malloc(sizeof(struct sockaddr_in6));
						if (sin6 == NULL)
							out_of_mem();
						sin6->sin6_family = AF_INET6;
						sin6->sin6_port = htons(0);
						sin6->sin6_addr = in6addr_any;
						res->ai_addr = (struct sockaddr*) sin6;
						res->ai_addrlen = (socklen_t) sizeof(res->ai_addr);
						break;
					default:
						break;
				}
			} else { 
				if ((aicode = getaddrinfo(NULL, svcport_str,
				    &hints, &res)) != 0) {
					syslog(LOG_ERR,
					    "cannot get local address for %s: %s",
					    nconf->nc_netid,
					    gai_strerror(aicode));
					continue;
				}
			}
		} else {
			if ((aicode = getaddrinfo(hosts[nhostsbak], svcport_str,
			    &hints, &res)) != 0) {
				syslog(LOG_ERR,
				    "cannot get local address for %s: %s",
				    nconf->nc_netid, gai_strerror(aicode));
				continue;
			}
		}
		servaddr.len = servaddr.maxlen = res->ai_addr->sa_len;
		servaddr.buf = res->ai_addr;
		uaddr = taddr2uaddr(nconf, &servaddr);
		addrs = realloc(addrs, 2 * (naddrs + 1) * sizeof(char *));
		if (!addrs)
			out_of_mem();
		addrs[2 * naddrs] = strdup(nconf->nc_netid);
		addrs[2 * naddrs + 1] = uaddr;
		naddrs++;
	} 
}
void lookup_addresses ( struct netconfig * nconf ) { struct addrinfo hints , * res = NULL ; struct sockaddr_in * sin ; struct sockaddr_in6 * sin6 ; struct __rpc_sockinfo si ; struct netbuf servaddr ; int aicode ; int nhostsbak ; u_int32_t host_addr [ 4 ] ; char * uaddr ; if ( ( nconf -> nc_semantics != NC_TPI_CLTS ) && ( nconf -> nc_semantics != NC_TPI_COTS ) && ( nconf -> nc_semantics != NC_TPI_COTS_ORD ) ) return ; if ( ! __rpc_nconf2sockinfo ( nconf , & si ) ) { syslog ( LOG_ERR , " " , nconf -> nc_netid ) ; return ; } memset ( & hints , 0 , sizeof hints ) ; hints . ai_flags = AI_PASSIVE ; hints . ai_family = si . si_af ; hints . ai_socktype = si . si_socktype ; hints . ai_protocol = si . si_proto ; nhostsbak = nhosts ; while ( nhostsbak > 0 ) { -- nhostsbak ; switch ( hints . ai_family ) { case AF_INET : if ( inet_pton ( AF_INET , hosts [ nhostsbak ] , host_addr ) == 1 ) { hints . ai_flags &= AI_NUMERICHOST ; } else { if ( inet_pton ( AF_INET6 , hosts [ nhostsbak ] , host_addr ) == 1 ) { continue ; } } break ; case AF_INET6 : if ( inet_pton ( AF_INET6 , hosts [ nhostsbak ] , host_addr ) == 1 ) { hints . ai_flags &= AI_NUMERICHOST ; } else { if ( inet_pton ( AF_INET , hosts [ nhostsbak ] , host_addr ) == 1 ) { continue ; } } break ; default : break ; } if ( strcmp ( " " , hosts [ nhostsbak ] ) == 0 ) { if ( svcport_str == NULL ) { res = malloc ( sizeof ( struct addrinfo ) ) ; if ( res == NULL ) out_of_mem ( ) ; res -> ai_flags = hints . ai_flags ; res -> ai_family = hints . ai_family ; res -> ai_protocol = hints . ai_protocol ; switch ( res -> ai_family ) { case AF_INET : sin = malloc ( sizeof ( struct sockaddr_in ) ) ; if ( sin == NULL ) out_of_mem ( ) ; sin -> sin_family = AF_INET ; sin -> sin_port = htons ( 0 ) ; sin -> sin_addr . s_addr = htonl ( INADDR_ANY ) ; res -> ai_addr = ( struct sockaddr * ) sin ; res -> ai_addrlen = ( socklen_t ) sizeof ( res -> ai_addr ) ; break ; case AF_INET6 : sin6 = malloc ( sizeof ( struct sockaddr_in6 ) ) ; if ( sin6 == NULL ) out_of_mem ( ) ; sin6 -> sin6_family = AF_INET6 ; sin6 -> sin6_port = htons ( 0 ) ; sin6 -> sin6_addr = in6addr_any ; res -> ai_addr = ( struct sockaddr * ) sin6 ; res -> ai_addrlen = ( socklen_t ) sizeof ( res -> ai_addr ) ; break ; default : break ; } } else { if ( ( aicode = getaddrinfo ( NULL , svcport_str , & hints , & res ) ) != 0 ) { syslog ( LOG_ERR , " " , nconf -> nc_netid , gai_strerror ( aicode ) ) ; continue ; } } } else { if ( ( aicode = getaddrinfo ( hosts [ nhostsbak ] , svcport_str , & hints , & res ) ) != 0 ) { syslog ( LOG_ERR , " " , nconf -> nc_netid , gai_strerror ( aicode ) ) ; continue ; } } servaddr . len = servaddr . maxlen = res -> ai_addr -> sa_len ; servaddr . buf = res -> ai_addr ; uaddr = taddr2uaddr ( nconf , & servaddr ) ; addrs = realloc ( addrs , 2 * ( naddrs + 1 ) * sizeof ( char * ) ) ; if ( ! addrs ) out_of_mem ( ) ; addrs [ 2 * naddrs ] = strdup ( nconf -> nc_netid ) ; addrs [ 2 * naddrs + 1 ] = uaddr ; naddrs ++ ; } }
Look up addresses for the kernel to create transports for.
Look up addresses for the kernel to create transports for .
/* IPv4 or IPv6 */ /* not my type */ /*
	 * XXX - using RPC library internal functions.
	 */ /* Get rpc.statd's address on this transport */ /*
	 * Bind to specific IPs if asked to
	 */ /*
					 * Skip if we have an AF_INET6 address.
					 */ /*
					 * Skip if we have an AF_INET address.
					 */ /*
		 * If no hosts were specified, just bind to INADDR_ANY
		 */ /* end while */