Commit | Line | Data |
---|---|---|
8ea4199d DF |
1 | /* |
2 | * Copyright (c) 1983 Regents of the University of California. | |
3 | * All rights reserved. The Berkeley software License Agreement | |
4 | * specifies the terms and conditions for redistribution. | |
5 | */ | |
6 | ||
2ce81398 | 7 | #if defined(LIBC_SCCS) && !defined(lint) |
5442f2c7 | 8 | static char sccsid[] = "@(#)getservbyport.c 5.3 (Berkeley) %G%"; |
2ce81398 | 9 | #endif LIBC_SCCS and not lint |
5528b2c1 SL |
10 | |
11 | #include <netdb.h> | |
12 | ||
5442f2c7 JL |
13 | extern int _serv_stayopen; |
14 | ||
5528b2c1 | 15 | struct servent * |
5e649950 | 16 | getservbyport(port, proto) |
5528b2c1 SL |
17 | int port; |
18 | char *proto; | |
19 | { | |
20 | register struct servent *p; | |
21 | ||
5442f2c7 | 22 | setservent(_serv_stayopen); |
5528b2c1 SL |
23 | while (p = getservent()) { |
24 | if (p->s_port != port) | |
25 | continue; | |
26 | if (proto == 0 || strcmp(p->s_proto, proto) == 0) | |
27 | break; | |
28 | } | |
5442f2c7 JL |
29 | if (!_serv_stayopen) |
30 | endservent(); | |
5528b2c1 SL |
31 | return (p); |
32 | } |