VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/resolv_conf_parser.h@ 50088

Last change on this file since 50088 was 50088, checked in by vboxsync, 11 years ago

Introduces resolv.conf parser replacement for Slirp and Main.

resolv_conf_parser.c - parser.
resolv_conf_parser.h - interface to parser.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: resolv_conf_parser.h 50088 2014-01-17 11:02:16Z vboxsync $ */
2/** @file
3 * resolv_conf_parser.h - interface to parser of resolv.conf resolver(5)
4 */
5
6/*
7 * Copyright (C) 2014 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef __RESOLV_CONF_PARSER_H__
19#define __RESOLV_CONF_PARSER_H__
20
21#include <iprt/cdefs.h>
22#include <iprt/net.h>
23
24RT_C_DECLS_BEGIN
25
26#define RCPS_MAX_NAMESERVERS 3
27#define RCPS_MAX_SEARCHLIST 10
28#define RCPS_BUFFER_SIZE 256
29#define RCPS_IPVX_SIZE 47
30/**
31 * In Slirp we don't need IPv6 for general case (only for dnsproxy mode
32 * it's potentially acceptable)
33 */
34#define RCPSF_IGNORE_IPV6 RT_BIT(0)
35/**
36 * In Main, we perhaps don't need parsed IPv6 and IPv4, because parsed values are
37 * used in Network services.
38 */
39#define RCPSF_NO_STR2IPCONV RT_BIT(1)
40
41struct rcp_state
42{
43 uint16_t rcps_port;
44 /**
45 * Filling of this array ommited iff RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set.
46 */
47 RTNETADDR rcps_nameserver[RCPS_MAX_NAMESERVERS];
48 /**
49 * this array contains non-NULL (pointing to rcp_state::rcps_nameserver_str_buffer) iff
50 * RCPSF_NO_STR2IPCONF in rcp_state::rcps_flags set.
51 */
52 char *rcps_str_nameserver[RCPS_MAX_NAMESERVERS];
53 unsigned rcps_num_nameserver;
54 /**
55 * Shortcuts to storage, note that domain is optional
56 * and if it's missed in resolv.conf rcps_domain should be equal
57 * to rcps_search_list[0]
58 */
59 char *rcps_domain;
60 char *rcps_searchlist[RCPS_MAX_SEARCHLIST];
61 unsigned rcps_num_searchlist;
62
63 uint32_t rcps_flags;
64
65 char rcps_domain_buffer[RCPS_BUFFER_SIZE];
66 char rcps_searchlist_buffer[RCPS_BUFFER_SIZE];
67 char rcps_nameserver_str_buffer[RCPS_MAX_NAMESERVERS * RCPS_IPVX_SIZE];
68};
69
70
71/**
72 * This function parses specified file (expected to conform resolver (5) Mac OSX or resolv.conf (3) Linux)
73 * and fills the structure.
74 * @return 0 - on success
75 * -1 - on fail.
76 * <code>
77 * struct rcp_state state;
78 * int rc;
79 *
80 * rc = rcp_parse(&state, "/etc/resolv.conf");
81 * for(i = 0; rc == 0 && i != state.rcps_num_nameserver; ++i)
82 * {
83 * if ((state.rcps_flags & RCPSF_NO_STR2IPCONV) == 0)
84 * {
85 * const RTNETADDR *addr = &state.rcps_nameserver[i];
86 *
87 * switch (state.rcps_nameserver[i].enmType)
88 * {
89 * case RTNETADDRTYPE_IPV4:
90 * RTPrintf("nameserver[%d]: [%RTnaipv4]:%d\n", i, addr->uAddr.IPv4, addr->uPort);
91 * break;
92 * case RTNETADDRTYPE_IPV6:
93 * RTPrintf("nameserver[%d]: [%RTnaipv6]:%d\n", i, &addr->uAddr.IPv6, addr->uPort);
94 * break;
95 * default:
96 * break;
97 * }
98 * }
99 * else
100 * RTPrintf("nameserver[%d]: %s\n", i, state.rcps_str_nameserver[i]);
101 * }
102 * </code>
103 *
104 */
105int rcp_parse(struct rcp_state *, const char *);
106
107RT_C_DECLS_END
108
109#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette