UNIXPC communication questions

Lenny Tropiano lenny at icus.islp.ny.us
Fri Apr 21 14:22:14 AEST 1989


In article <23118 at shemp.CS.UCLA.EDU> kirkaas at cs.ucla.edu (paul kirkaas) writes:
...
|>
|>2) phtoggle toggles between data/voice.  Is there any way to *absolutely* 
|>switch to data or voice?  I mean, I want to write a script that is scheduled 
|>by cron to make sure that the pc is is in a given mode at a given time.  I
|>don't want to automatically toggle if it is already in the right mode.
|>

Yes, I did exactly that with a little utility.  Since it's small I'm reposting
it again.  Basically it is invoked like:

$ phset DATA   -or-   phset VOICE

							-Lenny

-- cut here -- -- cut here -- -- cut here -- -- cut here -- -- cut here --
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  phset.mk phset.c phtoggle.mk phtoggle.mk
# Wrapped by lenny at icus on Fri Apr 21 00:21:24 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f phset.mk -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phset.mk\"
else
echo shar: Extracting \"phset.mk\" \(653 characters\)
sed "s/^X//" >phset.mk <<'END_OF_phset.mk'
X#
X# Makefile to compile phset.c  (Phone Set)
X# By Lenny Tropiano
X# (c)1988 ICUS Software Systems   UUCP:  ...icus!lenny
X#
X# add -DSINGLE_LINE to CFLAGS if using only /dev/ph0 as the line to toggle, 
X#                   else leave undefined.
XCFLAGS=-v -O
XLDFLAGS=-s
XLIBS=/lib/crt0s.o /lib/shlib.ifile
XDEST=/usr/lbin/
X#
Xphset.o:
X	$(CC) $(CFLAGS) -c phset.c
X#
Xphset:  phset.o
X	@echo "Loading ..."
X	$(LD) $(LDFLAGS) -o phset phset.o $(LIBS) 
X#
X# Need to be root for this
X#
X/usr/lbin:
X	mkdir /usr/lbin
X#
Xinstall: phset /usr/lbin
X	cp phset ${DEST}
X	chown root ${DEST}/phset
X	chgrp bin  ${DEST}/phset
X	chmod 4755 ${DEST}/phset
X#
Xclean:
X	rm -f phset *.o *.shar
END_OF_phset.mk
if test 653 -ne `wc -c <phset.mk`; then
    echo shar: \"phset.mk\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f phset.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phset.c\"
else
echo shar: Extracting \"phset.c\" \(3497 characters\)
sed "s/^X//" >phset.c <<'END_OF_phset.c'
X/************************************************************************\
X**                                                                      **
X** Program name: phset.c (Phone line set)                               **
X** Programmer:   Lenny Tropiano            UUCP: ...icus!lenny          **
X** Organization: ICUS Software Systems     (c)1988                      **
X** Date:         April 3, 1988                                          **
X**                                                                      **
X**************************************************************************
X**                                                                      **
X** Program use:  Program is run to set the phone line to a specific     **
X**               setting.  This checks the phone line status to         **
X**               see what the line is set at currently, and calls       **
X**               /usr/bin/phtoggle if necessary.  This will solve the   **
X**               problems inherent in using phtoggle in your crontab    **
X**               to adjust the line status.  If the status gets to the  **
X**               wrong setting you'll be toggling to the wrong setting. **
X**                                                                      **
X**************************************************************************
X** Permission is granted to distribute this program by any means as     **
X** long as credit is given for my work.     I would also like to see    **
X** any modifications or enhancements to this program.                   **
X\************************************************************************/
X
X#include <stdio.h>
X#include <sys/types.h>
X#include <sys/ph.h>
X#include <sys/phone.h>
X#include <nlist.h>
X
X#define PHNDEF	0
X#define	UNIX	"/unix"
X#define	KMEM	"/dev/kmem"
X
X#ifdef	SINGLE_LINE			/* if defined, then check ph0 */
X# 	define	OFFSET	0
X#else					/* else, then check ph1       */
X#	define	OFFSET	sizeof(struct phdef)
X#endif
X
Xstruct nlist unixsym[] = {		/* /unix name list of symbols */
X    { "phndef", },
X    { NULL, },
X};
X
Xmain(argc,argv)
Xint   argc;
Xchar *argv[];
X{
X	void	read_kmem();
X	struct  phdef   phblock;
X	int 	kmem; 
X	ushort	phone_mode;
X
X	if (argc != 2) {
X		printf("usage: %s [VOICE|DATA]\n", argv[0]);
X		exit(1);
X	}
X
X	if (strcmp(argv[1],"VOICE") != 0 &&
X	    strcmp(argv[1],"DATA") != 0) {
X		printf("usage: %s [VOICE|DATA]\n", argv[0]);
X		exit(1);
X	}
X
X	/*
X	 * Open unix namelist.
X	 */
X
X	if (nlist(UNIX, unixsym) < 0) {
X		fprintf(stderr, "%s: no namelist.\n", UNIX);
X		exit(1);
X	}
X
X	/*
X	 * Open kernel memory.
X	 */
X
X	if ((kmem = open(KMEM, 0)) < 0) {
X		perror(KMEM);
X		exit(1);
X	}
X
X	/*
X	 * Read memory location out of /dev/kmem.
X	 */
X
X   	read_kmem(kmem, &phblock, 
X		 (unixsym[PHNDEF].n_value + OFFSET), 
X		 (long)sizeof (struct phdef));
X
X	if (phblock.p_lineparam & DATA) {         /* check to see if DATA     */
X		if (strcmp(argv[1],"DATA") == 0)  /* do you want it this way? */
X			exit(0);
X	} else {			          /* it must be VOICE then    */
X		if (strcmp(argv[1],"VOICE") == 0) /* do you want it this way? */
X			exit(0);
X	}
X
X	/* if not set, call phtoggle, to change mode */
X
X	putenv("IFS=\" \n\t\"");	/* prevent any security breaches */
X
X	execl("/usr/bin/phtoggle","phtoggle", 0);
X
X	perror("execl() failed");
X
X}
X
Xvoid read_kmem(fd, caddr, kaddr, nbytes)
Xint  fd;
Xchar *caddr;
Xlong kaddr;
Xlong nbytes;
X{
X	if (lseek(fd, kaddr, 0)<0L ||
X	    read(fd, caddr, (unsigned)nbytes) != nbytes ) 
X	      perror("can't read /dev/kmem");
X}
X
END_OF_phset.c
if test 3497 -ne `wc -c <phset.c`; then
    echo shar: \"phset.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f phtoggle.mk -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phtoggle.mk\"
else
echo shar: Extracting \"phtoggle.mk\" \(395 characters\)
sed "s/^X//" >phtoggle.mk <<'END_OF_phtoggle.mk'
X# Makefile for phtoggle implementation.
X# By Lenny Tropiano            (lenny at icus.UUCP)
X# (c)1988 ICUS Software Systems
X
XCFLAGS = -v -O 
XLDFLAGS = -s
XBINDIR = /usr/lbin
XSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile
X
Xphtoggle: phtoggle.o
X	ld $(LDFLAGS) -o phtoggle phtoggle.o $(SHAREDLIB)
X
Xinstall: phtoggle 
X	chown root phtoggle 
X	chgrp root phtoggle 
X	chmod 4755 phtoggle 
X	mv phtoggle $(BINDIR)
X
END_OF_phtoggle.mk
if test 395 -ne `wc -c <phtoggle.mk`; then
    echo shar: \"phtoggle.mk\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f phtoggle.mk -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"phtoggle.mk\"
else
echo shar: Extracting \"phtoggle.mk\" \(395 characters\)
sed "s/^X//" >phtoggle.mk <<'END_OF_phtoggle.mk'
X# Makefile for phtoggle implementation.
X# By Lenny Tropiano            (lenny at icus.UUCP)
X# (c)1988 ICUS Software Systems
X
XCFLAGS = -v -O 
XLDFLAGS = -s
XBINDIR = /usr/lbin
XSHAREDLIB = /lib/crt0s.o /lib/shlib.ifile
X
Xphtoggle: phtoggle.o
X	ld $(LDFLAGS) -o phtoggle phtoggle.o $(SHAREDLIB)
X
Xinstall: phtoggle 
X	chown root phtoggle 
X	chgrp root phtoggle 
X	chmod 4755 phtoggle 
X	mv phtoggle $(BINDIR)
X
END_OF_phtoggle.mk
if test 395 -ne `wc -c <phtoggle.mk`; then
    echo shar: \"phtoggle.mk\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
Lenny Tropiano             ICUS Software Systems         [w] +1 (516) 582-5525
lenny at icus.islp.ny.us      Telex; 154232428 ICUS         [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny  attmail!icus!lenny
        ICUS Software Systems -- PO Box 1; Islip Terrace, NY  11752



More information about the Comp.sys.att mailing list