FreeBSD/usr.bin/ypwhich/ypwhich.c
/*
 * Like yp_bind except can query a specific host
 */
Like yp_bind except can query a specific host
Like yp_bind except can query a specific host
static int
bind_host(char *dom, struct sockaddr_in *sin)
{
	struct hostent *hent = NULL;
	struct ypbind_resp ypbr;
	struct in_addr ss_addr;
	struct timeval tv;
	CLIENT *client;
	int sock, r;
	sock = RPC_ANYSOCK;
	tv.tv_sec = 15;
	tv.tv_usec = 0;
	client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
	if (client == NULL) {
		warnx("host is not bound to a ypmaster");
		return (YPERR_YPBIND);
	}
	tv.tv_sec = 5;
	tv.tv_usec = 0;
	r = clnt_call(client, YPBINDPROC_DOMAIN,
		(xdrproc_t)xdr_domainname, &dom,
		(xdrproc_t)xdr_ypbind_resp, &ypbr, tv);
	if (r != RPC_SUCCESS) {
		warnx("can't clnt_call: %s", yperr_string(YPERR_YPBIND));
		clnt_destroy(client);
		return (YPERR_YPBIND);
	} else {
		if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
			warnx("can't yp_bind: reason: %s",
			    yperr_string(ypbr.ypbind_status));
			clnt_destroy(client);
			return (r);
		}
	}
	clnt_destroy(client);
	memmove(&ss_addr.s_addr, &ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr,
	    sizeof (ss_addr));
	hent = gethostbyaddr((char *)&ss_addr.s_addr, sizeof(ss_addr.s_addr),
	    AF_INET);
	if (hent != NULL)
		printf("%s\n", hent->h_name);
	else
		printf("%s\n", inet_ntoa(ss_addr));
	return (0);
}
static int bind_host ( char * dom , struct sockaddr_in * sin ) { struct hostent * hent = NULL ; struct ypbind_resp ypbr ; struct in_addr ss_addr ; struct timeval tv ; CLIENT * client ; int sock , r ; sock = RPC_ANYSOCK ; tv . tv_sec = 15 ; tv . tv_usec = 0 ; client = clntudp_create ( sin , YPBINDPROG , YPBINDVERS , tv , & sock ) ; if ( client == NULL ) { warnx ( " " ) ; return ( YPERR_YPBIND ) ; } tv . tv_sec = 5 ; tv . tv_usec = 0 ; r = clnt_call ( client , YPBINDPROC_DOMAIN , ( xdrproc_t ) xdr_domainname , & dom , ( xdrproc_t ) xdr_ypbind_resp , & ypbr , tv ) ; if ( r != RPC_SUCCESS ) { warnx ( " " , yperr_string ( YPERR_YPBIND ) ) ; clnt_destroy ( client ) ; return ( YPERR_YPBIND ) ; } else { if ( ypbr . ypbind_status != YPBIND_SUCC_VAL ) { warnx ( " " , yperr_string ( ypbr . ypbind_status ) ) ; clnt_destroy ( client ) ; return ( r ) ; } } clnt_destroy ( client ) ; memmove ( & ss_addr . s_addr , & ypbr . ypbind_resp_u . ypbind_bindinfo . ypbind_binding_addr , sizeof ( ss_addr ) ) ; hent = gethostbyaddr ( ( char * ) & ss_addr . s_addr , sizeof ( ss_addr . s_addr ) , AF_INET ) ; if ( hent != NULL ) printf ( " \n " , hent -> h_name ) ; else printf ( " \n " , inet_ntoa ( ss_addr ) ) ; return ( 0 ) ; }
Like yp_bind except can query a specific host
Like yp_bind except can query a specific host