xref: /freebsd/lib/libc/net/netdb_private.h (revision 5342d17f09a8eec0477b117bc74a90921ac2f03e)
1 /*-
2  * Copyright (C) 2005 The FreeBSD Project.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  * $FreeBSD$
26  */
27 
28 #ifndef _NETDB_PRIVATE_H_
29 #define _NETDB_PRIVATE_H_
30 
31 #include <stdio.h>				/* XXX: for FILE */
32 
33 #define	_MAXALIASES	35
34 #define	_MAXLINELEN	1024
35 #define	_MAXADDRS	35
36 #define	_HOSTBUFSIZE	(8 * 1024)
37 #define	_NETBUFSIZE	1025
38 
39 struct __res_state;
40 
41 struct hostent_data {
42 	uint32_t host_addr[4];			/* IPv4 or IPv6 */
43 	char *h_addr_ptrs[_MAXADDRS + 1];
44 	char *host_aliases[_MAXALIASES];
45 	char hostbuf[_HOSTBUFSIZE];
46 	FILE *hostf;
47 	int stayopen;
48 	struct __res_state *res;
49 #ifdef YP
50 	char *yp_domain;
51 #endif
52 };
53 
54 struct netent_data {
55 	char *net_aliases[_MAXALIASES];
56 	char netbuf[_NETBUFSIZE];
57 	FILE *netf;
58 	int stayopen;
59 #ifdef YP
60 	char *yp_domain;
61 #endif
62 };
63 
64 struct protoent_data {
65 	FILE *fp;
66 	char *aliases[_MAXALIASES];
67 	int stayopen;
68 	char line[_MAXLINELEN + 1];
69 };
70 
71 struct servent_data {
72 	FILE *fp;
73 	char *aliases[_MAXALIASES];
74 	int stayopen;
75 	char line[_MAXLINELEN + 1];
76 #ifdef YP
77 	int yp_stepping;
78 	char *yp_name;
79 	char *yp_proto;
80 	int yp_port;
81 	char *yp_domain;
82 	char *yp_key;
83 	int yp_keylen;
84 #endif
85 };
86 
87 struct hostdata {
88 	struct hostent host;
89 	struct hostent_data data;
90 };
91 
92 struct netdata {
93 	struct netent net;
94 	struct netent_data data;
95 };
96 
97 struct protodata {
98 	struct protoent proto;
99 	struct protoent_data data;
100 };
101 
102 struct servdata {
103 	struct servent serv;
104 	struct servent_data data;
105 };
106 
107 #define	endhostent_r		__endhostent_r
108 #define	endnetent_r		__endnetent_r
109 #define	endprotoent_r		__endprotoent_r
110 #define	endservent_r		__endservent_r
111 #define	gethostbyaddr_r		__gethostbyaddr_r
112 #define	gethostbyname_r		__gethostbyname_r
113 #define	gethostbyname2_r	__gethostbyname2_r
114 #define	gethostent_r		__gethostent_r
115 #define	getnetbyaddr_r		__getnetbyaddr_r
116 #define	getnetbyname_r		__getnetbyname_r
117 #define	getnetent_r		__getnetent_r
118 #define	getprotobyname_r	__getprotobyname_r
119 #define	getprotobynumber_r	__getprotobynumber_r
120 #define	getprotoent_r		__getprotoent_r
121 #define	getservbyname_r		__getservbyname_r
122 #define	getservbyport_r		__getservbyport_r
123 #define	getservent_r		__getservent_r
124 #define	sethostent_r		__sethostent_r
125 #define	setnetent_r		__setnetent_r
126 #define	setprotoent_r		__setprotoent_r
127 #define	setservent_r		__setservent_r
128 
129 struct hostdata *__hostdata_init(void);
130 struct netdata *__netdata_init(void);
131 struct protodata *__protodata_init(void);
132 struct servdata *__servdata_init(void);
133 void _endhostdnsent(void);
134 void _endhosthtent(struct hostent_data *);
135 void _endnetdnsent(void);
136 void _endnethtent(struct netent_data *);
137 struct hostent *_gethostbynisaddr(const char *, int, int);
138 struct hostent *_gethostbynisname(const char *, int);
139 void _map_v4v6_address(const char *, char *);
140 void _map_v4v6_hostent(struct hostent *, char **, char *);
141 void _sethostdnsent(int);
142 void _sethosthtent(int, struct hostent_data *);
143 void _setnetdnsent(int);
144 void _setnethtent(int, struct netent_data *);
145 void endhostent_r(struct hostent_data *);
146 void endnetent_r(struct netent_data *);
147 void endprotoent_r(struct protoent_data *);
148 void endservent_r(struct servent_data *);
149 int gethostbyaddr_r(const char *, int, int, struct hostent *,
150 	struct hostent_data *);
151 int gethostbyname_r(const char *, struct hostent *, struct hostent_data *);
152 int gethostbyname2_r(const char *, int, struct hostent *,
153 	struct hostent_data *);
154 int gethostent_r(struct hostent *, struct hostent_data *);
155 int getnetbyaddr_r(uint32_t addr, int af, struct netent *,
156 	struct netent_data *);
157 int getnetbyname_r(const char *, struct netent *, struct netent_data *);
158 int getnetent_r(struct netent *, struct netent_data *);
159 int getprotobyname_r(const char *, struct protoent *, struct protoent_data *);
160 int getprotobynumber_r(int, struct protoent *, struct protoent_data *);
161 int getprotoent_r(struct protoent *, struct protoent_data *);
162 int getservbyname_r(const char *, const char *, struct servent *,
163 	struct servent_data *);
164 int getservbyport_r(int, const char *, struct servent *,
165 	struct servent_data *);
166 int getservent_r(struct servent *, struct servent_data *);
167 void sethostent_r(int, struct hostent_data *);
168 void setnetent_r(int, struct netent_data *);
169 void setprotoent_r(int, struct protoent_data *);
170 void setservent_r(int, struct servent_data *);
171 
172 #endif /* _NETDB_PRIVATE_H_ */
173