xref: /csrg-svn/lib/libc/net/getnetbyname.c (revision 28280)
121376Sdist /*
221376Sdist  * Copyright (c) 1983 Regents of the University of California.
321376Sdist  * All rights reserved.  The Berkeley software License Agreement
421376Sdist  * specifies the terms and conditions for redistribution.
521376Sdist  */
67897Ssam 
726617Sdonn #if defined(LIBC_SCCS) && !defined(lint)
8*28280Slepreau static char sccsid[] = "@(#)getnetbyname.c	5.3 (Berkeley) 05/19/86";
926617Sdonn #endif LIBC_SCCS and not lint
1021376Sdist 
117897Ssam #include <netdb.h>
127897Ssam 
13*28280Slepreau extern int _net_stayopen;
14*28280Slepreau 
157897Ssam struct netent *
168324Ssam getnetbyname(name)
177897Ssam 	register char *name;
187897Ssam {
197897Ssam 	register struct netent *p;
207897Ssam 	register char **cp;
217897Ssam 
22*28280Slepreau 	setnetent(_net_stayopen);
237897Ssam 	while (p = getnetent()) {
247897Ssam 		if (strcmp(p->n_name, name) == 0)
257897Ssam 			break;
267897Ssam 		for (cp = p->n_aliases; *cp != 0; cp++)
277897Ssam 			if (strcmp(*cp, name) == 0)
287897Ssam 				goto found;
297897Ssam 	}
307897Ssam found:
31*28280Slepreau 	if (!_net_stayopen)
32*28280Slepreau 		endnetent();
337897Ssam 	return (p);
347897Ssam }
35