1 /* 2 * Copyright 2012 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Paweł Dziepak, pdziepak@quarnos.org 7 */ 8 #ifndef DNS_RESOLVER_H 9 #define DNS_RESOLVER_H 10 11 12 #include <netdb.h> 13 #include <stdlib.h> 14 15 #include <module.h> 16 17 18 #define DNS_RESOLVER_MODULE_NAME "network/dns_resolver/v1" 19 20 21 struct dns_resolver_module { 22 module_info module; 23 status_t (*getaddrinfo)(const char* node, const char* service, 24 const struct addrinfo* hints, struct addrinfo** res); 25 }; 26 27 28 static inline int 29 kgetaddrinfo(const char* node, const char* service, 30 const struct addrinfo* hints, struct addrinfo** res) 31 { 32 dns_resolver_module* dns; 33 status_t result = get_module(DNS_RESOLVER_MODULE_NAME, 34 reinterpret_cast<module_info**>(&dns)); 35 if (result != B_OK) 36 return result; 37 38 result = dns->getaddrinfo(node, service, hints, res); 39 40 put_module(DNS_RESOLVER_MODULE_NAME); 41 42 return result; 43 } 44 45 46 static inline void 47 kfreeaddrinfo(struct addrinfo* res) 48 { 49 free(res); 50 } 51 52 53 #define getaddrinfo kgetaddrinfo 54 #define freeaddrinfo kfreeaddrinfo 55 56 57 #endif // DNS_RESOLVER_H 58 59