Do # man setrpcent I got ... getrpcent() reads the next line of the file, opening the file if necessary. getrpcent() opens and rewinds the file. If the stayopen flag is non-zero, the net data base will not be closed after each call to getrpcent() (either directly, or indi- rectly through one of the other "getrpc" calls). I think the second getrpcent should be setrpcent.