INADDR_NONE, not -1; bug report 4.3BSD/lib/22
[unix-history] / usr / src / lib / libc / net / getservbyport.c
CommitLineData
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 8static 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
13extern int _serv_stayopen;
14
5528b2c1 15struct servent *
5e649950 16getservbyport(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}