1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 2001 by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <stdio.h> 30 #include <stdlib.h> 31 #include <alloca.h> 32 #include <string.h> 33 #include <errno.h> 34 #include <dhcp_svc_confopt.h> 35 36 int 37 main(void) 38 { 39 int i; 40 dhcp_confopt_t *dsp; 41 42 if (read_dsvc_conf(&dsp) < 0) { 43 if (errno != ENOENT) { 44 perror("Read failed"); 45 return (1); 46 } else { 47 (void) fprintf(stderr, 48 "Read failed because file does not exist\n"); 49 /* 50 * Make one. 51 */ 52 dsp = alloca(4 * sizeof (dhcp_confopt_t)); 53 dsp[0].co_type = DHCP_COMMENT; 54 dsp[0].co_comment = " Generated by test_confopt"; 55 dsp[1].co_type = DHCP_KEY; 56 dsp[1].co_key = "RESOURCE"; 57 dsp[1].co_value = "files"; 58 dsp[2].co_type = DHCP_KEY; 59 dsp[2].co_key = "PATH"; 60 dsp[2].co_value = "/var/dhcp"; 61 dsp[3].co_type = DHCP_END; 62 } 63 } else { 64 (void) printf("Read worked\n"); 65 66 for (i = 0; dsp[i].co_type != DHCP_END; i++) { 67 if (dsp[i].co_type == DHCP_KEY) { 68 (void) printf("Key: %s, Value: %s\n", 69 dsp[i].co_key, dsp[i].co_value); 70 if (strcmp(dsp[i].co_key, "RESOURCE") == 0) { 71 free(dsp[i].co_value); 72 dsp[i].co_value = strdup("nisplus"); 73 } 74 } else { 75 (void) printf("Comment: %s\n", 76 dsp[i].co_comment); 77 } 78 } 79 } 80 81 if (write_dsvc_conf(dsp, 0644) < 0) { 82 perror("Write failed"); 83 return (1); 84 } else 85 (void) printf("Write worked\n"); 86 87 free_dsvc_conf(dsp); 88 return (0); 89 }