xref: /titanic_41/usr/src/lib/libsocket/inet/getnetent.c (revision 2654012f83cec5dc15b61dfe3e4a4915f186e7a6)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <netdb.h>
30 #include <nss_dbdefs.h>
31 
32 
33 #ifdef	NSS_INCLUDE_UNSAFE
34 
35 /*
36  * Ye olde non-reentrant interface (MT-unsafe, caveat utor)
37  */
38 
39 /*
40  * Don't free this, even on an endnetent(), because bitter experience shows
41  * that there's production code that does getXXXbyYYY(), then endXXXent(),
42  * and then continues to use the pointer it got back.
43  */
44 static nss_XbyY_buf_t *buffer;
45 #define	GETBUF()	\
46 NSS_XbyY_ALLOC(&buffer, (int)sizeof (struct netent), NSS_BUFLEN_NETWORKS)
47 	/* === ?? set ENOMEM on failure?  */
48 
49 struct netent *
50 getnetbyname(const char *nam)
51 {
52 	nss_XbyY_buf_t	*b;
53 	struct netent	*res = 0;
54 
55 	if ((b = GETBUF()) != 0) {
56 		res = getnetbyname_r(nam, b->result, b->buffer, b->buflen);
57 	}
58 	return (res);
59 }
60 
61 struct netent *
62 getnetbyaddr(in_addr_t net, int type)
63 {
64 	nss_XbyY_buf_t	*b;
65 	struct netent	*res = 0;
66 
67 	if ((b = GETBUF()) != 0) {
68 		res = getnetbyaddr_r(net, type, b->result,
69 				b->buffer, b->buflen);
70 	}
71 	return (res);
72 }
73 
74 struct netent *
75 getnetent(void)
76 {
77 	nss_XbyY_buf_t	*b;
78 	struct netent	*res = 0;
79 
80 	if ((b = GETBUF()) != 0) {
81 		res = getnetent_r(b->result, b->buffer, b->buflen);
82 	}
83 	return (res);
84 }
85 
86 #endif	/* NSS_INCLUDE_UNSAFE */
87