#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>

void usage(void) 
{ 
fprintf(stderr,"Usage: [-h] [-f] netgroup groupname\n"); 
exit(1);
}


main(int argc, char **argv)
{
    char *machine,
	 *user,
	 *domain;

    int  host_part = 0;
    int  DNS_part = 0;

    int c;

    while( (c = getopt(argc, argv, "hf")) != -1 ) {
	switch(c) {
	    case 'h' : host_part = 1; break;
	    case 'f' : DNS_part = 1; break;
	}
    }
    if ( host_part == 0 && DNS_part == 0 ) {
	host_part = 1;
	DNS_part = 1;
    }

    if ( argc-optind != 1 )
	usage();

    setnetgrent(argv[optind]);
    while( getnetgrent(&machine, &user, &domain) == 1 ) {
	if ( strchr(machine, '.') != NULL && DNS_part == 1 )
	    fprintf(stdout, "%s ", machine);
	if ( strchr(machine, '.') == NULL && host_part == 1 )
	    fprintf(stdout, "%s ", machine);
    }

    endnetgrent();
    fprintf(stdout, "\n");
}