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) |
24fac7d8 | 9 | static char sccsid[] = "@(#)getservbyport.c 5.7 (Berkeley) %G%"; |
6b2f9dd0 | 10 | #endif /* LIBC_SCCS and not lint */ |
5528b2c1 SL |
11 | |
12 | #include <netdb.h> | |
24fac7d8 | 13 | #include <string.h> |
5528b2c1 | 14 | |
5442f2c7 JL |
15 | extern int _serv_stayopen; |
16 | ||
5528b2c1 | 17 | struct servent * |
5e649950 | 18 | getservbyport(port, proto) |
5528b2c1 | 19 | int port; |
24fac7d8 | 20 | const char *proto; |
5528b2c1 SL |
21 | { |
22 | register struct servent *p; | |
23 | ||
5442f2c7 | 24 | setservent(_serv_stayopen); |
5528b2c1 SL |
25 | while (p = getservent()) { |
26 | if (p->s_port != port) | |
27 | continue; | |
28 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | |
29 | break; | |
30 | } | |
5442f2c7 JL |
31 | if (!_serv_stayopen) |
32 | endservent(); | |
5528b2c1 SL |
33 | return (p); |
34 | } |