174e20cfeSnh145002 /*
274e20cfeSnh145002 * CDDL HEADER START
374e20cfeSnh145002 *
474e20cfeSnh145002 * The contents of this file are subject to the terms of the
574e20cfeSnh145002 * Common Development and Distribution License (the "License").
674e20cfeSnh145002 * You may not use this file except in compliance with the License.
774e20cfeSnh145002 *
874e20cfeSnh145002 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
974e20cfeSnh145002 * or http://www.opensolaris.org/os/licensing.
1074e20cfeSnh145002 * See the License for the specific language governing permissions
1174e20cfeSnh145002 * and limitations under the License.
1274e20cfeSnh145002 *
1374e20cfeSnh145002 * When distributing Covered Code, include this CDDL HEADER in each
1474e20cfeSnh145002 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1574e20cfeSnh145002 * If applicable, add the following below this CDDL HEADER, with the
1674e20cfeSnh145002 * fields enclosed by brackets "[]" replaced with your own identifying
1774e20cfeSnh145002 * information: Portions Copyright [yyyy] [name of copyright owner]
1874e20cfeSnh145002 *
1974e20cfeSnh145002 * CDDL HEADER END
2074e20cfeSnh145002 */
2174e20cfeSnh145002 /*
2274e20cfeSnh145002 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2374e20cfeSnh145002 * Use is subject to license terms.
2474e20cfeSnh145002 */
2574e20cfeSnh145002
2674e20cfeSnh145002 #pragma ident "%Z%%M% %I% %E% SMI"
2774e20cfeSnh145002
2874e20cfeSnh145002 #include <stdio.h>
2974e20cfeSnh145002 #include <libintl.h>
3074e20cfeSnh145002 #include <stdlib.h>
3174e20cfeSnh145002 #include <errno.h>
3274e20cfeSnh145002 #include <locale.h>
3374e20cfeSnh145002 #include <unistd.h>
3474e20cfeSnh145002 #include <strings.h>
3574e20cfeSnh145002 #include <fcntl.h>
3674e20cfeSnh145002 #include <stropts.h>
3774e20cfeSnh145002
3874e20cfeSnh145002 #include <sys/types.h>
3974e20cfeSnh145002 #include <sys/socket.h>
4074e20cfeSnh145002 #include <sys/sockio.h>
4174e20cfeSnh145002
4274e20cfeSnh145002 #define E_SUCCESS 0 /* Exit status for success */
4374e20cfeSnh145002 #define E_ERROR 1 /* Exit status for error */
4474e20cfeSnh145002 #define E_USAGE 2 /* Exit status for usage error */
4574e20cfeSnh145002
4674e20cfeSnh145002 static const char USAGE[] = "Usage:\tsdpadm\tstatus\n\t\tenable\n\t\tdisable\n";
4774e20cfeSnh145002 static const char OPTS[] = "?";
4874e20cfeSnh145002
4974e20cfeSnh145002 static const char FILEENTRY[] = "sysenable=%d\n";
5074e20cfeSnh145002 static const char FILENAME[] = "/etc/sdp.conf";
5174e20cfeSnh145002 static const char dcname[] = "/dev/sdp";
5274e20cfeSnh145002
5374e20cfeSnh145002 static char conf_header[] =
5474e20cfeSnh145002 "#\n"
5574e20cfeSnh145002 "# CDDL HEADER START\n"
5674e20cfeSnh145002 "#\n"
5774e20cfeSnh145002 "# The contents of this file are subject to the terms of the\n"
5874e20cfeSnh145002 "# Common Development and Distribution License (the \"License\").\n"
5974e20cfeSnh145002 "# You may not use this file except in compliance with the License.\n"
6074e20cfeSnh145002 "#\n"
6174e20cfeSnh145002 "# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE\n"
6274e20cfeSnh145002 "# or http://www.opensolaris.org/os/licensing.\n"
6374e20cfeSnh145002 "# See the License for the specific language governing permissions\n"
6474e20cfeSnh145002 "# and limitations under the License.\n"
6574e20cfeSnh145002 "#\n"
6674e20cfeSnh145002 "# When distributing Covered Code, include this CDDL HEADER in each\n"
6774e20cfeSnh145002 "# file and include the License file at usr/src/OPENSOLARIS.LICENSE.\n"
6874e20cfeSnh145002 "# If applicable, add the following below this CDDL HEADER, with the\n"
6974e20cfeSnh145002 "# fields enclosed by brackets \"[]\" replaced with your own identifying\n"
7074e20cfeSnh145002 "# information: Portions Copyright [yyyy] [name of copyright owner]\n"
7174e20cfeSnh145002 "#\n"
7274e20cfeSnh145002 "# CDDL HEADER END\n"
7374e20cfeSnh145002 "#\n"
7474e20cfeSnh145002 "#\n"
7574e20cfeSnh145002 "# ident \"@(#)sdp.conf 1.1 07/01/03 SMI\"\n"
7674e20cfeSnh145002 "#\n"
7774e20cfeSnh145002 "# Copyright 2007 Sun Microsystems, Inc. All rights reserved.\n"
7874e20cfeSnh145002 "# Use is subject to license terms.\n"
7974e20cfeSnh145002 "#\n\n";
8074e20cfeSnh145002
8174e20cfeSnh145002 static void
usage()8274e20cfeSnh145002 usage()
8374e20cfeSnh145002 {
8474e20cfeSnh145002 (void) fprintf(stderr, gettext(USAGE));
8574e20cfeSnh145002 exit(E_USAGE);
8674e20cfeSnh145002 }
8774e20cfeSnh145002
8874e20cfeSnh145002 int
main(int argc,char * argv[])8974e20cfeSnh145002 main(int argc, char *argv[])
9074e20cfeSnh145002 {
9174e20cfeSnh145002 int c, enable, ret = E_SUCCESS;
9274e20cfeSnh145002 int fd;
9374e20cfeSnh145002 FILE *fConf;
9474e20cfeSnh145002 struct strioctl stri;
9574e20cfeSnh145002
9674e20cfeSnh145002 (void) setlocale(LC_ALL, "");
9774e20cfeSnh145002 (void) textdomain(TEXT_DOMAIN);
9874e20cfeSnh145002
9974e20cfeSnh145002 while ((c = getopt(argc, argv, OPTS)) != EOF) {
10074e20cfeSnh145002 switch (c) {
10174e20cfeSnh145002 case '?':
10274e20cfeSnh145002 usage();
10374e20cfeSnh145002 }
10474e20cfeSnh145002 }
10574e20cfeSnh145002
10674e20cfeSnh145002 if (argc != 2) {
10774e20cfeSnh145002 usage();
10874e20cfeSnh145002 }
10974e20cfeSnh145002
11074e20cfeSnh145002 fd = open(dcname, O_RDONLY);
11174e20cfeSnh145002 if (fd < 0) {
11274e20cfeSnh145002 (void) fprintf(stderr, gettext("opening %s failed errno %d\n"),
11374e20cfeSnh145002 dcname, errno);
11474e20cfeSnh145002 exit(0);
11574e20cfeSnh145002 }
11674e20cfeSnh145002
11774e20cfeSnh145002 if (argc == 2) {
11874e20cfeSnh145002 /* Parse the on|off from the user */
119*bbfe764eSse146197 if (strcasecmp(argv[1], "enable") == 0) {
12074e20cfeSnh145002 enable = 1;
121*bbfe764eSse146197 } else if (strcasecmp(argv[1], "disable") == 0) {
12274e20cfeSnh145002 enable = 0;
123*bbfe764eSse146197 } else if (strcasecmp(argv[1], "status") == 0)
12474e20cfeSnh145002 enable = -1;
12574e20cfeSnh145002 else {
12674e20cfeSnh145002 usage();
12774e20cfeSnh145002 }
12874e20cfeSnh145002 }
12974e20cfeSnh145002
130*bbfe764eSse146197 stri.ic_cmd = SIOCSENABLESDP;
13174e20cfeSnh145002 stri.ic_timout = 0;
13274e20cfeSnh145002 stri.ic_len = sizeof (int);
13374e20cfeSnh145002 stri.ic_dp = (char *)&enable;
13474e20cfeSnh145002
13574e20cfeSnh145002 if (ioctl(fd, I_STR, &stri) >= 0) {
13674e20cfeSnh145002 (void) fprintf(stdout, gettext("SDP is %s\n"),
13774e20cfeSnh145002 enable ? "Enabled" : "Disabled");
13874e20cfeSnh145002 fConf = fopen(FILENAME, "w");
13974e20cfeSnh145002 if (NULL != fConf) {
14074e20cfeSnh145002 (void) fprintf(fConf, conf_header);
14174e20cfeSnh145002 if (enable == 0) {
14274e20cfeSnh145002 (void) fprintf(fConf, FILEENTRY, 0);
14374e20cfeSnh145002 } else {
14474e20cfeSnh145002 (void) fprintf(fConf, FILEENTRY, 1);
14574e20cfeSnh145002 }
14674e20cfeSnh145002 (void) fclose(fConf);
14774e20cfeSnh145002 }
14874e20cfeSnh145002 } else {
14974e20cfeSnh145002 perror("ioctl failed");
15074e20cfeSnh145002 ret = E_ERROR;
15174e20cfeSnh145002 }
15274e20cfeSnh145002 return (ret);
15374e20cfeSnh145002 }
154