8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / common / compat.c
blobec055db9109f2760406c59b013c7a1d2cca38b71
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <deflt.h>
30 #include <string.h>
31 #include <stddef.h>
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <compat.h>
36 #define DEFAULT_IP_LINE DEFAULT_IP"="
39 * Code to handle /etc/default/ file for IPv4 command output compatibility
41 * Note: Handles BOTH the same as IP_VERSION6.
43 * Returns 1 if IP_VERSION4; 0 for other versions.
44 * Returns -1 if the value of DEFAULT_IP found in /etc/default/inet_type is
45 * invalid.
47 int
48 get_compat_flag(char **value)
50 if (defopen(INET_DEFAULT_FILE) == 0) {
51 char *cp;
52 int flags;
55 * ignore case
57 flags = defcntl(DC_GETFLAGS, 0);
58 TURNOFF(flags, DC_CASE);
59 (void) defcntl(DC_SETFLAGS, flags);
61 if (cp = defread(DEFAULT_IP_LINE))
62 *value = strdup(cp);
64 /* close */
65 (void) defopen((char *)NULL);
67 if (*value != NULL) {
68 if (strcasecmp(*value, "IP_VERSION4") == 0) {
69 return (DEFAULT_PROT_V4_ONLY);
70 } else if (strcasecmp(*value, "BOTH") == 0 ||
71 strcasecmp(*value, "IP_VERSION6") == 0) {
72 return (DEFAULT_PROT_BOTH);
73 } else {
74 return (DEFAULT_PROT_BAD_VALUE);
78 /* No value set */
79 return (DEFAULT_PROT_BOTH);