74e20cfe817b82802b16fac8690dadcda76f54f5nh/*
74e20cfe817b82802b16fac8690dadcda76f54f5nh * CDDL HEADER START
74e20cfe817b82802b16fac8690dadcda76f54f5nh *
74e20cfe817b82802b16fac8690dadcda76f54f5nh * The contents of this file are subject to the terms of the
74e20cfe817b82802b16fac8690dadcda76f54f5nh * Common Development and Distribution License (the "License").
74e20cfe817b82802b16fac8690dadcda76f54f5nh * You may not use this file except in compliance with the License.
74e20cfe817b82802b16fac8690dadcda76f54f5nh *
74e20cfe817b82802b16fac8690dadcda76f54f5nh * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
74e20cfe817b82802b16fac8690dadcda76f54f5nh * or http://www.opensolaris.org/os/licensing.
74e20cfe817b82802b16fac8690dadcda76f54f5nh * See the License for the specific language governing permissions
74e20cfe817b82802b16fac8690dadcda76f54f5nh * and limitations under the License.
74e20cfe817b82802b16fac8690dadcda76f54f5nh *
74e20cfe817b82802b16fac8690dadcda76f54f5nh * When distributing Covered Code, include this CDDL HEADER in each
74e20cfe817b82802b16fac8690dadcda76f54f5nh * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
74e20cfe817b82802b16fac8690dadcda76f54f5nh * If applicable, add the following below this CDDL HEADER, with the
74e20cfe817b82802b16fac8690dadcda76f54f5nh * fields enclosed by brackets "[]" replaced with your own identifying
74e20cfe817b82802b16fac8690dadcda76f54f5nh * information: Portions Copyright [yyyy] [name of copyright owner]
74e20cfe817b82802b16fac8690dadcda76f54f5nh *
74e20cfe817b82802b16fac8690dadcda76f54f5nh * CDDL HEADER END
74e20cfe817b82802b16fac8690dadcda76f54f5nh */
74e20cfe817b82802b16fac8690dadcda76f54f5nh/*
74e20cfe817b82802b16fac8690dadcda76f54f5nh * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
74e20cfe817b82802b16fac8690dadcda76f54f5nh * Use is subject to license terms.
74e20cfe817b82802b16fac8690dadcda76f54f5nh */
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh#pragma ident "%Z%%M% %I% %E% SMI"
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <stdio.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <libintl.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <stdlib.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <errno.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <locale.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <unistd.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <strings.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <fcntl.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <stropts.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <sys/types.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <sys/socket.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh#include <sys/sockio.h>
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh#define E_SUCCESS 0 /* Exit status for success */
74e20cfe817b82802b16fac8690dadcda76f54f5nh#define E_ERROR 1 /* Exit status for error */
74e20cfe817b82802b16fac8690dadcda76f54f5nh#define E_USAGE 2 /* Exit status for usage error */
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic const char USAGE[] = "Usage:\tsdpadm\tstatus\n\t\tenable\n\t\tdisable\n";
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic const char OPTS[] = "?";
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic const char FILEENTRY[] = "sysenable=%d\n";
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic const char FILENAME[] = "/etc/sdp.conf";
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic const char dcname[] = "/dev/sdp";
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic char conf_header[] =
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# CDDL HEADER START\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# The contents of this file are subject to the terms of the\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# Common Development and Distribution License (the \"License\").\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# You may not use this file except in compliance with the License.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# or http://www.opensolaris.org/os/licensing.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# See the License for the specific language governing permissions\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# and limitations under the License.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# When distributing Covered Code, include this CDDL HEADER in each\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# file and include the License file at usr/src/OPENSOLARIS.LICENSE.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# If applicable, add the following below this CDDL HEADER, with the\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# fields enclosed by brackets \"[]\" replaced with your own identifying\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# information: Portions Copyright [yyyy] [name of copyright owner]\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# CDDL HEADER END\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# ident \"@(#)sdp.conf 1.1 07/01/03 SMI\"\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# Copyright 2007 Sun Microsystems, Inc. All rights reserved.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"# Use is subject to license terms.\n"
74e20cfe817b82802b16fac8690dadcda76f54f5nh"#\n\n";
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nhstatic void
74e20cfe817b82802b16fac8690dadcda76f54f5nhusage()
74e20cfe817b82802b16fac8690dadcda76f54f5nh{
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(stderr, gettext(USAGE));
74e20cfe817b82802b16fac8690dadcda76f54f5nh exit(E_USAGE);
74e20cfe817b82802b16fac8690dadcda76f54f5nh}
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nhint
74e20cfe817b82802b16fac8690dadcda76f54f5nhmain(int argc, char *argv[])
74e20cfe817b82802b16fac8690dadcda76f54f5nh{
74e20cfe817b82802b16fac8690dadcda76f54f5nh int c, enable, ret = E_SUCCESS;
74e20cfe817b82802b16fac8690dadcda76f54f5nh int fd;
74e20cfe817b82802b16fac8690dadcda76f54f5nh FILE *fConf;
74e20cfe817b82802b16fac8690dadcda76f54f5nh struct strioctl stri;
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) setlocale(LC_ALL, "");
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) textdomain(TEXT_DOMAIN);
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh while ((c = getopt(argc, argv, OPTS)) != EOF) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh switch (c) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh case '?':
74e20cfe817b82802b16fac8690dadcda76f54f5nh usage();
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (argc != 2) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh usage();
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh fd = open(dcname, O_RDONLY);
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (fd < 0) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(stderr, gettext("opening %s failed errno %d\n"),
74e20cfe817b82802b16fac8690dadcda76f54f5nh dcname, errno);
74e20cfe817b82802b16fac8690dadcda76f54f5nh exit(0);
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (argc == 2) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh /* Parse the on|off from the user */
bbfe764ef179c2f606b093b6ec6bb149cde0e31bse if (strcasecmp(argv[1], "enable") == 0) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh enable = 1;
bbfe764ef179c2f606b093b6ec6bb149cde0e31bse } else if (strcasecmp(argv[1], "disable") == 0) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh enable = 0;
bbfe764ef179c2f606b093b6ec6bb149cde0e31bse } else if (strcasecmp(argv[1], "status") == 0)
74e20cfe817b82802b16fac8690dadcda76f54f5nh enable = -1;
74e20cfe817b82802b16fac8690dadcda76f54f5nh else {
74e20cfe817b82802b16fac8690dadcda76f54f5nh usage();
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh
bbfe764ef179c2f606b093b6ec6bb149cde0e31bse stri.ic_cmd = SIOCSENABLESDP;
74e20cfe817b82802b16fac8690dadcda76f54f5nh stri.ic_timout = 0;
74e20cfe817b82802b16fac8690dadcda76f54f5nh stri.ic_len = sizeof (int);
74e20cfe817b82802b16fac8690dadcda76f54f5nh stri.ic_dp = (char *)&enable;
74e20cfe817b82802b16fac8690dadcda76f54f5nh
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (ioctl(fd, I_STR, &stri) >= 0) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(stdout, gettext("SDP is %s\n"),
74e20cfe817b82802b16fac8690dadcda76f54f5nh enable ? "Enabled" : "Disabled");
74e20cfe817b82802b16fac8690dadcda76f54f5nh fConf = fopen(FILENAME, "w");
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (NULL != fConf) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(fConf, conf_header);
74e20cfe817b82802b16fac8690dadcda76f54f5nh if (enable == 0) {
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(fConf, FILEENTRY, 0);
74e20cfe817b82802b16fac8690dadcda76f54f5nh } else {
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fprintf(fConf, FILEENTRY, 1);
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh (void) fclose(fConf);
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh } else {
74e20cfe817b82802b16fac8690dadcda76f54f5nh perror("ioctl failed");
74e20cfe817b82802b16fac8690dadcda76f54f5nh ret = E_ERROR;
74e20cfe817b82802b16fac8690dadcda76f54f5nh }
74e20cfe817b82802b16fac8690dadcda76f54f5nh return (ret);
74e20cfe817b82802b16fac8690dadcda76f54f5nh}