2 * $FreeBSD: src/release/sysinstall/dhcp.c,v 1.3.4.1 2001/09/16 23:05:50 murray Exp $
3 * $DragonFly: src/release/sysinstall/Attic/dhcp.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
6 * C. Stone. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer,
13 * verbatim and that no modifications are made prior to this
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY C. STONE ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL C STONE OR HIS BODILY PARASITES BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, LIFE OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE BY THE VOICES IN YOUR HEAD BEFOREHAND.
33 #include "sysinstall.h"
38 dhcpParseLeases(char *file, char *hostname, char *domain, char *nameserver,
39 char *ipaddr, char *gateway, char *netmask)
42 char optbuf[1024], *optname = NULL;
47 enum { P_NOSTMT, P_NOSTMT1, P_STMT, P_STMTLINE } state;
49 if ((fp = fopen(file, "r")) == NULL) {
50 msgDebug("error opening file %s: %s\n", file, strerror(errno));
55 while (fscanf(fp, "%1023s", tempbuf) > 0) {
59 if (!strncasecmp(tempbuf, "lease", 5)) {
70 if (tempbuf[0] != '{') {
71 msgWarn("dhcpParseLeases: '{' expected");
79 if (!strncasecmp("option", tempbuf, 6))
81 if (tempbuf[0] == '}') {
88 if (tempbuf[0] == ';') { /* play it safe */
92 if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
96 if (!isalnum(tempbuf[0])) {
97 msgWarn("dhcpParseLeases: bad option");
103 optname = strdup(tempbuf);
113 if (tempbuf[0] == ';') {
117 if ((tptr = (char *)strchr(tempbuf, ';')) && (*(tptr + 1) == 0)) {
121 if (tempbuf[0] == '"') {
122 if (sscanf(tempbuf, "\"%[^\" ]\"", optbuf) < 1) {
123 msgWarn("dhcpParseLeases: bad option value");
129 strcpy(optbuf, tempbuf);
131 if (!strcasecmp("host-name", optname)) {
132 strcpy(hostname, optbuf);
133 } else if (!strcasecmp("domain-name", optname)) {
134 strcpy(domain, optbuf);
135 } else if (!strcasecmp("fixed-address", optname)) {
136 strcpy(ipaddr, optbuf);
137 } else if (!strcasecmp("routers", optname)) {
138 if((tptr = (char *)strchr(optbuf, ',')))
140 strcpy(gateway, optbuf);
141 } else if (!strcasecmp("subnet-mask", optname)) {
142 strcpy(netmask, optbuf);
143 } else if (!strcasecmp("domain-name-servers", optname)) {
144 /* <jkh> ...one value per property */
145 if((tptr = (char *)strchr(optbuf, ',')))
147 strcpy(nameserver, optbuf);