soconfig.c revision 0f1702c5201310f0529cd5abb77652e5e9b241b6
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <locale.h>
#define MAXLINELEN 4096
/*
* Usage:
* sonconfig -f <file>
* Reads input from file. The file is structured as
* <fam> <type> <protocol> <path|module>
* <fam> <type> <protocol>
* with the first line registering and the second line
* deregistering.
*
* soconfig <fam> <type> <protocol> <path|module>
* registers
*
* soconfig <fam> <type> <protocol>
* deregisters
*/
static int parse_file(char *filename);
static void usage(void);
int
int argc;
char *argv[];
{
int ret;
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
}
if (argc == 3) {
}
if (argc == 4) {
}
usage();
exit(1);
/* NOTREACHED */
}
static void
usage(void)
{
"Usage: soconfig -f <file>\n"
"\tsoconfig <fam> <type> <protocol> <path|module>\n"
"\tsoconfig <fam> <type> <protocol>\n"));
}
/*
* Open the specified file and parse each line. Skip comments (everything
* after a '#'). Return 1 if at least one error was encountered; otherwise 0.
*/
static int
parse_file(char *filename)
{
char line[MAXLINELEN];
char pline[MAXLINELEN];
int argcount;
char *argvec[20];
int linecount = 0;
int numerror = 0;
perror("soconfig: open");
usage();
return (1);
}
linecount++;
#ifdef DEBUG
{
int i;
for (i = 0; i < argcount; i++)
}
#endif /* DEBUG */
switch (argcount) {
case 0:
/* Empty line - or comment only line */
break;
case 3:
break;
case 4:
break;
default:
numerror++;
break;
}
}
if (numerror > 0)
return (1);
else
return (0);
}
/*
* Parse a line splitting it off at whitspace characters.
* Modifies the content of the string by inserting NULLs.
*/
static int
{
int i = 0;
char *cp;
/* Truncate at the beginning of a comment */
/* CONSTCOND */
while (1) {
/* Skip any whitespace */
line++;
if (i >= maxargvec)
return (i);
return (i);
i++;
/* Skip until next whitespace */
line++;
/* Break off argument */
}
}
/* NOTREACHED */
}
/*
* Parse the set of parameters and issues the sockconfig syscall.
* If line is not -1 it is assumed to be the line number in the file.
*/
static int
{
if (fam == -1) {
if (line != -1)
else {
usage();
}
return (1);
}
if (type == -1) {
if (line != -1)
else {
usage();
}
return (1);
}
if (protocol == -1) {
if (line != -1)
else {
usage();
}
return (1);
}
if (line != -1)
else {
usage();
}
return (1);
}
}
#ifdef DEBUG
printf("not calling sockconfig(%d, %d, %d, %s)\n",
#else
perror("sockconfig");
return (1);
}
#endif
return (0);
}
static int
{
char *end;
int res;
return (-1);
return (res);
}