/* $Id$ */
/** @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;
* 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__
/**
* RESOLV_CONF_FILE can be defined in external tests for verification of Slirp behaviour.
*/
#ifndef RESOLV_CONF_FILE
# ifndef RT_OS_OS2
# else
# define RESOLV_CONF_FILE "\\MPTN\\ETC\\RESOLV2"
# endif
#endif
/**
* In Slirp we don't need IPv6 for general case (only for dnsproxy mode
* it's potentially acceptable)
*/
/**
* In Main, we perhaps don't need parsed IPv6 and IPv4, because parsed values are
* used in Network services.
*/
struct rcp_state
{
/**
* Filling of this array ommited iff RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set.
*/
/**
* this array contains non-NULL (pointing to rcp_state::rcps_nameserver_str_buffer) iff
* RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set.
*/
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;
unsigned rcps_num_searchlist;
};
/**
* 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.
* <code>
* 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]);
* }
* </code>
*
*/
#endif