xref: /haiku/src/system/libnetwork/netresolv/net/getprotobyname.c (revision 75e1de3c2369b5acb868c2a66e526dce183c7892)
1*75e1de3cSAugustin Cavalier /*	$NetBSD: getprotobyname.c,v 1.4 2008/04/28 20:23:00 martin Exp $	*/
2*75e1de3cSAugustin Cavalier 
3*75e1de3cSAugustin Cavalier /*-
4*75e1de3cSAugustin Cavalier  * Copyright (c) 2004 The NetBSD Foundation, Inc.
5*75e1de3cSAugustin Cavalier  * All rights reserved.
6*75e1de3cSAugustin Cavalier  *
7*75e1de3cSAugustin Cavalier  * This code is derived from software contributed to The NetBSD Foundation
8*75e1de3cSAugustin Cavalier  * by Christos Zoulas.
9*75e1de3cSAugustin Cavalier  *
10*75e1de3cSAugustin Cavalier  * Redistribution and use in source and binary forms, with or without
11*75e1de3cSAugustin Cavalier  * modification, are permitted provided that the following conditions
12*75e1de3cSAugustin Cavalier  * are met:
13*75e1de3cSAugustin Cavalier  * 1. Redistributions of source code must retain the above copyright
14*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer.
15*75e1de3cSAugustin Cavalier  * 2. Redistributions in binary form must reproduce the above copyright
16*75e1de3cSAugustin Cavalier  *    notice, this list of conditions and the following disclaimer in the
17*75e1de3cSAugustin Cavalier  *    documentation and/or other materials provided with the distribution.
18*75e1de3cSAugustin Cavalier  *
19*75e1de3cSAugustin Cavalier  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20*75e1de3cSAugustin Cavalier  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21*75e1de3cSAugustin Cavalier  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22*75e1de3cSAugustin Cavalier  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23*75e1de3cSAugustin Cavalier  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24*75e1de3cSAugustin Cavalier  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25*75e1de3cSAugustin Cavalier  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26*75e1de3cSAugustin Cavalier  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27*75e1de3cSAugustin Cavalier  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28*75e1de3cSAugustin Cavalier  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29*75e1de3cSAugustin Cavalier  * POSSIBILITY OF SUCH DAMAGE.
30*75e1de3cSAugustin Cavalier  */
31*75e1de3cSAugustin Cavalier #include <sys/cdefs.h>
32*75e1de3cSAugustin Cavalier #if defined(LIBC_SCCS) && !defined(lint)
33*75e1de3cSAugustin Cavalier __RCSID("$NetBSD: getprotobyname.c,v 1.4 2008/04/28 20:23:00 martin Exp $");
34*75e1de3cSAugustin Cavalier #endif /* LIBC_SCCS and not lint */
35*75e1de3cSAugustin Cavalier 
36*75e1de3cSAugustin Cavalier #include <pthread.h>
37*75e1de3cSAugustin Cavalier #include <netdb.h>
38*75e1de3cSAugustin Cavalier 
39*75e1de3cSAugustin Cavalier #include "protoent.h"
40*75e1de3cSAugustin Cavalier 
41*75e1de3cSAugustin Cavalier #ifdef __weak_alias
42*75e1de3cSAugustin Cavalier __weak_alias(getprotobyname,_getprotobyname)
43*75e1de3cSAugustin Cavalier #endif
44*75e1de3cSAugustin Cavalier 
45*75e1de3cSAugustin Cavalier #ifdef _REENTRANT
46*75e1de3cSAugustin Cavalier extern pthread_mutex_t _protoent_mutex;
47*75e1de3cSAugustin Cavalier #endif
48*75e1de3cSAugustin Cavalier extern struct protoent_data _protoent_data;
49*75e1de3cSAugustin Cavalier 
50*75e1de3cSAugustin Cavalier struct protoent *
getprotobyname(const char * name)51*75e1de3cSAugustin Cavalier getprotobyname(const char *name)
52*75e1de3cSAugustin Cavalier {
53*75e1de3cSAugustin Cavalier 	struct protoent *p;
54*75e1de3cSAugustin Cavalier 
55*75e1de3cSAugustin Cavalier 	pthread_mutex_lock(&_protoent_mutex);
56*75e1de3cSAugustin Cavalier 	p = getprotobyname_r(name, &_protoent_data.proto, &_protoent_data);
57*75e1de3cSAugustin Cavalier 	pthread_mutex_unlock(&_protoent_mutex);
58*75e1de3cSAugustin Cavalier 	return (p);
59*75e1de3cSAugustin Cavalier }
60