#include #include #define DOMAINNAME "cs-snuent" #define YPMAP "passwd.byname" #pragma ident "ypcat.c 10/29/06 CAM" /* * ypcat.c * * `ypcat` using yp_first() & yp_next(). * */ int main( int argc, char **argv ) { char **outkey; int *outkey_len; char **outval; int *outval_len; int yp_ret = 0; outkey = (char**) malloc(sizeof(char*)); /* Allocate */ (void) memset((void *)outkey, 0, sizeof(char*)); /* Initalize */ outval = (char**) malloc(sizeof(char*)); /* Allocate */ (void) memset((void *)outval, 0, sizeof(char*)); /* Initalize */ if( (yp_ret = yp_first( DOMAINNAME, YPMAP, outkey, outkey_len, outval, outval_len ) ) != 0 ) { printf("Problem: yp_first returned nonzero. (%i=%s)\n", yp_ret, yperr_string(ypprot_err(yp_ret)) ); } printf("%s", *outval); /*N.B. appears both 'out' strings are terminated with '\n'.*/ while( (yp_ret = yp_next( DOMAINNAME, YPMAP, *outkey, *outkey_len, outkey, outkey_len, outval, outval_len ) ) == 0 ) { printf("%s", *outval); /*N.B. appears both 'out' strings are terminated with '\n'.*/ } printf("Problem: yp_first returned nonzero. (%i=%s)\n", yp_ret, yperr_string(ypprot_err(yp_ret)) ); (void) free((void *)outkey); (void) free((void *)outval); return 0; }