xref: /freebsd/lib/libcasper/services/cap_dns/cap_dns.h (revision 5c2bc3db201a4fe8d7911cf816bea104d5dc2138)
1c501d73cSMariusz Zaborski /*-
2c501d73cSMariusz Zaborski  * Copyright (c) 2012 The FreeBSD Foundation
3c501d73cSMariusz Zaborski  *
4c501d73cSMariusz Zaborski  * This software was developed by Pawel Jakub Dawidek under sponsorship from
5c501d73cSMariusz Zaborski  * the FreeBSD Foundation.
6c501d73cSMariusz Zaborski  *
7c501d73cSMariusz Zaborski  * Redistribution and use in source and binary forms, with or without
8c501d73cSMariusz Zaborski  * modification, are permitted provided that the following conditions
9c501d73cSMariusz Zaborski  * are met:
10c501d73cSMariusz Zaborski  * 1. Redistributions of source code must retain the above copyright
11c501d73cSMariusz Zaborski  *    notice, this list of conditions and the following disclaimer.
12c501d73cSMariusz Zaborski  * 2. Redistributions in binary form must reproduce the above copyright
13c501d73cSMariusz Zaborski  *    notice, this list of conditions and the following disclaimer in the
14c501d73cSMariusz Zaborski  *    documentation and/or other materials provided with the distribution.
15c501d73cSMariusz Zaborski  *
16c501d73cSMariusz Zaborski  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
17c501d73cSMariusz Zaborski  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c501d73cSMariusz Zaborski  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c501d73cSMariusz Zaborski  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
20c501d73cSMariusz Zaborski  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c501d73cSMariusz Zaborski  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c501d73cSMariusz Zaborski  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c501d73cSMariusz Zaborski  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c501d73cSMariusz Zaborski  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c501d73cSMariusz Zaborski  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c501d73cSMariusz Zaborski  * SUCH DAMAGE.
27c501d73cSMariusz Zaborski  */
28c501d73cSMariusz Zaborski 
29c501d73cSMariusz Zaborski #ifndef	_CAP_DNS_H_
30c501d73cSMariusz Zaborski #define	_CAP_DNS_H_
31c501d73cSMariusz Zaborski 
32ceb36bc9SMariusz Zaborski #ifdef HAVE_CASPER
33ceb36bc9SMariusz Zaborski #define WITH_CASPER
34ceb36bc9SMariusz Zaborski #endif
35ceb36bc9SMariusz Zaborski 
36b30c6ac9SConrad Meyer #include <sys/cdefs.h>
37c501d73cSMariusz Zaborski #include <sys/socket.h>	/* socklen_t */
38c501d73cSMariusz Zaborski 
39*388197f4SAdrian Chadd /*
40*388197f4SAdrian Chadd  * Pull these in if we're just inlining calls to the underlying
41*388197f4SAdrian Chadd  * libc functions.
42*388197f4SAdrian Chadd  */
43*388197f4SAdrian Chadd #ifndef	WITH_CASPER
44*388197f4SAdrian Chadd #include <sys/types.h>
45*388197f4SAdrian Chadd #include <netdb.h>
46*388197f4SAdrian Chadd #endif	/* WITH_CASPER */
47*388197f4SAdrian Chadd 
48c501d73cSMariusz Zaborski struct addrinfo;
49c501d73cSMariusz Zaborski struct hostent;
50c501d73cSMariusz Zaborski 
51ceb36bc9SMariusz Zaborski #ifdef WITH_CASPER
52b30c6ac9SConrad Meyer __BEGIN_DECLS
53b30c6ac9SConrad Meyer 
54c501d73cSMariusz Zaborski struct hostent *cap_gethostbyname(cap_channel_t *chan, const char *name);
55c501d73cSMariusz Zaborski struct hostent *cap_gethostbyname2(cap_channel_t *chan, const char *name,
56c501d73cSMariusz Zaborski     int type);
57c501d73cSMariusz Zaborski struct hostent *cap_gethostbyaddr(cap_channel_t *chan, const void *addr,
58c501d73cSMariusz Zaborski     socklen_t len, int type);
59c501d73cSMariusz Zaborski 
60c501d73cSMariusz Zaborski int cap_getaddrinfo(cap_channel_t *chan, const char *hostname,
61c501d73cSMariusz Zaborski     const char *servname, const struct addrinfo *hints, struct addrinfo **res);
62c501d73cSMariusz Zaborski int cap_getnameinfo(cap_channel_t *chan, const struct sockaddr *sa,
63c501d73cSMariusz Zaborski     socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen,
64c501d73cSMariusz Zaborski     int flags);
65c501d73cSMariusz Zaborski 
66c501d73cSMariusz Zaborski int cap_dns_type_limit(cap_channel_t *chan, const char * const *types,
67c501d73cSMariusz Zaborski     size_t ntypes);
68c501d73cSMariusz Zaborski int cap_dns_family_limit(cap_channel_t *chan, const int *families,
69c501d73cSMariusz Zaborski     size_t nfamilies);
70b30c6ac9SConrad Meyer 
71b30c6ac9SConrad Meyer __END_DECLS
72ceb36bc9SMariusz Zaborski #else
73ceb36bc9SMariusz Zaborski 
74*388197f4SAdrian Chadd static inline struct hostent *
75*388197f4SAdrian Chadd cap_gethostbyname(cap_channel_t *chan __unused, const char *name)
76*388197f4SAdrian Chadd {
77ceb36bc9SMariusz Zaborski 
78*388197f4SAdrian Chadd 	return (gethostbyname(name));
79*388197f4SAdrian Chadd }
80*388197f4SAdrian Chadd 
81*388197f4SAdrian Chadd static inline struct hostent *
82*388197f4SAdrian Chadd cap_gethostbyname2(cap_channel_t *chan __unused, const char *name, int type)
83*388197f4SAdrian Chadd {
84*388197f4SAdrian Chadd 
85*388197f4SAdrian Chadd 	return (gethostbyname2(name, type));
86*388197f4SAdrian Chadd }
87*388197f4SAdrian Chadd 
88*388197f4SAdrian Chadd static inline struct hostent *
89*388197f4SAdrian Chadd cap_gethostbyaddr(cap_channel_t *chan __unused, const void *addr,
90*388197f4SAdrian Chadd     socklen_t len, int type)
91*388197f4SAdrian Chadd {
92*388197f4SAdrian Chadd 
93*388197f4SAdrian Chadd 	return (gethostbyaddr(addr, len, type));
94*388197f4SAdrian Chadd }
95*388197f4SAdrian Chadd 
96*388197f4SAdrian Chadd static inline int cap_getaddrinfo(cap_channel_t *chan __unused,
97*388197f4SAdrian Chadd     const char *hostname, const char *servname, const struct addrinfo *hints,
98*388197f4SAdrian Chadd     struct addrinfo **res)
99*388197f4SAdrian Chadd {
100*388197f4SAdrian Chadd 
101*388197f4SAdrian Chadd 	return (getaddrinfo(hostname, servname, hints, res));
102*388197f4SAdrian Chadd }
103*388197f4SAdrian Chadd 
104*388197f4SAdrian Chadd static inline int cap_getnameinfo(cap_channel_t *chan __unused,
105*388197f4SAdrian Chadd     const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen,
106*388197f4SAdrian Chadd     char *serv, size_t servlen, int flags)
107*388197f4SAdrian Chadd {
108*388197f4SAdrian Chadd 
109*388197f4SAdrian Chadd 	return (getnameinfo(sa, salen, host, hostlen, serv, servlen, flags));
110*388197f4SAdrian Chadd }
111*388197f4SAdrian Chadd 
112*388197f4SAdrian Chadd static inline int
113*388197f4SAdrian Chadd cap_dns_type_limit(cap_channel_t *chan __unused,
114*388197f4SAdrian Chadd     const char * const *types __unused,
115*388197f4SAdrian Chadd     size_t ntypes __unused)
116*388197f4SAdrian Chadd {
117*388197f4SAdrian Chadd 
118*388197f4SAdrian Chadd 	return (0);
119*388197f4SAdrian Chadd }
120*388197f4SAdrian Chadd 
121*388197f4SAdrian Chadd static inline int
122*388197f4SAdrian Chadd cap_dns_family_limit(cap_channel_t *chan __unused,
123*388197f4SAdrian Chadd     const int *families __unused,
124*388197f4SAdrian Chadd     size_t nfamilies __unused)
125*388197f4SAdrian Chadd {
126*388197f4SAdrian Chadd 
127*388197f4SAdrian Chadd 	return (0);
128*388197f4SAdrian Chadd }
129*388197f4SAdrian Chadd #endif	/* WITH_CASPER */
130c501d73cSMariusz Zaborski 
131c501d73cSMariusz Zaborski #endif	/* !_CAP_DNS_H_ */
132