Commit | Line | Data |
---|---|---|
8ea4199d DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
6b2f9dd0 KB |
3 | * All rights reserved. |
4 | * | |
269a7923 | 5 | * %sccs.include.redist.c% |
8ea4199d DF |
6 | */ |
7 | ||
2ce81398 | 8 | #if defined(LIBC_SCCS) && !defined(lint) |
269a7923 | 9 | static char sccsid[] = "@(#)getservbyport.c 5.6 (Berkeley) %G%"; |
6b2f9dd0 | 10 | #endif /* LIBC_SCCS and not lint */ |
5528b2c1 SL |
11 | |
12 | #include <netdb.h> | |
13 | ||
5442f2c7 JL |
14 | extern int _serv_stayopen; |
15 | ||
5528b2c1 | 16 | struct servent * |
5e649950 | 17 | getservbyport(port, proto) |
5528b2c1 SL |
18 | int port; |
19 | char *proto; | |
20 | { | |
21 | register struct servent *p; | |
22 | ||
5442f2c7 | 23 | setservent(_serv_stayopen); |
5528b2c1 SL |
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 | } | |
5442f2c7 JL |
30 | if (!_serv_stayopen) |
31 | endservent(); | |
5528b2c1 SL |
32 | return (p); |
33 | } |