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
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]
23 * Copyright (c) 1991-1996,2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
37 #define MAXLINELEN 4096
42 * Reads input from file. The file is structured as
43 * <fam> <type> <protocol> <path>
44 * <fam> <type> <protocol>
45 * with the first line registering and the second line
48 * soconfig <fam> <type> <protocol> <path>
51 * soconfig <fam> <type> <protocol>
55 static int parse_file(char *filename
);
57 static int split_line(char *line
, char *argvec
[], int maxargvec
);
59 static int parse_params(char *famstr
, char *typestr
, char *protostr
,
60 char *path
, int line
);
62 static int parse_int(char *str
);
64 static void usage(void);
75 (void) setlocale(LC_ALL
, "");
76 #if !defined(TEXT_DOMAIN)
77 #define TEXT_DOMAIN "SYS_TEST"
79 (void) textdomain(TEXT_DOMAIN
);
81 if (argc
== 2 && strcmp(argv
[0], "-f") == 0) {
82 ret
= parse_file(argv
[1]);
86 ret
= parse_params(argv
[0], argv
[1], argv
[2], NULL
, -1);
90 ret
= parse_params(argv
[0], argv
[1], argv
[2], argv
[3], -1);
101 fprintf(stderr
, gettext(
102 "Usage: soconfig -f <file>\n"
103 "\tsoconfig <fam> <type> <protocol> <path>\n"
104 "\tsoconfig <fam> <type> <protocol>\n"));
108 * Open the specified file and parse each line. Skip comments (everything
109 * after a '#'). Return 1 if at least one error was encountered; otherwise 0.
112 parse_file(char *filename
)
114 char line
[MAXLINELEN
];
115 char pline
[MAXLINELEN
];
122 fp
= fopen(filename
, "r");
124 perror("soconfig: open");
125 fprintf(stderr
, "\n");
130 while (fgets(line
, sizeof (line
) - 1, fp
) != NULL
) {
133 argcount
= split_line(pline
, argvec
,
134 sizeof (argvec
) / sizeof (argvec
[0]));
139 printf("scanned %d args\n", argcount
);
140 for (i
= 0; i
< argcount
; i
++)
141 printf("arg[%d]: %s\n", i
, argvec
[i
]);
146 /* Empty line - or comment only line */
149 numerror
+= parse_params(argvec
[0], argvec
[1],
150 argvec
[2], NULL
, linecount
);
153 numerror
+= parse_params(argvec
[0], argvec
[1],
154 argvec
[2], argvec
[3], linecount
);
159 gettext("Malformed line: <%s>\n"), line
);
161 gettext("\ton line %d\n"), linecount
);
174 * Parse a line splitting it off at whitspace characters.
175 * Modifies the content of the string by inserting NULLs.
178 split_line(char *line
, char *argvec
[], int maxargvec
)
183 /* Truncate at the beginning of a comment */
184 cp
= strchr(line
, '#');
190 /* Skip any whitespace */
191 while (isspace(*line
) && *line
!= NULL
)
201 /* Skip until next whitespace */
202 while (!isspace(*line
) && *line
!= NULL
)
205 /* Break off argument */
213 * Parse the set of parameters and issues the sockconfig syscall.
214 * If line is not -1 it is assumed to be the line number in the file.
217 parse_params(char *famstr
, char *typestr
, char *protostr
, char *path
, int line
)
219 int fam
, type
, protocol
;
221 fam
= parse_int(famstr
);
223 fprintf(stderr
, gettext("Bad family number: %s\n"), famstr
);
226 gettext("\ton line %d\n"), line
);
228 fprintf(stderr
, "\n");
234 type
= parse_int(typestr
);
237 gettext("Bad socket type number: %s\n"), typestr
);
240 gettext("\ton line %d\n"), line
);
242 fprintf(stderr
, "\n");
248 protocol
= parse_int(protostr
);
249 if (protocol
== -1) {
251 gettext("Bad protocol number: %s\n"), protostr
);
254 gettext("\ton line %d\n"), line
);
256 fprintf(stderr
, "\n");
266 if (stat(path
, &stats
) == -1) {
270 gettext("\ton line %d\n"), line
);
272 fprintf(stderr
, "\n");
280 printf("not calling sockconfig(%d, %d, %d, %s)\n",
281 fam
, type
, protocol
, path
== NULL
? "(null)" : path
);
283 if (_sockconfig(fam
, type
, protocol
, path
) == -1) {
284 perror("sockconfig");
297 res
= strtol(str
, &end
, 0);