lwconfig.c revision ae6860081ff6cd3c1ec8329c4deb2d0da4802116
499b34cea04a46823d003d4c0520c8b03e8513cbBrian Wellington * Copyright (C) 2000, 2001 Internet Software Consortium.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
33f87146a856eb6c3dfd55a8ee9c173c94f82150Andreas Gustafsson/* $Id: lwconfig.c,v 1.32 2001/04/12 22:45:12 tale Exp $ */
d25afd60ee2286cb171c4960a790f3d7041b6f85Bob Halley *** Module for parsing resolv.conf files.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence *** entry points are:
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrews *** lwres_conf_init(lwres_context_t *ctx)
1a69a1a78cfaa86f3b68bbc965232b7876d4da2aDavid Lawrence *** intializes data structure for subsequent config parsing.
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence *** lwres_conf_parse(lwres_context_t *ctx, const char *filename)
6e3a8256eed85f6704861d269ccfb35bdaeed5ffDavid Lawrence *** parses a file and fills in the data structure.
33f87146a856eb6c3dfd55a8ee9c173c94f82150Andreas Gustafsson *** lwres_conf_print(lwres_context_t *ctx, FILE *fp)
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews *** prints the config data structure to the FILE.
94e25967cda41b886e33ec254b917d21df21a187Bob Halley *** lwres_conf_clear(lwres_context_t *ctx)
364a82f7c25b62967678027043425201a5e5171aBob Halley *** frees up all the internal memory used by the config data
94e25967cda41b886e33ec254b917d21df21a187Bob Halley *** structure, returning it to the lwres_context_t.
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewslwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewslwres_conf_parselwserver(lwres_context_t *ctx, FILE *fp);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewslwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewslwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp);
70ec7dd74103fa9e92a6d56a0e3b0fc30e17af0dMark Andrewslwres_conf_parsesortlist(lwres_context_t *ctx, FILE *fp);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleylwres_conf_parseoption(lwres_context_t *ctx, FILE *fp);
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halleylwres_create_addr(const char *buff, lwres_addr_t *addr, int convert_zero);
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence * Eat characters from FP until EOL or EOF. Returns EOF or '\n'
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * Eats white space up to next newline or non-whitespace character (of
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley * EOF). Returns the last character read. Comments are considered white
4bed2e84a34b37259b85e5c092d51c122ef58c3cBob Halley while (ch != '\n' && ch != EOF && isspace((unsigned char)ch))
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * Skip over any leading whitespace and then read in the next sequence of
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews * non-whitespace characters. In this context newline is not considered
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrews * whitespace. Returns EOF on end-of-file, or the character
94e25967cda41b886e33ec254b917d21df21a187Bob Halley * that caused the reading to stop.
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencegetword(FILE *fp, char *buffer, size_t size) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence *p++ = (char)ch;
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halleystatic char *
4b87939256ede703385e9cab92d3c58d03c31098Mark Andrewslwres_strdup(lwres_context_t *ctx, const char *str) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence for (i = 0 ; i < LWRES_CONFMAXNAMESERVERS ; i++)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++)
afdb3abb9b06ed4070ac9021f1f4427b4cb3a286Bob Halley for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence for (i = 0 ; i < LWRES_CONFMAXSORTLIST ; i++) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence lwres_resetaddr(&confdata->sortlist[i].addr);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence lwres_resetaddr(&confdata->sortlist[i].mask);
3740b569ae76295b941d57a724a43beb75b533baBob Halleylwres_conf_parsenameserver(lwres_context_t *ctx, FILE *fp) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence if (confdata->nsnext == LWRES_CONFMAXNAMESERVERS)
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return (LWRES_R_FAILURE); /* Extra junk on line. */
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence &confdata->nameservers[confdata->nsnext++], 1);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencelwres_conf_parselwserver(lwres_context_t *ctx, FILE *fp) {
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence if (confdata->lwnext == LWRES_CONFMAXLWSERVERS)
4ad9b25e6ddf948ffb3b8198c5540d251f26c52eDavid Lawrence return (LWRES_R_FAILURE); /* Nothing on line. */
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence return (LWRES_R_FAILURE); /* Extra junk on line. */
585529aaeb95a71cd3d95df2602a4688fc7c3292David Lawrence &confdata->lwservers[confdata->lwnext++], 1);
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrencelwres_conf_parsedomain(lwres_context_t *ctx, FILE *fp) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return (LWRES_R_FAILURE); /* Nothing else on line. */
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence return (LWRES_R_FAILURE); /* Extra junk on line. */
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence * Search and domain are mutually exclusive.
826c281a05cb89c9c28621937dc83fa676a5b207David Lawrence for (i = 0 ; i < LWRES_CONFMAXSEARCH ; i++) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence confdata->domainname = lwres_strdup(ctx, word);
604a596b5f97f09f6a4de67fe2f076d3c939df33David Lawrencelwres_conf_parsesearch(lwres_context_t *ctx, FILE *fp) {
6fa1cb5754695d550a58c6e8978fda65f5146af7David Lawrence * Search and domain are mutually exclusive.
114d0d1642b5ede0ab154532159fe38c30762d82David Lawrence * Remove any previous search definitions.
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson for (idx = 0 ; idx < LWRES_CONFMAXSEARCH ; idx++) {
c8563aaf86c04f0e2284bcc8e444a0651c157ea0Andreas Gustafsson return (LWRES_R_FAILURE); /* Nothing else on line. */
idx = 0;
return (LWRES_R_FAILURE);
idx++;
return (LWRES_R_SUCCESS);
static lwres_result_t
if (convert_zero) {
unsigned char zeroaddress[] = {0, 0, 0, 0};
return (LWRES_R_SUCCESS);
static lwres_result_t
if (p != NULL)
return (res);
if (p != NULL) {
return (res);
return (LWRES_R_SUCCESS);
static lwres_result_t
int delim;
long ndots;
return (LWRES_R_FAILURE);
return (LWRES_R_FAILURE);
return (LWRES_R_SUCCESS);
int stopchar;
errno = 0;
return (LWRES_R_FAILURE);
return (ret);
int af;
if (p != tmp)
return (LWRES_R_FAILURE);
if (p != tmp)
return (LWRES_R_FAILURE);
if (p != tmp)
return (LWRES_R_FAILURE);
p = lwres_net_ntop
(af,
if (p != tmp)
return (LWRES_R_FAILURE);
return (LWRES_R_SUCCESS);