xref: /illumos-gate/usr/src/lib/libsocket/inet/getprotoent.c (revision 20a7641f9918de8574b8b3b47dbe35c4bfc78df1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1986-1992,2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include <netdb.h>
28 #include <nss_dbdefs.h>
29 
30 
31 #ifdef	NSS_INCLUDE_UNSAFE
32 
33 /*
34  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
35  */
36 
37 /*
38  * Don't free this, even on an endprotoent(), because bitter experience shows
39  * that there's production code that does getXXXbyYYY(), then endXXXent(),
40  * and then continues to use the pointer it got back.
41  */
42 static nss_XbyY_buf_t *buffer;
43 #define	GETBUF()	\
44 NSS_XbyY_ALLOC(&buffer, (int)sizeof (struct protoent), NSS_BUFLEN_PROTOCOLS)
45 	/* === ?? set ENOMEM on failure?  */
46 
47 struct protoent *
48 getprotobyname(const char *nam)
49 {
50 	nss_XbyY_buf_t	*b;
51 	struct protoent	*res = 0;
52 
53 	if ((b = GETBUF()) != 0) {
54 		res = getprotobyname_r(nam, b->result, b->buffer, b->buflen);
55 	}
56 	return (res);
57 }
58 
59 struct protoent *
60 getprotobynumber(int proto)
61 {
62 	nss_XbyY_buf_t	*b;
63 	struct protoent	*res = 0;
64 
65 	if ((b = GETBUF()) != 0) {
66 		res = getprotobynumber_r(proto, b->result,
67 					b->buffer, b->buflen);
68 	}
69 	return (res);
70 }
71 
72 struct protoent *
73 getprotoent()
74 {
75 	nss_XbyY_buf_t	*b;
76 	struct protoent	*res = 0;
77 
78 	if ((b = GETBUF()) != 0) {
79 		res = getprotoent_r(b->result, b->buffer, b->buflen);
80 	}
81 	return (res);
82 }
83 
84 #endif	/* NSS_INCLUDE_UNSAFE */
85