1*4e3cae58Skleink /* $NetBSD: getprotobynumber_r.c,v 1.3 2005/04/18 19:39:45 kleink Exp $ */
28059eed1Schristos
38059eed1Schristos /*
48059eed1Schristos * Copyright (c) 1983, 1993
58059eed1Schristos * The Regents of the University of California. All rights reserved.
68059eed1Schristos *
78059eed1Schristos * Redistribution and use in source and binary forms, with or without
88059eed1Schristos * modification, are permitted provided that the following conditions
98059eed1Schristos * are met:
108059eed1Schristos * 1. Redistributions of source code must retain the above copyright
118059eed1Schristos * notice, this list of conditions and the following disclaimer.
128059eed1Schristos * 2. Redistributions in binary form must reproduce the above copyright
138059eed1Schristos * notice, this list of conditions and the following disclaimer in the
148059eed1Schristos * documentation and/or other materials provided with the distribution.
158059eed1Schristos * 3. Neither the name of the University nor the names of its contributors
168059eed1Schristos * may be used to endorse or promote products derived from this software
178059eed1Schristos * without specific prior written permission.
188059eed1Schristos *
198059eed1Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
208059eed1Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218059eed1Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228059eed1Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238059eed1Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248059eed1Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258059eed1Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268059eed1Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278059eed1Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288059eed1Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298059eed1Schristos * SUCH DAMAGE.
308059eed1Schristos */
318059eed1Schristos
328059eed1Schristos #include <sys/cdefs.h>
338059eed1Schristos #if defined(LIBC_SCCS) && !defined(lint)
348059eed1Schristos #if 0
358059eed1Schristos static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93";
368059eed1Schristos #else
37*4e3cae58Skleink __RCSID("$NetBSD: getprotobynumber_r.c,v 1.3 2005/04/18 19:39:45 kleink Exp $");
388059eed1Schristos #endif
398059eed1Schristos #endif /* LIBC_SCCS and not lint */
408059eed1Schristos
418059eed1Schristos #include "namespace.h"
428059eed1Schristos #include <netdb.h>
438059eed1Schristos #include <stddef.h>
448059eed1Schristos
45*4e3cae58Skleink #include "protoent.h"
46*4e3cae58Skleink
478059eed1Schristos #ifdef __weak_alias
__weak_alias(getprotobynumber_r,_getprotobynumber_r)488059eed1Schristos __weak_alias(getprotobynumber_r,_getprotobynumber_r)
498059eed1Schristos #endif
508059eed1Schristos
518059eed1Schristos struct protoent *
528059eed1Schristos getprotobynumber_r(int proto, struct protoent *pr, struct protoent_data *pd)
538059eed1Schristos {
548059eed1Schristos struct protoent *p;
558059eed1Schristos
568059eed1Schristos setprotoent_r(pd->stayopen, pd);
578059eed1Schristos while ((p = getprotoent_r(pr, pd)) != NULL)
588059eed1Schristos if (p->p_proto == proto)
598059eed1Schristos break;
608059eed1Schristos if (!pd->stayopen)
61119b5f63Senami if (pd->fp != NULL) {
62119b5f63Senami (void)fclose(pd->fp);
63119b5f63Senami pd->fp = NULL;
64119b5f63Senami }
658059eed1Schristos return p;
668059eed1Schristos }
67