/* $Id: resolv_conf_parser.h $ */ /** @file * resolv_conf_parser.h - interface to parser of resolv.conf resolver(5) */ /* * Copyright (C) 2014 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. */ #ifndef __RESOLV_CONF_PARSER_H__ #define __RESOLV_CONF_PARSER_H__ #include #include RT_C_DECLS_BEGIN #define RCPS_MAX_NAMESERVERS 3 #define RCPS_MAX_SEARCHLIST 10 #define RCPS_BUFFER_SIZE 256 #define RCPS_IPVX_SIZE 47 /** * In Slirp we don't need IPv6 for general case (only for dnsproxy mode * it's potentially acceptable) */ #define RCPSF_IGNORE_IPV6 RT_BIT(0) /** * In Main, we perhaps don't need parsed IPv6 and IPv4, because parsed values are * used in Network services. */ #define RCPSF_NO_STR2IPCONV RT_BIT(1) struct rcp_state { uint16_t rcps_port; /** * Filling of this array ommited iff RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set. */ RTNETADDR rcps_nameserver[RCPS_MAX_NAMESERVERS]; /** * this array contains non-NULL (pointing to rcp_state::rcps_nameserver_str_buffer) iff * RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set. */ char *rcps_str_nameserver[RCPS_MAX_NAMESERVERS]; unsigned rcps_num_nameserver; /** * Shortcuts to storage, note that domain is optional * and if it's missed in resolv.conf rcps_domain should be equal * to rcps_search_list[0] */ char *rcps_domain; char *rcps_searchlist[RCPS_MAX_SEARCHLIST]; unsigned rcps_num_searchlist; uint32_t rcps_flags; char rcps_domain_buffer[RCPS_BUFFER_SIZE]; char rcps_searchlist_buffer[RCPS_BUFFER_SIZE]; char rcps_nameserver_str_buffer[RCPS_MAX_NAMESERVERS * RCPS_IPVX_SIZE]; }; /** * This function parses specified file (expected to conform resolver (5) Mac OSX or resolv.conf (3) Linux) * and fills the structure. * @return 0 - on success * -1 - on fail. * * struct rcp_state state; * int rc; * * rc = rcp_parse(&state, "/etc/resolv.conf"); * for(i = 0; rc == 0 && i != state.rcps_num_nameserver; ++i) * { * if ((state.rcps_flags & RCPSF_NO_STR2IPCONV) == 0) * { * const RTNETADDR *addr = &state.rcps_nameserver[i]; * * switch (state.rcps_nameserver[i].enmType) * { * case RTNETADDRTYPE_IPV4: * RTPrintf("nameserver[%d]: [%RTnaipv4]:%d\n", i, addr->uAddr.IPv4, addr->uPort); * break; * case RTNETADDRTYPE_IPV6: * RTPrintf("nameserver[%d]: [%RTnaipv6]:%d\n", i, &addr->uAddr.IPv6, addr->uPort); * break; * default: * break; * } * } * else * RTPrintf("nameserver[%d]: %s\n", i, state.rcps_str_nameserver[i]); * } * * */ int rcp_parse(struct rcp_state *, const char *); RT_C_DECLS_END #endif