1*75e1de3cSAugustin Cavalier /* $NetBSD: getservbyport.c,v 1.12 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
32*75e1de3cSAugustin Cavalier #include <sys/cdefs.h>
33*75e1de3cSAugustin Cavalier #if defined(LIBC_SCCS) && !defined(lint)
34*75e1de3cSAugustin Cavalier __RCSID("$NetBSD: getservbyport.c,v 1.12 2008/04/28 20:23:00 martin Exp $");
35*75e1de3cSAugustin Cavalier #endif /* LIBC_SCCS and not lint */
36*75e1de3cSAugustin Cavalier
37*75e1de3cSAugustin Cavalier #include <netdb.h>
38*75e1de3cSAugustin Cavalier #include <pthread.h>
39*75e1de3cSAugustin Cavalier
40*75e1de3cSAugustin Cavalier #include "servent.h"
41*75e1de3cSAugustin Cavalier
42*75e1de3cSAugustin Cavalier #ifdef __weak_alias
43*75e1de3cSAugustin Cavalier __weak_alias(getservbyport,_getservbyport)
44*75e1de3cSAugustin Cavalier #endif
45*75e1de3cSAugustin Cavalier
46*75e1de3cSAugustin Cavalier #ifdef _REENTRANT
47*75e1de3cSAugustin Cavalier extern pthread_mutex_t _servent_mutex;
48*75e1de3cSAugustin Cavalier #endif
49*75e1de3cSAugustin Cavalier extern struct servent_data _servent_data;
50*75e1de3cSAugustin Cavalier
51*75e1de3cSAugustin Cavalier struct servent *
getservbyport(int port,const char * proto)52*75e1de3cSAugustin Cavalier getservbyport(int port, const char *proto)
53*75e1de3cSAugustin Cavalier {
54*75e1de3cSAugustin Cavalier struct servent *s;
55*75e1de3cSAugustin Cavalier
56*75e1de3cSAugustin Cavalier pthread_mutex_lock(&_servent_mutex);
57*75e1de3cSAugustin Cavalier s = getservbyport_r(port, proto, &_servent_data.serv, &_servent_data);
58*75e1de3cSAugustin Cavalier pthread_mutex_unlock(&_servent_mutex);
59*75e1de3cSAugustin Cavalier return (s);
60*75e1de3cSAugustin Cavalier }
61