xref: /haiku/src/system/libnetwork/netresolv/net/getprotobynumber_r.c (revision 75e1de3c2369b5acb868c2a66e526dce183c7892)
1*75e1de3cSAugustin Cavalier /*	$NetBSD: getprotobynumber_r.c,v 1.3 2005/04/18 19:39:45 kleink Exp $	*/
2*75e1de3cSAugustin Cavalier 
3*75e1de3cSAugustin Cavalier /*
4*75e1de3cSAugustin Cavalier  * Copyright (c) 1983, 1993
5*75e1de3cSAugustin Cavalier  *	The Regents of the University of California.  All rights reserved.
6*75e1de3cSAugustin Cavalier  *
7*75e1de3cSAugustin Cavalier  * Redistribution and use in source and binary forms, with or without
8*75e1de3cSAugustin Cavalier  * modification, are permitted provided that the following conditions
9*75e1de3cSAugustin Cavalier  * are met:
10*75e1de3cSAugustin Cavalier  * 1. Redistributions of source code must retain the above copyright
11*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer.
12*75e1de3cSAugustin Cavalier  * 2. Redistributions in binary form must reproduce the above copyright
13*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer in the
14*75e1de3cSAugustin Cavalier  *    documentation and/or other materials provided with the distribution.
15*75e1de3cSAugustin Cavalier  * 3. Neither the name of the University nor the names of its contributors
16*75e1de3cSAugustin Cavalier  *    may be used to endorse or promote products derived from this software
17*75e1de3cSAugustin Cavalier  *    without specific prior written permission.
18*75e1de3cSAugustin Cavalier  *
19*75e1de3cSAugustin Cavalier  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*75e1de3cSAugustin Cavalier  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*75e1de3cSAugustin Cavalier  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*75e1de3cSAugustin Cavalier  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*75e1de3cSAugustin Cavalier  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*75e1de3cSAugustin Cavalier  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*75e1de3cSAugustin Cavalier  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*75e1de3cSAugustin Cavalier  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*75e1de3cSAugustin Cavalier  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*75e1de3cSAugustin Cavalier  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*75e1de3cSAugustin Cavalier  * SUCH DAMAGE.
30*75e1de3cSAugustin Cavalier  */
31*75e1de3cSAugustin Cavalier 
32*75e1de3cSAugustin Cavalier #include <sys/cdefs.h>
33*75e1de3cSAugustin Cavalier #if defined(LIBC_SCCS) && !defined(lint)
34*75e1de3cSAugustin Cavalier #if 0
35*75e1de3cSAugustin Cavalier static char sccsid[] = "@(#)getproto.c	8.1 (Berkeley) 6/4/93";
36*75e1de3cSAugustin Cavalier #else
37*75e1de3cSAugustin Cavalier __RCSID("$NetBSD: getprotobynumber_r.c,v 1.3 2005/04/18 19:39:45 kleink Exp $");
38*75e1de3cSAugustin Cavalier #endif
39*75e1de3cSAugustin Cavalier #endif /* LIBC_SCCS and not lint */
40*75e1de3cSAugustin Cavalier 
41*75e1de3cSAugustin Cavalier #include <netdb.h>
42*75e1de3cSAugustin Cavalier #include <stddef.h>
43*75e1de3cSAugustin Cavalier 
44*75e1de3cSAugustin Cavalier #include "protoent.h"
45*75e1de3cSAugustin Cavalier 
46*75e1de3cSAugustin Cavalier #ifdef __weak_alias
__weak_alias(getprotobynumber_r,_getprotobynumber_r)47*75e1de3cSAugustin Cavalier __weak_alias(getprotobynumber_r,_getprotobynumber_r)
48*75e1de3cSAugustin Cavalier #endif
49*75e1de3cSAugustin Cavalier 
50*75e1de3cSAugustin Cavalier struct protoent *
51*75e1de3cSAugustin Cavalier getprotobynumber_r(int proto, struct protoent *pr, struct protoent_data *pd)
52*75e1de3cSAugustin Cavalier {
53*75e1de3cSAugustin Cavalier 	struct protoent *p;
54*75e1de3cSAugustin Cavalier 
55*75e1de3cSAugustin Cavalier 	setprotoent_r(pd->stayopen, pd);
56*75e1de3cSAugustin Cavalier 	while ((p = getprotoent_r(pr, pd)) != NULL)
57*75e1de3cSAugustin Cavalier 		if (p->p_proto == proto)
58*75e1de3cSAugustin Cavalier 			break;
59*75e1de3cSAugustin Cavalier 	if (!pd->stayopen)
60*75e1de3cSAugustin Cavalier 		if (pd->fp != NULL) {
61*75e1de3cSAugustin Cavalier 			(void)fclose(pd->fp);
62*75e1de3cSAugustin Cavalier 			pd->fp = NULL;
63*75e1de3cSAugustin Cavalier 		}
64*75e1de3cSAugustin Cavalier 	return p;
65*75e1de3cSAugustin Cavalier }
66