1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #if defined(LIBC_SCCS) && !defined(lint) 9 static char sccsid[] = "@(#)getservbyport.c 5.6 (Berkeley) 06/01/90"; 10 #endif /* LIBC_SCCS and not lint */ 11 12 #include <netdb.h> 13 14 extern int _serv_stayopen; 15 16 struct servent * 17 getservbyport(port, proto) 18 int port; 19 char *proto; 20 { 21 register struct servent *p; 22 23 setservent(_serv_stayopen); 24 while (p = getservent()) { 25 if (p->s_port != port) 26 continue; 27 if (proto == 0 || strcmp(p->s_proto, proto) == 0) 28 break; 29 } 30 if (!_serv_stayopen) 31 endservent(); 32 return (p); 33 } 34