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